//checks if two lines are collinear or not
        public static bool LineAdjacencyCheck(Line2d lineA, Line2d lineB, double eps = 0)
        {
            Point2d pA = lineA.StartPoint, qA = lineA.EndPoint;
            Point2d pB = lineB.StartPoint, qB = lineB.EndPoint;

            Vector2d vecA = new Vector2d(pA, qA), vecB = new Vector2d(pB, qB);
            double   crossMag = vecA.Cross(vecB);

            if (crossMag != 0)
            {
                return(false);
            }

            bool checkA1 = ValidateObject.CheckOnSegment(lineB, pA), checkA2 = ValidateObject.CheckOnSegment(lineB, qA);
            bool checkB1 = ValidateObject.CheckOnSegment(lineA, pB), checkB2 = ValidateObject.CheckOnSegment(lineA, qB);

            if (checkA1 || checkA2)
            {
                return(true);
            }
            if (checkB1 || checkB2)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        //################################################################################################################
        //this class stores methods realted to GraphicsUtility class which needs to be tested further for reliability
        //################################################################################################################

        // checks if two lines are collinear - not using
        internal static bool CheckLineCollinear(Line2d lineA, Line2d lineB)
        {
            Point2d p1 = lineA.StartPoint;
            Point2d p2 = lineA.EndPoint;
            Point2d q1 = lineB.StartPoint;
            Point2d q2 = lineB.EndPoint;

            // Find the four orientations needed for general and special cases
            int o1 = GraphicsUtility.Orientation(p1, q1, p2);
            int o2 = GraphicsUtility.Orientation(p1, q1, q2);
            int o3 = GraphicsUtility.Orientation(p2, q2, p1);
            int o4 = GraphicsUtility.Orientation(p2, q2, q1);

            // General case
            if (o1 != o2 && o3 != o4)
            {
                return(false);
            }
            // p1, q1 and p2 are colinear and p2 lies on segment p1q1
            if (o1 == 0 && ValidateObject.CheckOnSegment(p1, p2, q1))
            {
                return(true);
            }

            // p1, q1 and p2 are colinear and q2 lies on segment p1q1
            if (o2 == 0 && ValidateObject.CheckOnSegment(p1, q2, q1))
            {
                return(true);
            }

            // p2, q2 and p1 are colinear and p1 lies on segment p2q2
            if (o3 == 0 && ValidateObject.CheckOnSegment(p2, p1, q2))
            {
                return(true);
            }

            // p2, q2 and q1 are colinear and q1 lies on segment p2q2
            if (o4 == 0 && ValidateObject.CheckOnSegment(p2, q1, q2))
            {
                return(true);
            }
            return(false); // Doesn't fall in any of the above cases
        }