1
Vote

Plane/Segment intersection problem

description

Hello,
First of all thank you for this beautiful library!
 
I'm not sure if I'm using the library in the correct way, but with the following code I get wrong results:
if a segment from point A to point B intersects the plane, also the segment from B to A should intersect, but I get false from the first test.
 
// z = 0
Plane plane = new Plane(Vector3F.ZAxis, 0);
Vector3F pointA = new Vector3F(0, 0, -10);
Vector3F pointB = new Vector3F(0, 0, 10);
Segment segmentAB = new Segment(pointA, pointB);
Segment segmentBA = new Segment(pointB, pointA);
IntersectionPair intersection = IntersectionMethods.Intersects(segmentAB, plane);
Console.WriteLine(intersection.IntersectionOccurred);
intersection = IntersectionMethods.Intersects(segmentBA, plane);
Console.WriteLine(intersection.IntersectionOccurred);
 
Many thanks,
Stenio Brunetta

comments

stenio wrote Aug 20, 2007 at 3:36 PM

Hi,

another issue:
    [Test]        public void test() {            Sharp3D.Math.Geometry3D.Plane plane = new Sharp3D.Math.Geometry3D.Plane(Vector3F.ZAxis, -3e6f);

        Vector3F p1 = new Vector3F(161746.9f, 0.00571176f, 3195273f);            Vector3F p2 = new Vector3F(279734.7f, 0.004676462f, 2649951f);

        Sharp3D.Math.Geometry3D.Segment segment1 = new Sharp3D.Math.Geometry3D.Segment(p1, p2);

        Sharp3D.Math.Geometry3D.IntersectionPair intersection = Sharp3D.Math.Geometry3D.IntersectionMethods.Intersects(segment1, plane);

        Assert.IsFalse(intersection.IntersectionOccurred);        }
There should be no intersection with the segment because its end points have a positive z.

stenio wrote Aug 21, 2007 at 2:54 PM

I've posted the previous comment as a new issue, because it seems to be a different kind of problem.

Regards,Stenio

Saint_Grey wrote Feb 8, 2010 at 7:44 PM

There is a mistake in public static bool TestIntersection(Segment segment, Plane plane) function that caused the first described problem.

The original code is:
                    // Get the position of the line's end point relative to the plane.
        int sign0 = (int)plane.GetSign(segment.P0);
        int sign1 = (int)plane.GetSign(segment.P1);

        // Intersection occurs if the 2 endpoints are at oposite sides of the plane.
        return ( ((sign0 > 0) && (sign1 < 0)) || ((sign0 < 0) && (sign0 > 0)) );
But the return statement should be the following:
                    return ( ((sign0 > 0) && (sign1 < 0)) || ((sign0 < 0) && (sign1 > 0)) );

wrote Feb 14, 2013 at 12:40 AM