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

[Feature] Add rectangle and triangle sdf_func #387

Merged
merged 2 commits into from
Jun 17, 2023

Conversation

AndPuQing
Copy link
Contributor

@AndPuQing AndPuQing commented Jun 17, 2023

PR types

New features

PR changes

APIs

Describe

In this pull request, I have added the sdf_func implementations for rectangles and triangles. The visual result can be tested using the following code:

import ppsci
import numpy as np

from matplotlib import pyplot as plt

geo = ppsci.geometry.Triangle((0, 0), (1, 0), (0, 1))

x = np.linspace(-0.5, 1.3, 1000)
y = np.linspace(-0.5, 1.3, 1000)
X, Y = np.meshgrid(x, y)
x = X.flatten()
y = Y.flatten()
Z = geo.sdf_func(np.stack([x, y], axis=-1)).reshape(X.shape)
plt.contour(X, Y, Z, 0, colors="black")
plt.contourf(X, Y, Z, 20, cmap="RdBu_r")
plt.colorbar()
plt.show()

Visual Result

output
output1

#376

@paddle-bot
Copy link

paddle-bot bot commented Jun 17, 2023

Thanks for your contribution!

ppsci/geometry/geometry_2d.py Outdated Show resolved Hide resolved
ppsci/geometry/geometry_2d.py Outdated Show resolved Hide resolved
- v3p
)

s = self.is_inside(points).reshape(-1, 1) * 2 - 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量名字建议不要单个小写字母,命名尽量能表明变量本身的意义

"""
assert points.shape[1] == 2, "The shape of points must be [N, 2]."
center = (self.xmin + self.xmax) / 2
q = np.abs(points - center) - np.array([self.xmax - self.xmin]) / 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量名字建议不要单个小写字母,命名尽量能表明变量本身的意义

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HydrogenSulfate HydrogenSulfate merged commit 9346670 into PaddlePaddle:develop Jun 17, 2023
4 checks passed
@AndPuQing AndPuQing deleted the patch-sdf branch June 18, 2023 02:50
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants