Пример #1
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);
        }
Пример #2
0
        public bool Intersects(Ray2LR other, out Point2LR?intersection, out bool parallel)
        {
            if (this.direction.IsZero)
            {
                parallel = false;
                bool flag;
                if (flag = other.Contains(this.origin))
                {
                    intersection = new Point2LR?(this.origin);
                }
                else
                {
                    intersection = new Point2LR?();
                }
                return(flag);
            }
            if (other.Direction.IsZero)
            {
                parallel = false;
                bool flag;
                if (flag = this.Contains(other.origin))
                {
                    intersection = new Point2LR?(other.origin);
                }
                else
                {
                    intersection = new Point2LR?();
                }
                return(flag);
            }
            LongRational longRational1 = this.direction.X * other.direction.Y - this.direction.Y * other.direction.X;

            if (longRational1.IsZero)
            {
                parallel = true;
                bool flag;
                if (flag = other.Contains(this.origin))
                {
                    intersection = new Point2LR?(this.origin);
                }
                else
                {
                    intersection = new Point2LR?();
                }
                return(flag);
            }
            parallel = false;
            Vector2LR    u             = other.origin - this.origin;
            LongRational longRational2 = Vector2LR.CrossProduct(u, other.direction);

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

            if (longRational1.IsPositive)
            {
                if (longRational3.IsNegative)
                {
                    intersection = new Point2LR?();
                    return(false);
                }
            }
            else if (longRational3.IsPositive)
            {
                intersection = new Point2LR?();
                return(false);
            }
            LongRational longRational4 = longRational2 / longRational1;

            intersection = new Point2LR?(this.origin + longRational4 * this.direction);
            return(true);
        }
Пример #3
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);
        }