Пример #1
0
        public bool Contains(Point2LR point)
        {
            if (point.X > LongRational.Max(this.start.X, this.end.X) || point.X < LongRational.Min(this.start.X, this.end.X) || (point.Y > LongRational.Max(this.start.Y, this.end.Y) || point.Y < LongRational.Min(this.start.Y, this.end.Y)))
            {
                return(false);
            }
            if (this.start == this.end)
            {
                return(true);
            }
            Vector2LR delta = this.GetDelta();
            Vector2LR u     = point - this.start;
            Vector2LR v     = new Vector2LR(-delta.Y, delta.X);

            if (!Vector2LR.DotProduct(u, v).IsZero)
            {
                return(false);
            }
            LongRational longRational = Vector2LR.DotProduct(u, delta);

            if (longRational.IsNegative)
            {
                return(false);
            }
            LongRational lengthSquared = delta.GetLengthSquared();

            return(!(longRational > lengthSquared));
        }
Пример #2
0
 public LongRational GetDistanceSquared(Point2LR point)
 {
     if (this.direction.IsZero)
     {
         return((point - this.origin).GetLengthSquared());
     }
     return((Vector2LR.DotProduct(point - this.origin, this.direction) * this.direction / this.direction.GetLengthSquared() + this.origin - point).GetLengthSquared());
 }
Пример #3
0
        public Point2LR GetClosestPoint(Point2LR point)
        {
            Vector2LR    u             = point - this.start;
            Vector2LR    v             = this.end - this.start;
            LongRational lengthSquared = v.GetLengthSquared();
            LongRational longRational  = Vector2LR.DotProduct(u, v);

            return(longRational.IsNegative || !(longRational <= lengthSquared) ? (longRational.IsNegative ? this.start : this.end) : longRational / lengthSquared * v + this.start);
        }
Пример #4
0
        public LongRational GetDistanceSquared(Point2LR point)
        {
            Vector2LR    u             = point - this.start;
            Vector2LR    v             = this.end - this.start;
            LongRational lengthSquared = v.GetLengthSquared();
            LongRational longRational  = Vector2LR.DotProduct(u, v);

            return(longRational.IsNegative || !(longRational <= lengthSquared) ? (!longRational.IsNegative ? (this.end - point).GetLengthSquared() : (this.start - point).GetLengthSquared()) : (longRational / lengthSquared * v + this.start - point).GetLengthSquared());
        }
Пример #5
0
        public bool Contains(Point2LR p)
        {
            if (this.direction.IsZero)
            {
                return(p == this.origin);
            }
            Vector2LR v = new Vector2LR(-this.direction.Y, this.direction.X);

            return(Vector2LR.DotProduct(p - this.origin, v).IsZero);
        }
Пример #6
0
            public bool method_1(Point2LR point)
            {
                LongRational longRational = Vector2LR.DotProduct(point - this.point2LR_0, this.vector2LR_0);

                if (!longRational.IsNegative)
                {
                    return(longRational <= this.longRational_0);
                }
                return(false);
            }
Пример #7
0
        public LongRational GetNormalizedProjection(Point2LR point)
        {
            if (this.start == this.end)
            {
                return(LongRational.NaN);
            }
            Vector2LR delta = this.GetDelta();

            return(Vector2LR.DotProduct(point - this.start, delta) / delta.GetLengthSquared());
        }
Пример #8
0
        public static bool Intersects(Ray2LR a, Segment2LR b)
        {
            if (a.direction.IsZero)
            {
                return(b.Contains(a.origin));
            }
            Vector2LR v = new Vector2LR(-a.Direction.Y, a.Direction.X);

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

            if (longRational1.IsZero)
            {
                return(false);
            }
            Vector2LR    u             = b.Start - a.Origin;
            LongRational longRational2 = Vector2LR.CrossProduct(u, delta);

            if (longRational1.IsPositive)
            {
                if (longRational2.IsNegative)
                {
                    return(false);
                }
            }
            else if (longRational2.IsPositive)
            {
                return(false);
            }
            LongRational longRational3 = Vector2LR.CrossProduct(u, a.Direction);

            if (longRational1.IsPositive)
            {
                if (longRational3.IsNegative || longRational3 > longRational1)
                {
                    return(false);
                }
            }
            else if (longRational3.IsPositive || longRational3 < longRational1)
            {
                return(false);
            }
            LongRational longRational4 = longRational3 / longRational1;
            LongRational longRational5 = longRational2 / longRational1;

            return(true);
        }
