Ejemplo n.º 1
0
        // How should we treat points on the line?
        public static bool TestIntersection(LineSegment l1, LineSegment l2)
        {
            double l1p1 = l2.CalculatePointInStandardForm (l1.p1);
            double l1p2 = l2.CalculatePointInStandardForm (l1.p2);

            //if (Math.Abs (l1p1) < tolerance || Math.Abs (l1p2) < tolerance) {]
            // Ignore this ->
            // touching lines will be considered intersecting

            // If the signs differ the points are on different sides of the
            // other line. If the signs are the same tho they are on the same
            // side of the other segment and hence no intersection.
            if (Math.Sign (l1p1) == Math.Sign (l1p2)) {
                return false;
            }

            double l2p1 = l1.CalculatePointInStandardForm (l2.p1);
            double l2p2 = l1.CalculatePointInStandardForm (l2.p2);

            //if (Math.Abs (l2p1) < tolerance || Math.Abs (l2p2) < tolerance) {}
            // Ignore this -> touching lines will be considered intersection

            if (Math.Sign (l2p1) == Math.Sign (l2p2)) {
                return false;
            }

            // Different signs for all points and lines involved. Intersection!
            return true;
        }