modulus-sym icon indicating copy to clipboard operation
modulus-sym copied to clipboard

🐛[BUG]: Incorrect sdf calculation in Polygon geometry

Open 052279 opened this issue 10 months ago • 0 comments

Version

22.09

On which installation method(s) does this occur?

Docker

Describe the issue

When calculating the sdf of the polygon geometry, the sign of the sdf outside the polygon is reversed if there is only one (or an odd number) of points on the polygon whose y-coordinates match those of the point for which the sdf is calculated.

Minimum reproducible example

import numpy as np
from modulus.geometry.primitives_2d import Polygon

geo = Polygon([(0, 0), (1, 1), (1, -1)]) # triangle
point1 = {'x': np.array([[-1]], 'y': np.array([[0]])} # The y coordinate is the same as one point of the triangle
point2 = {'x': np.array([[0]], 'y': np.array([[2]])} # The x coordinate is the same as one point of the triangle
point3 = {'x': np.array([[0.01]], 'y': np.array([[2]])} # The x or y coordinates do not coincide with any point in the triangle

print(sdf.geo(point1, params={}) # sdf should be negative, but it is positive
print(sdf.geo(point2, params={})
print(sdf.geo(point3, params={})

geo = Polygon([(0, 0), (1, 1), (1, 0), (1, -1)]) # add dummy point to make 2 points with y-coordinate equal to point1

print(sdf.geo(point1, params={}) # sign of sdf becomes negative
print(sdf.geo(point2, params={})
print(sdf.geo(point3, params={})

Relevant log output

No response

Environment details

No response

Other/Misc.

No response

052279 avatar Mar 27 '24 07:03 052279