Skip to content

Commit 118076c

Browse files
Merge pull request #857 from zacsimile/sdf-ellipse
2 parents a5e972f + 9de4ac4 commit 118076c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/navigate/tools/sdf.py

+16
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,19 @@ def box(p, w):
108108
return np.linalg.norm(np.maximum(q, 0.0), axis=0) + np.minimum(
109109
np.maximum(q[0, :], np.maximum(q[1, :], q[2, :])), 0.0
110110
)
111+
112+
def ellipsoid(p, r):
113+
"""Signed distance function for an ellipsoid.
114+
115+
p : npt.ArrayLike
116+
(3, N) array of points on which to evaluate the sdf.
117+
w : tuple
118+
(3,) tuple of ellipsoid radii
119+
"""
120+
121+
r = np.array(r)
122+
123+
k0 = np.linalg.norm(p/(r[:,None]), axis=0)
124+
k1 = np.linalg.norm(p/((r*r)[:,None]), axis=0)
125+
126+
return k0*(k0-1.0)/k1

0 commit comments

Comments
 (0)