static internal Point IntersectDiagonalWithRay(Point pivot, Point pointOnRay, Diagonal diagonal)
        {
            Point ray    = pointOnRay - pivot;
            Point source = diagonal.Start;
            Point target = diagonal.End;
            //let x(t-s)+s is on the ray, then for some y we x(t-s)+s=y*ray+pivot, or x(t-s)-y*ray=pivot-s
            double x, y;
            bool   result = LinearSystem2.Solve(target.X - source.X, -ray.X, pivot.X - source.X, target.Y - source.Y, -ray.Y, pivot.Y - source.Y, out x, out y);

            System.Diagnostics.Debug.Assert(result && -ApproximateComparer.Tolerance <= x && x <= 1 + ApproximateComparer.Tolerance);

            return(pivot + y * ray);
        }
Exemple #2
0
        Point IntersectEdgeWithRay(Point source, Point target, Point ray)
        {
            //let x(t-s)+s is on the ray, then for some y we x(t-s)+s=y*ray+pivot, or x(t-s)-y*ray=pivot-s
            double x, y;
            bool   result = LinearSystem2.Solve(target.X - source.X, -ray.X, Pivot.X - source.X, target.Y - source.Y, -ray.Y, Pivot.Y - source.Y, out x, out y);

            if (!(-ApproximateComparer.Tolerance <= x && x <= 1 + ApproximateComparer.Tolerance))
            {
                throw new Exception();
            }
            if (!result)
            {
                throw new InvalidOperationException();
            }

            return(Pivot + y * ray);
        }
Exemple #3
0
        static public bool LineLineIntersection(Point a, Point b, Point c, Point d, out Point x)
        {
            //look for the solution in the form a+u*(b-a)=c+v*(d-c)
            double u, v;
            Point  ba  = b - a;
            Point  cd  = c - d;
            Point  ca  = c - a;
            bool   ret = LinearSystem2.Solve(ba.X, cd.X, ca.X, ba.Y, cd.Y, ca.Y, out u, out v);

            if (ret)
            {
                x = a + u * ba;
                return(true);
            }
            else
            {
                x = new Point();
                return(false);
            }
        }
Exemple #4
0
        static public bool SegmentSegmentIntersection(Point a, Point b, Point c, Point d, out Point x)
        {
            //look for the solution in the form a+u*(b-a)=c+v*(d-c)
            double u, v;
            Point  ba  = b - a;
            Point  cd  = c - d;
            Point  ca  = c - a;
            bool   ret = LinearSystem2.Solve(ba.X, cd.X, ca.X, ba.Y, cd.Y, ca.Y, out u, out v);
            double eps = ApproximateComparer.Tolerance;

            if (ret && u > -eps && u < 1.0 + eps && v > -eps && v < 1.0 + eps)
            {
                x = a + u * ba;
                return(true);
            }
            else
            {
                x = new Point();
                return(false);
            }
        }