コード例 #1
0
ファイル: CustomLine.cs プロジェクト: bicep/opossum-test-ui
        public static Point?getIntersectionCoordinates(CustomLine l1, CustomLine l2)
        {
            Point intersectionPoint = new Point();

            // if parallel
            if (l1.getSlope() == l2.getSlope())
            {
                return(null);
            }

            // if either one is vertical (but not both because we would have returned null already)

            else if (l1.getIsVertical())
            {
                intersectionPoint.X = l1.getPoint1().X;
                Point l2Point = l2.getPoint1();
                intersectionPoint.Y = (intersectionPoint.X * l2.getSlope()) + l2.getConstant();
            }

            else if (l2.getIsVertical())
            {
                intersectionPoint.X = l2.getPoint1().X;
                Point l1Point = l1.getPoint1();
                intersectionPoint.Y = (intersectionPoint.X * l1.getSlope()) + l1.getConstant();
            }

            else
            {
                Point  l1Point = l1.getPoint1();
                Point  l2Point = l2.getPoint1();
                double a1      = l1Point.Y - l1.getSlope() * l1Point.X;
                double a2      = l2Point.Y - l2.getSlope() * l2Point.X;
                intersectionPoint.X = (a1 - a2) / (l2.getSlope() - l1.getSlope());
                intersectionPoint.Y = a2 + l2.getSlope() * intersectionPoint.X;
            }

            return(intersectionPoint);
        }