示例#1
0
        // Token: 0x06000415 RID: 1045 RVA: 0x00012610 File Offset: 0x00010810
        public static Vector3?IntersectionWith(this Segment3 segment, Triangle3 triangle)
        {
            IntersectionSegment3Triangle3 intersectionSegment3Triangle = new IntersectionSegment3Triangle3(segment, triangle);

            if (intersectionSegment3Triangle.Find() && intersectionSegment3Triangle.IntersectionType != Intersection.Type.IT_EMPTY)
            {
                return(new Vector3?(segment.Origin + intersectionSegment3Triangle.SegmentParameter * segment.Direction));
            }
            return(null);
        }
示例#2
0
        // Token: 0x06000464 RID: 1124 RVA: 0x00013F08 File Offset: 0x00012108
        public bool Test()
        {
            Vector3[] array = new Vector3[]
            {
                this.triangle0.V1 - this.triangle0.V0,
                this.triangle0.V2 - this.triangle0.V1,
                this.triangle0.V0 - this.triangle0.V2
            };
            UnitVector3 axis;

            if (!array[0].TryGetUnitCross(array[1], out axis))
            {
                int      num     = IntersectionUtility3.MaxIndex(array[0].SquaredLength, array[1].SquaredLength, array[2].SquaredLength);
                Segment3 segment = new Segment3(this.triangle0[num], this.triangle0[(num + 1) % 3]);
                IntersectionSegment3Triangle3 intersectionSegment3Triangle = new IntersectionSegment3Triangle3(segment, this.triangle1);
                return(intersectionSegment3Triangle.Test());
            }
            double num2 = axis.Dot(this.triangle0.V0);
            double num3;
            double num4;

            IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis, out num3, out num4);
            if (num2 < num3 || num2 > num4)
            {
                return(false);
            }
            Vector3[] array2 = new Vector3[]
            {
                this.triangle1.V1 - this.triangle1.V0,
                this.triangle1.V2 - this.triangle1.V1,
                this.triangle1.V0 - this.triangle1.V2
            };
            UnitVector3 unitVector;

            if (!array2[0].TryGetUnitCross(array2[1], out unitVector))
            {
                int      num5     = IntersectionUtility3.MaxIndex(array2[0].SquaredLength, array2[1].SquaredLength, array2[2].SquaredLength);
                Segment3 segment2 = new Segment3(this.triangle1[num5], this.triangle1[(num5 + 1) % 3]);
                IntersectionSegment3Triangle3 intersectionSegment3Triangle2 = new IntersectionSegment3Triangle3(segment2, this.triangle0);
                return(intersectionSegment3Triangle2.Test());
            }
            Vector3 vector = new Vector3();

            if (axis.Cross(unitVector).Dot(vector) >= 1E-08)
            {
                double num6 = unitVector.Dot(this.triangle1.V0);
                double num7;
                double num8;
                IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, unitVector, out num7, out num8);
                if (num6 < num7 || num6 > num8)
                {
                    return(false);
                }
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        UnitVector3 axis2;
                        if (array[j].TryGetUnitCross(array2[i], out axis2))
                        {
                            IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, axis2, out num7, out num8);
                            IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis2, out num3, out num4);
                            if (num8 < num3 || num4 < num7)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            else
            {
                for (int j = 0; j < 3; j++)
                {
                    UnitVector3 axis3;
                    if (axis.TryGetUnitCross(array[j], out axis3))
                    {
                        double num7;
                        double num8;
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, axis3, out num7, out num8);
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis3, out num3, out num4);
                        if (num8 < num3 || num4 < num7)
                        {
                            return(false);
                        }
                    }
                }
                for (int i = 0; i < 3; i++)
                {
                    UnitVector3 axis4;
                    if (unitVector.TryGetUnitCross(array2[i], out axis4))
                    {
                        double num7;
                        double num8;
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle0, axis4, out num7, out num8);
                        IntersectionTriangle3Triangle3.ProjectOntoAxis(this.triangle1, axis4, out num3, out num4);
                        if (num8 < num3 || num4 < num7)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
示例#3
0
        // Token: 0x06000414 RID: 1044 RVA: 0x000125F0 File Offset: 0x000107F0
        public static bool Intersects(this Segment3 segment, Triangle3 triangle)
        {
            IntersectionSegment3Triangle3 intersectionSegment3Triangle = new IntersectionSegment3Triangle3(segment, triangle);

            return(intersectionSegment3Triangle.Test());
        }
示例#4
0
        // Token: 0x06000465 RID: 1125 RVA: 0x000142D4 File Offset: 0x000124D4
        public bool Find()
        {
            Vector3[] array = new Vector3[]
            {
                this.triangle0.V1 - this.triangle0.V0,
                this.triangle0.V2 - this.triangle0.V1,
                this.triangle0.V0 - this.triangle0.V2
            };
            UnitVector3 unitVector;

            if (!array[0].TryGetUnitCross(array[1], out unitVector))
            {
                int      num     = IntersectionUtility3.MaxIndex(array[0].SquaredLength, array[1].SquaredLength, array[2].SquaredLength);
                Segment3 segment = new Segment3(this.triangle0[num], this.triangle0[(num + 1) % 3]);
                IntersectionSegment3Triangle3 intersectionSegment3Triangle = new IntersectionSegment3Triangle3(segment, this.triangle1);
                bool result = intersectionSegment3Triangle.Find();
                if (intersectionSegment3Triangle.IntersectionType == Intersection.Type.IT_POINT)
                {
                    this.Points[0]        = segment.Origin + intersectionSegment3Triangle.SegmentParameter * segment.Direction;
                    this.Quantity         = 1;
                    this.IntersectionType = Intersection.Type.IT_POINT;
                }
                return(result);
            }
            Plane3 plane = new Plane3(this.triangle0.V0, this.triangle0.V1, this.triangle0.V2);

            int[]    array2 = new int[3];
            double[] array3 = new double[3];
            int      num2;
            int      num3;
            int      num4;

            IntersectionTriangle3Triangle3.TrianglePlaneRelations(this.triangle1, plane, ref array3, ref array2, out num2, out num3, out num4);
            if (num2 == 3 || num3 == 3)
            {
                return(false);
            }
            if (num4 == 3)
            {
                return(this.ReportCoplanarIntersections && this.GetCoplanarIntersection(plane, this.triangle0, this.triangle1));
            }
            if (num2 == 0 || num3 == 0)
            {
                if (num4 == 2)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (array2[i] != 0)
                        {
                            int num5 = (i + 2) % 3;
                            int num6 = (i + 1) % 3;
                            return(this.IntersectsSegment(plane, this.triangle0, this.triangle1[num5], this.triangle1[num6]));
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (array2[i] == 0)
                        {
                            return(this.ContainsPoint(this.triangle0, plane, this.triangle1[i]));
                        }
                    }
                }
            }
            if (num4 == 0)
            {
                int num7 = (num2 == 1) ? 1 : -1;
                for (int i = 0; i < 3; i++)
                {
                    if (array2[i] == num7)
                    {
                        int     num5   = (i + 2) % 3;
                        int     num6   = (i + 1) % 3;
                        double  scalar = array3[i] / (array3[i] - array3[num5]);
                        Vector3 vector = this.triangle1[i] + scalar * (this.triangle1[num5] - this.triangle1[i]);
                        scalar = array3[i] / (array3[i] - array3[num6]);
                        Vector3 end = this.triangle1[i] + scalar * (this.triangle1[num6] - this.triangle1[i]);
                        return(this.IntersectsSegment(plane, this.triangle0, vector, end));
                    }
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (array2[i] == 0)
                {
                    int     num5   = (i + 2) % 3;
                    int     num6   = (i + 1) % 3;
                    double  scalar = array3[num5] / (array3[num5] - array3[num6]);
                    Vector3 vector = this.triangle1[num5] + scalar * (this.triangle1[num6] - this.triangle1[num5]);
                    return(this.IntersectsSegment(plane, this.triangle0, this.triangle1[i], vector));
                }
            }
            MathBase.Assert(false, "Triangle3Triangle3.Find(): should not be here");
            return(false);
        }