Example #1
0
        public bool ContainsProjection(Point2BR point)
        {
            Vector2BR   delta       = this.GetDelta();
            BigRational bigRational = Vector2BR.DotProduct(point - this.point2BR_0, delta);

            if (bigRational.IsNegative)
            {
                return(false);
            }
            BigRational lengthSquared = delta.GetLengthSquared();

            return(!(bigRational.Square() > lengthSquared));
        }
Example #2
0
        public static bool Intersects(Segment2BR segment1, Segment2BR segment2)
        {
            if (segment1.point2BR_0 == segment1.point2BR_1)
            {
                return(segment2.Contains(segment1.point2BR_0));
            }
            Vector2BR   v1           = segment1.point2BR_1 - segment1.point2BR_0;
            Vector2BR   u1           = segment2.Start - segment1.point2BR_0;
            Vector2BR   u2           = segment2.End - segment1.point2BR_0;
            Vector2BR   v2           = new Vector2BR(-v1.Y, v1.X);
            BigRational bigRational1 = Vector2BR.DotProduct(u1, v2);
            BigRational bigRational2 = Vector2BR.DotProduct(u2, v2);

            if (bigRational1.IsPositive && bigRational2.IsPositive || bigRational1.IsNegative && bigRational2.IsNegative)
            {
                return(false);
            }
            BigRational a            = Vector2BR.DotProduct(u1, v1);
            BigRational b            = Vector2BR.DotProduct(u2, v1);
            BigRational bigRational3 = b - a;

            if (bigRational3.IsZero)
            {
                BigRational bigRational4 = a;
                if (bigRational4.IsNegative)
                {
                    return(false);
                }
                return(bigRational4.Square() <= v1.GetLengthSquared());
            }
            BigRational bigRational5 = bigRational2 - bigRational1;

            if (bigRational5.IsZero)
            {
                if (BigMath.Max(a, b).IsNegative)
                {
                    return(false);
                }
                return(BigMath.Min(a, b).Square() <= v1.GetLengthSquared());
            }
            BigRational bigRational6 = bigRational3 / bigRational5;
            BigRational bigRational7 = a - bigRational1 * bigRational6;

            if (bigRational7.IsNegative)
            {
                return(false);
            }
            return(bigRational7.Square() < v1.GetLengthSquared());
        }