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

Plane Intersection of line segment is not taking into account floating point inaccuracies #79

Open
SubDrag opened this issue Sep 30, 2024 · 0 comments

Comments

@SubDrag
Copy link

SubDrag commented Sep 30, 2024

https://github.com/juj/MathGeoLib/blob/master/src/Geometry/Plane.cpp#L655

I believe should be like this:
bool Plane::Intersects(const LineSegment &lineSegment, float *d) const
{
float t;
bool success = IntersectLinePlane(normal, this->d, lineSegment.a, lineSegment.Dir(), t);
const float lineSegmentLength = lineSegment.Length();
if (d)
*d = t / lineSegmentLength;
// Added by me
const float epsilon = 1e-4f; // Allow a small epsilon amount for tests for floating point inaccuracies.
return success && t >= 0.f && t <= (lineSegmentLength + epsilon);
}

Example where t=113.000008 and LineSegmentLength=113, which fails, but should be successful
LineSegment
{x=1439.00000 y=341.000000 z=1742.00000 }
{x=1326.00000 y=341.000000 z=1742.00000 }

CutPlane
{x=-0.999999940 y=0.00000000 z=0.00000000 }
d = -1325.99988

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

No branches or pull requests

1 participant