Exemple #1
0
        public static float getXAtY(LineSegment seg, int y)
        {
            PointF fx = getFxForm(seg);

            return((y - fx.Y) / fx.X);
        }
Exemple #2
0
        public static bool FindIntersectionPoint(LineSegment segA, LineSegment segB, out Point result)
        {
            result = new Point();
            bool isAV = (segA.start.X == segA.end.X);
            bool isAH = (segA.start.Y == segA.end.Y);
            bool isBV = (segB.start.X == segB.end.X);
            bool isBH = (segB.start.Y == segB.end.Y);

            if (isAV && isBV)
            {
                return(false);             //parallel vertikal
            }
            if (isAH && isBH)
            {
                return(false); //parallel horizontal
            }
            if (isAH && isBV)  //intersection h - v
            {
                result = new Point(segB.start.X, segA.start.Y);
                return(isPointInSegment(segA, result) && isPointInSegment(segB, result));
            }
            if (isAV && isBH)
            {
                return(FindIntersectionPoint(segB, segA, out result));             //intersection v-h
            }
            if (isBV || isBH)
            {
                return(FindIntersectionPoint(segB, segA, out result)); //if only one is h or v make it segA
            }
            if (isAH)                                                  //only A is horizontal
            {
                result = new Point((int)getXAtY(segB, segA.start.Y), segA.start.Y);
                return(isPointInSegment(segA, result) && isPointInSegment(segB, result));
            }
            if (isAV) //only A is vertical
            {
                result = new Point(segA.start.X, (int)getYAtX(segB, segA.start.X));
                return(isPointInSegment(segA, result) && isPointInSegment(segB, result));
            }
            //both steep
            //y = Ax + B
            PointF fx1 = getFxForm(segA);
            PointF fx2 = getFxForm(segB);
            //Ax - y = -B
            float A1 = fx1.X;
            float B1 = -1;
            float C1 = -fx1.Y;
            float A2 = fx2.X;
            float B2 = -1;
            float C2 = -fx2.Y;
            //Ax + By = C
            float delta = A1 * B2 - A2 * B1;

            if (delta == 0)
            {
                return(false);
            }
            result.X = (int)((B2 * C1 - B1 * C2) / delta);
            result.Y = (int)((A1 * C2 - A2 * C1) / delta);
            return(isPointInSegment(segA, result) && isPointInSegment(segB, result));
        }
Exemple #3
0
        public static float getYAtX(LineSegment seg, int x)
        {
            PointF fx = getFxForm(seg);

            return(fx.X * x + fx.Y);
        }