Пример #9
0
        public bool ContainsProjection(Point2LR point)
        {
            Vector2LR    delta        = this.GetDelta();
            LongRational longRational = Vector2LR.DotProduct(point - this.start, delta);

            if (longRational.IsNegative)
            {
                return(false);
            }
            LongRational lengthSquared = delta.GetLengthSquared();

            return(!(longRational.Square() > lengthSquared));
        }
Пример #10
0
        public bool Contains(Point2LR p)
        {
            if (this.direction.IsZero)
            {
                return(p == this.origin);
            }
            Vector2LR v = new Vector2LR(-this.direction.Y, this.direction.X);
            Vector2LR u = p - this.origin;

            if (!Vector2LR.DotProduct(u, v).IsZero)
            {
                return(false);
            }
            return(!Vector2LR.DotProduct(u, this.direction).IsNegative);
        }
Пример #11
0
 public Point2LR GetClosestPoint(Point2LR point)
 {
     return(Vector2LR.DotProduct(point - this.origin, this.direction) / this.direction.GetLengthSquared() * this.direction + this.origin);
 }
Пример #12
0
        public static bool GetIntersectionCoefficients(
            Ray2LR a,
            Segment2LR b,
            out LongRational?p,
            out LongRational?q,
            out bool areParallel)
        {
            if (a.direction.IsZero)
            {
                areParallel = false;
                p           = new LongRational?();
                bool flag;
                if (flag = b.Contains(a.origin))
                {
                    Vector2LR delta = b.GetDelta();
                    q = new LongRational?(Vector2LR.DotProduct(a.origin - b.Start, delta) / delta.GetLengthSquared());
                }
                else
                {
                    q = new LongRational?();
                }
                return(flag);
            }
            Vector2LR    v             = new Vector2LR(-a.direction.Y, a.direction.X);
            Vector2LR    u             = b.Start - a.Origin;
            LongRational longRational1 = Vector2LR.DotProduct(u, v);
            LongRational longRational2 = Vector2LR.DotProduct(b.End - a.Origin, v);

            if (longRational1.IsPositive && longRational2.IsPositive || longRational1.IsNegative && longRational2.IsNegative)
            {
                p           = new LongRational?();
                q           = new LongRational?();
                areParallel = false;
                return(false);
            }
            Vector2LR delta1 = b.GetDelta();

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

            if (longRational3.IsZero)
            {
                p           = new LongRational?();
                q           = new LongRational?();
                areParallel = true;
                return(true);
            }
            areParallel = false;
            LongRational longRational4 = Vector2LR.CrossProduct(u, delta1);

            if (longRational3.IsPositive)
            {
                if (longRational4.IsNegative)
                {
                    p = new LongRational?();
                    q = new LongRational?();
                    return(false);
                }
            }
            else if (longRational4.IsPositive)
            {
                p = new LongRational?();
                q = new LongRational?();
                return(false);
            }
            LongRational longRational5 = Vector2LR.CrossProduct(u, a.Direction);

            if (longRational3.IsPositive)
            {
                if (longRational5.IsNegative || longRational5 > longRational3)
                {
                    p = new LongRational?();
                    q = new LongRational?();
                    return(false);
                }
            }
            else if (longRational5.IsPositive || longRational5 < longRational3)
            {
                p = new LongRational?();
                q = new LongRational?();
                return(false);
            }
            p = new LongRational?(longRational4 / longRational3);
            q = new LongRational?(longRational5 / longRational3);
            return(true);
        }
Пример #13
0
        public static bool GetIntersectionCoefficients(
            Ray2LR a,
            Ray2LR b,
            out LongRational?p,
            out LongRational?q,
            out bool parallel)
        {
            if (a.direction.IsZero)
            {
                if (b.direction.IsZero)
                {
                    bool flag = a.origin == b.origin;
                    parallel = false;
                    if (flag)
                    {
                        p = new LongRational?(LongRational.Zero);
                        q = new LongRational?(LongRational.Zero);
                    }
                    else
                    {
                        p = new LongRational?();
                        q = new LongRational?();
                    }
                    return(flag);
                }
                parallel = false;
                p        = new LongRational?();
                bool flag1;
                if (flag1 = b.Contains(a.origin))
                {
                    q = new LongRational?(Vector2LR.DotProduct(a.origin - b.origin, b.direction) / b.direction.GetLengthSquared());
                }
                else
                {
                    q = new LongRational?();
                }
                return(flag1);
            }
            if (b.Direction.IsZero)
            {
                parallel = false;
                q        = new LongRational?();
                bool flag;
                if (flag = a.Contains(b.origin))
                {
                    p = new LongRational?(Vector2LR.DotProduct(b.origin - a.origin, a.direction) / a.direction.GetLengthSquared());
                }
                else
                {
                    p = new LongRational?();
                }
                return(flag);
            }
            LongRational longRational1 = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X;

            if (longRational1.IsZero)
            {
                parallel = true;
                if (!a.Contains(b.origin))
                {
                    b.Contains(a.origin);
                }
                p = new LongRational?();
                q = new LongRational?();
                return(true);
            }
            parallel = false;
            Vector2LR    u             = b.origin - a.origin;
            LongRational longRational2 = Vector2LR.CrossProduct(u, b.direction);

            if (longRational1.IsPositive)
            {
                if (longRational2.IsNegative)
                {
                    p = new LongRational?();
                    q = new LongRational?();
                    return(false);
                }
            }
            else if (longRational2.IsPositive)
            {
                p = new LongRational?();
                q = new LongRational?();
                return(false);
            }
            LongRational longRational3 = Vector2LR.CrossProduct(u, a.direction);

            if (longRational1.IsPositive)
            {
                if (longRational3.IsNegative)
                {
                    p = new LongRational?();
                    q = new LongRational?();
                    return(false);
                }
            }
            else if (longRational3.IsPositive)
            {
                p = new LongRational?();
                q = new LongRational?();
                return(false);
            }
            p = new LongRational?(longRational2 / longRational1);
            q = new LongRational?(longRational3 / longRational1);
            return(true);
        }
Пример #14
0
        public static bool GetIntersectionCoefficients(
            Line2LR a,
            Line2LR b,
            out LongRational?p,
            out LongRational?q,
            out bool parallel)
        {
            if (a.direction.IsZero)
            {
                if (b.direction.IsZero)
                {
                    bool flag = a.origin == b.origin;
                    parallel = false;
                    if (flag)
                    {
                        p = new LongRational?(LongRational.Zero);
                        q = new LongRational?(LongRational.Zero);
                    }
                    else
                    {
                        p = new LongRational?();
                        q = new LongRational?();
                    }
                    return(flag);
                }
                parallel = false;
                p        = new LongRational?();
                bool flag1;
                if (flag1 = b.Contains(a.origin))
                {
                    q = new LongRational?(Vector2LR.DotProduct(a.origin - b.origin, b.direction) / b.direction.GetLengthSquared());
                }
                else
                {
                    q = new LongRational?();
                }
                return(flag1);
            }
            if (b.Direction.IsZero)
            {
                parallel = false;
                q        = new LongRational?();
                bool flag;
                if (flag = a.Contains(b.origin))
                {
                    p = new LongRational?(Vector2LR.DotProduct(b.origin - a.origin, a.direction) / a.direction.GetLengthSquared());
                }
                else
                {
                    p = new LongRational?();
                }
                return(flag);
            }
            LongRational longRational = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X;

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

            p = new LongRational?(Vector2LR.CrossProduct(u, b.Direction) / longRational);
            q = new LongRational?(Vector2LR.CrossProduct(u, a.Direction) / longRational);
            return(true);
        }
Пример #15
0
 public bool method_0(Point2LR p)
 {
     return(Vector2LR.DotProduct(p - this.point2LR_0, new Vector2LR(-this.vector2LR_0.Y, this.vector2LR_0.X)).IsZero);
 }