Skip to content

🐛[BUG]: Incorrect sdf calculation in Polygon geometry #140

@052279

Description

@052279

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

Metadata

Metadata

Assignees

Labels

0 - BacklogIn queue waiting for assignmentbugSomething isn't workingexternalIssues/PR filed by people outside the core team

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions