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

Fix issue where all points would be considered to be part of plane if the origin is not in the polygon #40

Merged
merged 1 commit into from
Jul 27, 2024

Conversation

mauriciopoppe
Copy link
Owner

@mauriciopoppe mauriciopoppe commented Jul 27, 2024

The PR #33 added detection for an edge case where all the points are part of a plane, the detection algorithm was:

  1. Compute the initial tetrahedron containing 4 vertices.
  2. Taking any 3 vertex from it create a plane.
  3. Project all the points towards the plane using dot product, if the dot product is greater than some tolerance (not zero because of float point errors) then it means that a point is not part of plane.

There is an error in (3), let's assume a simple input in 2d where all the points are not in plane.

  • [2, 0], [2, 1], [2, -1] (they're points in x=2)
  • [1, 0] which is a point in x=1

An ascii diagram:

 1       x
 |
 |
-0---x---x
 |
 |
-1       x
x=0 x=1 x=2

If step (2) detected that all the points in x=2 were part of the plane where the normal is [1, 0] then by following (3) and projecting point [1, 0] to the plane (note that the point is not the normal) would result on it being behind the face and therefore it pass the check and consider the input to be a plane.

The problem in (3) is that we should compare the projection of the point to test [1, 0] to the projection of any plane point to the plane

  • project [2, 0] to the plane with a normal [1, 0] is dot([2,0], [1,0]) = 2
  • project [1, 0] to the plane with a normal [1, 0] is dot([1,0], [1,0]) = 1
  • The diff is 1 and is greater than any tolerance (typically tolerance is a tiny value like 1e-9)

Fixes #38

… the origin is not in the polygon

The PR #33 added detection for an edge case where all the points are
part of a plane, the detection algorithm was:

1. Compute the initial tetrahedron containing 4 vertices.
2. Taking any 3 vertex from it create a plane.
3. Project all the points towards the plane using dot product,
   if the dot product is greater than some tolerance (not zero because
   of float point errors) then it means that a point is not part of
   plane.

There is an error in (3), let's assume a simple input in 2d where all
the points are not a polygon.

- [2, 0], [2, 1], [2, -1] (they're points in x=2)
- [1, 0] which is a point in x=1

An ascii diagram:

```
 1       x
 |
 |
-0---x---x
 |
 |
-1       x
x=0 x=1 x=2
```

If step (2) detected that all the points in x=2 were part of the plane
where the normal is [1, 0] then by following (3) and projecting point
[1, 0] to the plane (note that the point is not the normal) would
result on it being behind the face and therefore it pass the check
and consider the input to be a plane.

The problem in (3) is that we should compare the projection of the point
to test [1, 0] to the projection of any plane point to the plane

- project [2, 0] to the plane with a normal [1, 0] is
  dot([2,0], [1,0]) = 2
- project [1, 0] to the plane with a normal [1, 0] is
  dot([1,0], [1,0]) = 1
- The diff is 1 and is greater than any tolerance (typically
  tolerance is a tiny value like 1e-9)
Copy link

codecov bot commented Jul 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.32%. Comparing base (f554dc2) to head (2d1efad).
Report is 32 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
+ Coverage   89.36%   90.32%   +0.95%     
==========================================
  Files           6        6              
  Lines         536      620      +84     
  Branches      100      106       +6     
==========================================
+ Hits          479      560      +81     
- Misses         52       55       +3     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mauriciopoppe mauriciopoppe merged commit 5ebc15d into master Jul 27, 2024
5 checks passed
@mauriciopoppe mauriciopoppe deleted the origin-not-in-initial-polygon-plane-detection branch July 27, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect results for objects with duplicate vertices
1 participant