Example #1
0
        public static bool Intersects(Ray2BR 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);
            }
            Vector2BR   u            = b.Start - a.Origin;
            BigRational bigRational2 = Vector2BR.CrossProduct(u, delta);

            if (bigRational1.IsPositive)
            {
                if (bigRational2.IsNegative)
                {
                    return(false);
                }
            }
            else if (bigRational2.IsPositive)
            {
                return(false);
            }
            BigRational bigRational3 = Vector2BR.CrossProduct(u, a.Direction);

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

            return(true);
        }
Example #2
0
        public bool Intersects(Ray2BR 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;
            Vector2BR   u            = other.origin - this.origin;
            BigRational bigRational2 = Vector2BR.CrossProduct(u, other.direction);

            if (bigRational1.IsPositive)
            {
                if (bigRational2.IsNegative)
                {
                    intersection = new Point2BR?();
                    return(false);
                }
            }
            else if (bigRational2.IsPositive)
            {
                intersection = new Point2BR?();
                return(false);
            }
            BigRational bigRational3 = Vector2BR.CrossProduct(u, this.direction);

            if (bigRational1.IsPositive)
            {
                if (bigRational3.IsNegative)
                {
                    intersection = new Point2BR?();
                    return(false);
                }
            }
            else if (bigRational3.IsPositive)
            {
                intersection = new Point2BR?();
                return(false);
            }
            BigRational bigRational4 = bigRational2 / bigRational1;

            intersection = new Point2BR?(this.origin + bigRational4 * this.direction);
            return(true);
        }
Example #3
0
        public static bool GetIntersectionCoefficients(
            Ray2BR a,
            Ray2BR 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 bigRational1 = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X;

            if (bigRational1.IsZero)
            {
                parallel = true;
                if (!a.Contains(b.origin))
                {
                    b.Contains(a.origin);
                }
                p = new BigRational?();
                q = new BigRational?();
                return(true);
            }
            parallel = false;
            Vector2BR   u            = b.origin - a.origin;
            BigRational bigRational2 = Vector2BR.CrossProduct(u, b.direction);

            if (bigRational1.IsPositive)
            {
                if (bigRational2.IsNegative)
                {
                    p = new BigRational?();
                    q = new BigRational?();
                    return(false);
                }
            }
            else if (bigRational2.IsPositive)
            {
                p = new BigRational?();
                q = new BigRational?();
                return(false);
            }
            BigRational bigRational3 = Vector2BR.CrossProduct(u, a.direction);

            if (bigRational1.IsPositive)
            {
                if (bigRational3.IsNegative)
                {
                    p = new BigRational?();
                    q = new BigRational?();
                    return(false);
                }
            }
            else if (bigRational3.IsPositive)
            {
                p = new BigRational?();
                q = new BigRational?();
                return(false);
            }
            p = new BigRational?(bigRational2 / bigRational1);
            q = new BigRational?(bigRational3 / bigRational1);
            return(true);
        }