Skip to content

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

Open
@SubDrag

Description

@SubDrag

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions