Skip to content

Commit 9434e1f

Browse files
committed
Add box_sdf
1 parent ceffc9d commit 9434e1f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl std::ops::Mul<Res> for Res {
6060

6161
fn scene(x: f64, y: f64) -> Res {
6262
Res {
63-
sd: capsule_sdf(x, y, 0.4, 0.4, 0.6, 0.6, 0.1),
63+
sd: box_sdf(x, y, 0.5, 0.5, 2.0 * PI / 16.0, 0.3, 0.1) - 0.1,
6464
emissive: 1.0,
6565
}
6666
}
@@ -90,6 +90,16 @@ fn capsule_sdf(x: f64, y: f64, ax: f64, ay: f64, bx: f64, by: f64, r: f64) -> f6
9090
segment_sdf(x, y, ax, ay, bx, by) - r
9191
}
9292

93+
fn box_sdf(x: f64, y: f64, cx: f64, cy: f64, theta: f64, sx: f64, sy: f64) -> f64 {
94+
let costheta = theta.cos();
95+
let sintheta = theta.sin();
96+
let dx = ((x - cx) * costheta + (y - cy) * sintheta).abs() - sx;
97+
let dy = ((y - cy) * costheta - (x - cx) * sintheta).abs() - sy;
98+
let ax = dx.max(0.0);
99+
let ay = dy.max(0.0);
100+
dx.max(dy).min(0.0) + (ax * ax + ay * ay).sqrt()
101+
}
102+
93103
fn trace(ox: f64, oy: f64, dx: f64, dy: f64) -> f64 {
94104
let mut t = 0.0;
95105
let mut i = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy