示例#1
0
 public Point2D[] GetIntersections(Segment2D segment)
 {
     return(this.GetIntersections(segment, 8.88178419700125E-16));
 }
示例#2
0
        public static bool GetIntersectionParameters(
            Segment2D a,
            Segment2D b,
            out double[] pArray,
            out double[] qArray,
            double precision)
        {
            Segment2D.Struct10 struct10_1 = new Segment2D.Struct10(a.start, a.end, precision);
            Segment2D.Struct10 struct10_2 = new Segment2D.Struct10(b.start, b.end, precision);
            if ((struct10_1.double_0 > struct10_2.double_0 ? (!struct10_1.method_0(b.start) ? 0 : (struct10_1.method_0(b.End) ? 1 : 0)) : (struct10_2.double_0 == 0.0 || !struct10_2.method_0(a.start) ? 0 : (struct10_2.method_0(a.end) ? 1 : 0))) != 0)
            {
                struct10_1.method_1();
                struct10_2.method_1();
                if (struct10_1.method_2(b.start))
                {
                    if (struct10_1.method_2(b.end))
                    {
                        pArray = new double[2]
                        {
                            a.GetNormalizedProjection(b.start),
                            a.GetNormalizedProjection(b.end)
                        };
                        qArray = new double[2] {
                            0.0, 1.0
                        };
                        return(true);
                    }
                    if (struct10_2.method_2(a.start))
                    {
                        if (struct10_2.method_2(a.end))
                        {
                            pArray = new double[2] {
                                0.0, 1.0
                            };
                            qArray = new double[2]
                            {
                                0.0,
                                b.GetNormalizedProjection(a.end)
                            };
                        }
                        else
                        {
                            pArray = new double[2]
                            {
                                0.0,
                                a.GetNormalizedProjection(b.start)
                            };
                            qArray = new double[2]
                            {
                                b.GetNormalizedProjection(a.start),
                                0.0
                            };
                        }
                        return(true);
                    }
                    if (struct10_2.method_2(a.End))
                    {
                        pArray = new double[2]
                        {
                            a.GetNormalizedProjection(b.start),
                            1.0
                        };
                        qArray = new double[2]
                        {
                            0.0,
                            b.GetNormalizedProjection(a.end)
                        };
                        return(true);
                    }
                }
                else if (struct10_1.method_2(b.end))
                {
                    if (struct10_2.method_2(a.start))
                    {
                        if (struct10_2.method_2(a.End))
                        {
                            pArray = new double[2] {
                                0.0, 1.0
                            };
                            qArray = new double[2]
                            {
                                b.GetNormalizedProjection(a.start),
                                b.GetNormalizedProjection(a.end)
                            };
                        }
                        else
                        {
                            pArray = new double[2]
                            {
                                0.0,
                                a.GetNormalizedProjection(b.end)
                            };
                            qArray = new double[2]
                            {
                                b.GetNormalizedProjection(a.start),
                                1.0
                            };
                        }
                        return(true);
                    }
                    if (struct10_2.method_2(a.End))
                    {
                        pArray = new double[2]
                        {
                            1.0,
                            a.GetNormalizedProjection(b.end)
                        };
                        qArray = new double[2]
                        {
                            b.GetNormalizedProjection(a.end),
                            1.0
                        };
                        return(true);
                    }
                }
                else if (struct10_2.method_2(a.start))
                {
                    pArray = new double[2] {
                        0.0, 1.0
                    };
                    qArray = new double[2]
                    {
                        b.GetNormalizedProjection(a.start),
                        b.GetNormalizedProjection(a.end)
                    };
                    return(true);
                }
            }
            Vector2D vector2D0_1 = struct10_1.vector2D_0;
            Vector2D vector2D0_2 = struct10_2.vector2D_0;
            double   num1        = vector2D0_1.X * vector2D0_2.Y - vector2D0_1.Y * vector2D0_2.X;
            double   num2        = precision * precision;

            if (System.Math.Abs(num1) < num2)
            {
                pArray = (double[])null;
                qArray = (double[])null;
                return(false);
            }
            bool   flag;
            double num3 = (flag = num1 < 0.0) ? -num1 : num1;
            double num4 = (b.Start.X - a.Start.X) * vector2D0_2.Y - (b.Start.Y - a.Start.Y) * vector2D0_2.X;

            if (flag)
            {
                num4 = -num4;
            }
            if (num4 >= -num2 && num4 - num3 <= num2)
            {
                double num5 = (b.Start.X - a.Start.X) * vector2D0_1.Y - (b.Start.Y - a.Start.Y) * vector2D0_1.X;
                if (flag)
                {
                    num5 = -num5;
                }
                if (num5 >= -num2 && num5 - num3 <= num2)
                {
                    double num6 = 1.0 / num3;
                    double num7 = num4 * num6;
                    double num8 = 1.0 + precision;
                    if (num7 >= -precision && num7 <= num8)
                    {
                        double num9 = num5 * num6;
                        if (num9 >= -precision && num9 <= num8)
                        {
                            pArray = new double[1] {
                                num7
                            };
                            qArray = new double[1] {
                                num9
                            };
                            return(true);
                        }
                        pArray = (double[])null;
                        qArray = (double[])null;
                        return(false);
                    }
                    pArray = (double[])null;
                    qArray = (double[])null;
                    return(false);
                }
                pArray = (double[])null;
                qArray = (double[])null;
                return(false);
            }
            pArray = (double[])null;
            qArray = (double[])null;
            return(false);
        }
