Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add sdf] sphere #386

Merged
merged 1 commit into from
Jun 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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