Beispiel #1
0
        public bool Intersects(Line2BR other, out Point2BR?intersection, out bool parallel)
        {
            if (this.direction.IsZero)
            {
                parallel = false;
                bool flag;
                if (flag = other.Contains(this.origin))
                {
                    intersection = new Point2BR?(this.origin);
                }
                else
                {
                    intersection = new Point2BR?();
                }
                return(flag);
            }
            if (other.Direction.IsZero)
            {
                parallel = false;
                bool flag;
                if (flag = this.Contains(other.origin))
                {
                    intersection = new Point2BR?(other.origin);
                }
                else
                {
                    intersection = new Point2BR?();
                }
                return(flag);
            }
            BigRational bigRational1 = this.direction.X * other.direction.Y - this.direction.Y * other.direction.X;

            if (bigRational1.IsZero)
            {
                parallel = true;
                bool flag;
                if (flag = other.Contains(this.origin))
                {
                    intersection = new Point2BR?(this.origin);
                }
                else
                {
                    intersection = new Point2BR?();
                }
                return(flag);
            }
            parallel = false;
            BigRational bigRational2 = Vector2BR.CrossProduct(other.Origin - this.origin, other.Direction) / bigRational1;

            intersection = new Point2BR?(this.origin + bigRational2 * this.direction);
            return(true);
        }
Beispiel #2
0
        public static bool Intersects(Line2BR a, Segment2BR b)
        {
            if (a.direction.IsZero)
            {
                return(b.Contains(a.origin));
            }
            Vector2BR v = new Vector2BR(-a.Direction.Y, a.Direction.X);

            if (Vector2BR.DotProduct(b.Start - a.Origin, v).IsPositive == Vector2BR.DotProduct(b.End - a.Origin, v).IsPositive)
            {
                return(false);
            }
            if (b.Start == b.End)
            {
                return(a.Contains(b.Start));
            }
            Vector2BR   delta        = b.GetDelta();
            BigRational bigRational1 = a.Direction.X * delta.Y - a.Direction.Y * delta.X;

            if (bigRational1.IsZero)
            {
                return(false);
            }
            BigRational bigRational2 = Vector2BR.CrossProduct(b.Start - a.Origin, a.Direction);

            if (bigRational1.IsPositive)
            {
                if (bigRational2.IsNegative || bigRational2 > bigRational1)
                {
                    return(false);
                }
            }
            else if (bigRational2.IsPositive || bigRational2 < bigRational1)
            {
                return(false);
            }
            BigRational bigRational3 = bigRational2 / bigRational1;

            return(true);
        }
Beispiel #3
0
        public static bool GetIntersectionCoefficients(
            Line2BR a,
            Segment2BR b,
            out BigRational?p,
            out BigRational?q,
            out bool areParallel)
        {
            if (a.direction.IsZero)
            {
                areParallel = false;
                p           = new BigRational?();
                bool flag;
                if (flag = b.Contains(a.origin))
                {
                    Vector2BR delta = b.GetDelta();
                    q = new BigRational?(Vector2BR.DotProduct(a.origin - b.Start, delta) / delta.GetLengthSquared());
                }
                else
                {
                    q = new BigRational?();
                }
                return(flag);
            }
            Vector2BR   v            = new Vector2BR(-a.direction.Y, a.direction.X);
            Vector2BR   u            = b.Start - a.Origin;
            BigRational bigRational1 = Vector2BR.DotProduct(u, v);
            BigRational bigRational2 = Vector2BR.DotProduct(b.End - a.Origin, v);

            if (bigRational1.IsPositive && bigRational2.IsPositive || bigRational1.IsNegative && bigRational2.IsNegative)
            {
                p           = new BigRational?();
                q           = new BigRational?();
                areParallel = false;
                return(false);
            }
            Vector2BR delta1 = b.GetDelta();

            if (delta1.IsZero)
            {
                areParallel = false;
                p           = new BigRational?(Vector2BR.DotProduct(u, a.direction) / a.direction.GetLengthSquared());
                q           = new BigRational?(BigRational.Zero);
                return(true);
            }
            BigRational bigRational3 = a.Direction.X * delta1.Y - a.Direction.Y * delta1.X;

            if (bigRational3.IsZero)
            {
                p           = new BigRational?();
                q           = new BigRational?();
                areParallel = true;
                return(true);
            }
            areParallel = false;
            BigRational bigRational4 = Vector2BR.CrossProduct(u, a.Direction);

            if (bigRational3.IsPositive)
            {
                if (bigRational4.IsNegative || bigRational4 > bigRational3)
                {
                    p = new BigRational?();
                    q = new BigRational?();
                    return(false);
                }
            }
            else if (bigRational4.IsPositive || bigRational4 < bigRational3)
            {
                p = new BigRational?();
                q = new BigRational?();
                return(false);
            }
            p = new BigRational?(Vector2BR.CrossProduct(u, delta1) / bigRational3);
            q = new BigRational?(bigRational4 / bigRational3);
            return(true);
        }
Beispiel #4
0
        public static bool GetIntersectionCoefficients(
            Line2BR a,
            Line2BR b,
            out BigRational?p,
            out BigRational?q,
            out bool parallel)
        {
            if (a.direction.IsZero)
            {
                if (b.direction.IsZero)
                {
                    bool flag = a.origin == b.origin;
                    parallel = false;
                    if (flag)
                    {
                        p = new BigRational?(BigRational.Zero);
                        q = new BigRational?(BigRational.Zero);
                    }
                    else
                    {
                        p = new BigRational?();
                        q = new BigRational?();
                    }
                    return(flag);
                }
                parallel = false;
                p        = new BigRational?();
                bool flag1;
                if (flag1 = b.Contains(a.origin))
                {
                    q = new BigRational?(Vector2BR.DotProduct(a.origin - b.origin, b.direction) / b.direction.GetLengthSquared());
                }
                else
                {
                    q = new BigRational?();
                }
                return(flag1);
            }
            if (b.Direction.IsZero)
            {
                parallel = false;
                q        = new BigRational?();
                bool flag;
                if (flag = a.Contains(b.origin))
                {
                    p = new BigRational?(Vector2BR.DotProduct(b.origin - a.origin, a.direction) / a.direction.GetLengthSquared());
                }
                else
                {
                    p = new BigRational?();
                }
                return(flag);
            }
            BigRational bigRational = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X;

            if (bigRational.IsZero)
            {
                parallel = true;
                a.Contains(b.origin);
                p = new BigRational?();
                q = new BigRational?();
                return(true);
            }
            parallel = false;
            Vector2BR u = b.Origin - a.Origin;

            p = new BigRational?(Vector2BR.CrossProduct(u, b.Direction) / bigRational);
            q = new BigRational?(Vector2BR.CrossProduct(u, a.Direction) / bigRational);
            return(true);
        }