Skip to content

Commit

Permalink
add sphere (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyulingyue authored Jun 17, 2023
1 parent dae0e19 commit 9305c56
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ppsci/geometry/geometry_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,23 @@ def uniform_boundary_points(self, n: int):
x = np.sqrt(1 - z**2) * np.cos(2 * np.pi * nl * g)
y = np.sqrt(1 - z**2) * np.sin(2 * np.pi * nl * g)
return np.stack((x, y, z), axis=-1)

def sdf_func(self, points: np.ndarray) -> np.ndarray:
"""Compute signed distance field.
Args:
points (np.ndarray): The coordinate points used to calculate the SDF value,
the shape is [N, 3]
Returns:
np.ndarray: Unsquared SDF values of input points, the shape is [N, 1].
NOTE: This function usually returns ndarray with negative values, because
according to the definition of SDF, the SDF value of the coordinate point inside
the object(interior points) is negative, the outside is positive, and the edge
is 0. Therefore, when used for weighting, a negative sign is often added before
the result of this function.
"""
sdf = self.radius - (((points - self.center) ** 2).sum(axis=1)) ** 0.5
sdf = -sdf[..., np.newaxis]
return sdf

0 comments on commit 9305c56

Please sign in to comment.