示例#3
0
        public static bool Intersects(Segment2D segment1, Segment2D segment2, out bool areOverlapping)
        {
            Vector2D v1   = segment1.end - segment1.start;
            Vector2D u1   = segment2.Start - segment1.start;
            Vector2D u2   = segment2.End - segment1.start;
            Vector2D v2   = new Vector2D(-v1.Y, v1.X);
            double   num1 = Vector2D.DotProduct(u1, v2);
            double   num2 = Vector2D.DotProduct(u2, v2);

            if (num1 > 0.0 && num2 > 0.0 || num1 < 0.0 && num2 < 0.0)
            {
                areOverlapping = false;
                return(false);
            }
            double val1 = Vector2D.DotProduct(u1, v1);
            double val2 = Vector2D.DotProduct(u2, v1);
            double num3 = val2 - val1;

            if (num3 == 0.0)
            {
                areOverlapping = false;
                if (num1 == 0.0 || num2 == 0.0)
                {
                    return(false);
                }
                double num4 = val1;
                if (num4 > 0.0)
                {
                    return(num4 < v1.GetLengthSquared());
                }
                return(false);
            }
            double num5 = num2 - num1;

            if (num5 == 0.0)
            {
                areOverlapping = true;
                double num4 = System.Math.Min(val1, val2);
                if (System.Math.Max(val1, val2) > 0.0)
                {
                    return(num4 < v1.GetLengthSquared());
                }
                return(false);
            }
            areOverlapping = false;
            if (num1 == 0.0 || num2 == 0.0)
            {
                return(false);
            }
            double num6 = val1 * num5 - num1 * num3;

            if (num5 > 0.0)
            {
                if (num6 > 0.0)
                {
                    return(num6 < num5 *v1.GetLengthSquared());
                }
                return(false);
            }
            if (num6 < 0.0)
            {
                return(num6 > num5 *v1.GetLengthSquared());
            }
            return(false);
        }
示例#4
0
        public static bool IntersectsInclusive(Segment2D segment1, Segment2D segment2)
        {
            bool areOverlapping;

            return(Segment2D.IntersectsInclusive(segment1, segment2, out areOverlapping));
        }
示例#5
0
        public static bool GetIntersectionCoefficients(
            Ray2D a,
            Segment2D b,
            out double p,
            out double q,
            out bool areParallel,
            double precision)
        {
            double   length1 = a.Direction.GetLength();
            Vector2D v1      = a.Direction / length1;
            Vector2D v2      = new Vector2D(-v1.Y, v1.X);
            Vector2D u       = b.Start - a.Origin;
            double   a1      = Vector2D.DotProduct(u, v2);
            double   b1      = Vector2D.DotProduct(b.End - a.Origin, v2);

            if (a1 > b1)
            {
                MathUtil.Swap(ref a1, ref b1);
            }
            if (a1 < precision && b1 > -precision)
            {
                Vector2D delta = b.GetDelta();
                if (delta == Vector2D.Zero)
                {
                    areParallel = false;
                    p           = Vector2D.DotProduct(u, v1) / length1;
                    if (p < 0.0)
                    {
                        p = double.NaN;
                        q = double.NaN;
                        return(false);
                    }
                    q = 0.0;
                    return(true);
                }
                double   length2  = delta.GetLength();
                Vector2D vector2D = delta / length2;
                double   num1     = v1.X * vector2D.Y - v1.Y * vector2D.X;
                if (System.Math.Abs(num1) < precision)
                {
                    p           = double.NaN;
                    q           = double.NaN;
                    areParallel = true;
                    return(true);
                }
                areParallel = false;
                double num2 = 1.0 / num1;
                p = (u.X * vector2D.Y - u.Y * vector2D.X) * num2 / length1;
                if (p < 0.0)
                {
                    p = double.NaN;
                    q = double.NaN;
                    return(false);
                }
                q = (u.X * v1.Y - u.Y * v1.X) * num2 / length2;
                bool flag;
                if (!(flag = q >= -precision && q <= 1.0 + precision))
                {
                    p = double.NaN;
                    q = double.NaN;
                }
                return(flag);
            }
            p           = double.NaN;
            q           = double.NaN;
            areParallel = false;
            return(false);
        }