コード例 #1
0
        // Token: 0x06000466 RID: 1126 RVA: 0x000146E8 File Offset: 0x000128E8
        private static void ProjectOntoAxis(Triangle3 tri, UnitVector3 axis, out double min, out double max)
        {
            double num  = axis.Dot(tri.V0);
            double num2 = axis.Dot(tri.V1);
            double num3 = axis.Dot(tri.V2);

            min = num;
            max = min;
            if (num2 < min)
            {
                min = num2;
            }
            else if (num2 > max)
            {
                max = num2;
            }
            if (num3 < min)
            {
                min = num3;
                return;
            }
            if (num3 > max)
            {
                max = num3;
            }
        }
コード例 #2
0
        // Token: 0x0600047F RID: 1151 RVA: 0x00015FBC File Offset: 0x000141BC
        public static AxisAlignedBox3 ComputeAxisAlignedBoundingBox(this Circle3 circle)
        {
            Vector3     center = circle.Center;
            UnitVector3 normal = circle.Normal;
            double      a      = Math.Acos(normal.Dot(UnitVector3.UnitX));
            double      a2     = Math.Acos(normal.Dot(UnitVector3.UnitY));
            double      a3     = Math.Acos(normal.Dot(UnitVector3.UnitZ));
            Vector3     vector = new Vector3(Math.Sin(a), Math.Sin(a2), Math.Sin(a3));

            vector *= circle.Radius;
            return(new AxisAlignedBox3(center - vector, center + vector));
        }
コード例 #3
0
 // Token: 0x060001B3 RID: 435 RVA: 0x00009C98 File Offset: 0x00007E98
 public Rectangle3(Vector3 center, UnitVector3 axis0, UnitVector3 axis1, double extent0, double extent1)
 {
     this = default(Rectangle3);
     MathBase.Assert(Math.Abs(axis0.Dot(axis1)) < 1E-08, "Rectangle3 constructor: axes not perpendicular.");
     this.Axis0   = axis0;
     this.Axis1   = axis1;
     this.Extent0 = extent0;
     this.Extent1 = extent1;
     this.Center  = center;
 }
コード例 #4
0
        internal static Segment3?DoClipping(double fT0, double fT1, Vector3 origin, UnitVector3 direction, Box3 box)
        {
            MathBase.Assert(fT0 < fT1, "Intersection.DoClipping(): invalid arguments");
            Vector3 vector  = origin - box.Center;
            Vector3 vector2 = new Vector3(vector.Dot(box.Axis0), vector.Dot(box.Axis1), vector.Dot(box.Axis2));
            Vector3 vector3 = new Vector3(direction.Dot(box.Axis0), direction.Dot(box.Axis1), direction.Dot(box.Axis2));

            if (!Intersection.Clip(vector3.X, -vector2.X - box.Extent0, ref fT0, ref fT1) || !Intersection.Clip(-vector3.X, vector2.X - box.Extent0, ref fT0, ref fT1) || !Intersection.Clip(vector3.Y, -vector2.Y - box.Extent1, ref fT0, ref fT1) || !Intersection.Clip(-vector3.Y, vector2.Y - box.Extent1, ref fT0, ref fT1) || !Intersection.Clip(vector3.Z, -vector2.Z - box.Extent2, ref fT0, ref fT1) || !Intersection.Clip(-vector3.Z, vector2.Z - box.Extent2, ref fT0, ref fT1))
            {
                return(null);
            }
            if (fT1 > fT0)
            {
                Vector3 left    = origin + fT0 * direction;
                Vector3 right   = origin + fT1 * direction;
                Vector3 origin2 = (left + right) * 0.5;
                double  extent  = (left - right).Length * 0.5;
                return(new Segment3?(new Segment3(origin2, direction, extent)));
            }
            return(new Segment3?(new Segment3(origin + fT0 * direction, direction, 0.0)));
        }
コード例 #5
0
        // Token: 0x06000468 RID: 1128 RVA: 0x000147E8 File Offset: 0x000129E8
        private bool ContainsPoint(Triangle3 triangle, Plane3 plane, Vector3 point)
        {
            AffineTransform3 affineTransform = Transform3Factory.CreateOrthonormalBasis(plane.Normal);
            UnitVector3      axisX           = affineTransform.AxisX;
            UnitVector3      axisY           = affineTransform.AxisY;
            Vector3          vector          = point - triangle.V0;
            Vector3          vector2         = triangle.V1 - triangle.V0;
            Vector3          vector3         = triangle.V2 - triangle.V0;
            Vector2          rkP             = new Vector2(axisX.Dot(vector), axisY.Dot(vector));

            Vector2[] vertices = new Vector2[]
            {
                Vector2.Zero,
                new Vector2(axisX.Dot(vector2), axisY.Dot(vector2)),
                new Vector2(axisX.Dot(vector3), axisY.Dot(vector3))
            };
            if (new IntersectionTriangle3Triangle3.Query2(3, vertices).ToTriangle(rkP, 0, 1, 2) <= 0)
            {
                this.Quantity  = 1;
                this.Points[0] = point;
                return(true);
            }
            return(false);
        }
コード例 #6
0
        // Token: 0x0600037A RID: 890 RVA: 0x0000F064 File Offset: 0x0000D264
        internal static int Find(Vector3 origin, UnitVector3 dir, Cylinder3 cylinder, double[] t)
        {
            UnitVector3 direction = cylinder.Axis.Direction;
            UnitVector3 unitVector;
            UnitVector3 unitVector2;

            Vector3Factory.GenerateComplementBasis(out unitVector, out unitVector2, direction);
            double  num     = 0.5 * cylinder.Height;
            double  num2    = cylinder.Radius * cylinder.Radius;
            Vector3 vector  = origin - cylinder.Axis.Origin;
            Vector3 vector2 = new Vector3(unitVector.Dot(vector), unitVector2.Dot(vector), direction.Dot(vector));
            double  num3    = direction.Dot(dir);

            if (Math.Abs(num3) >= 0.99999999)
            {
                if (num2 - vector2.X * vector2.X - vector2.Y * vector2.Y < 0.0)
                {
                    return(0);
                }
                if (num3 > 0.0)
                {
                    t[0] = -vector2.Z - num;
                    t[1] = -vector2.Z + num;
                }
                else
                {
                    t[0] = vector2.Z - num;
                    t[1] = vector2.Z + num;
                }
                return(2);
            }
            else
            {
                Vector3 vector3 = new Vector3(unitVector.Dot(dir), unitVector2.Dot(dir), num3);
                if (Math.Abs(vector3.Z) <= 1E-08)
                {
                    if (Math.Abs(vector2.Z) > num)
                    {
                        return(0);
                    }
                    double num4 = vector2.X * vector2.X + vector2.Y * vector2.Y - num2;
                    double num5 = vector2.X * vector3.X + vector2.Y * vector3.Y;
                    double num6 = vector3.X * vector3.X + vector3.Y * vector3.Y;
                    double num7 = num5;
                    double num8 = num7 * num7 - num4 * num6;
                    if (num8 < -1E-08)
                    {
                        return(0);
                    }
                    if (num8 > 1E-08)
                    {
                        double num9  = Math.Sqrt(num8);
                        double num10 = 1.0 / num6;
                        t[0] = (-num5 - num9) * num10;
                        t[1] = (-num5 + num9) * num10;
                        return(2);
                    }
                    t[0] = -num5 / num6;
                    return(1);
                }
                else
                {
                    int    num11 = 0;
                    double num10 = 1.0 / vector3.Z;
                    double num12 = (-num - vector2.Z) * num10;
                    double num13 = vector2.X + num12 * vector3.X;
                    double num14 = vector2.Y + num12 * vector3.Y;
                    double num15 = num13 * num13;
                    double num16 = num14;
                    if (num15 + num16 * num16 <= num2)
                    {
                        t[num11++] = num12;
                    }
                    double num17 = (num - vector2.Z) * num10;
                    double num18 = vector2.X + num17 * vector3.X;
                    num14 = vector2.Y + num17 * vector3.Y;
                    double num19 = num18 * num18;
                    double num20 = num14;
                    if (num19 + num20 * num20 <= num2)
                    {
                        t[num11++] = num17;
                    }
                    if (num11 == 2)
                    {
                        if (t[0] > t[1])
                        {
                            double num21 = t[0];
                            t[0] = t[1];
                            t[1] = num21;
                        }
                        return(2);
                    }
                    double num4  = vector2.X * vector2.X + vector2.Y * vector2.Y - num2;
                    double num5  = vector2.X * vector3.X + vector2.Y * vector3.Y;
                    double num6  = vector3.X * vector3.X + vector3.Y * vector3.Y;
                    double num22 = num5;
                    double num8  = num22 * num22 - num4 * num6;
                    if (num8 < -1E-08)
                    {
                        MathBase.Assert(num11 == 0, "IntersectionLine3Cylinder3: Unexpected condition\n");
                        return(0);
                    }
                    if (num8 > 1E-08)
                    {
                        double num9 = Math.Sqrt(num8);
                        num10 = 1.0 / num6;
                        double num23 = (-num5 - num9) * num10;
                        if (num11 != 1 || Math.Abs(t[0] - num23) >= 1E-08)
                        {
                            if (num12 <= num17)
                            {
                                if (num12 <= num23 && num23 <= num17)
                                {
                                    t[num11++] = num23;
                                }
                            }
                            else if (num17 <= num23 && num23 <= num12)
                            {
                                t[num11++] = num23;
                            }
                        }
                        if (num11 == 2)
                        {
                            if (t[0] > t[1])
                            {
                                double num24 = t[0];
                                t[0] = t[1];
                                t[1] = num24;
                            }
                            return(2);
                        }
                        num23 = (-num5 + num9) * num10;
                        if (num12 <= num17)
                        {
                            if (num12 <= num23 && num23 <= num17)
                            {
                                t[num11++] = num23;
                            }
                        }
                        else if (num17 <= num23 && num23 <= num12)
                        {
                            t[num11++] = num23;
                        }
                    }
                    else
                    {
                        double num23 = -num5 / num6;
                        if (num12 <= num17)
                        {
                            if (num12 <= num23 && num23 <= num17)
                            {
                                t[num11++] = num23;
                            }
                        }
                        else if (num17 <= num23 && num23 <= num12)
                        {
                            t[num11++] = num23;
                        }
                    }
                    if (num11 == 2 && t[0] > t[1])
                    {
                        double num25 = t[0];
                        t[0] = t[1];
                        t[1] = num25;
                    }
                    return(num11);
                }
            }
        }
コード例 #7
0
        // Token: 0x060000D9 RID: 217 RVA: 0x000052B4 File Offset: 0x000034B4
        public DistanceLine3Rectangle3(Line3 line, Rectangle3 rectangle)
        {
            this = default(DistanceLine3Rectangle3);
            if (Math.Abs(rectangle.Axis0.Cross(rectangle.Axis1).Dot(line.Direction)) > 1E-08)
            {
                Vector3          vector          = line.Origin - rectangle.Center;
                UnitVector3      direction       = line.Direction;
                AffineTransform3 affineTransform = Transform3Factory.CreateOrthonormalBasis(direction);
                double           num             = affineTransform.AxisX.Dot(rectangle.Axis0);
                double           num2            = affineTransform.AxisX.Dot(rectangle.Axis1);
                double           num3            = affineTransform.AxisX.Dot(vector);
                double           num4            = affineTransform.AxisY.Dot(rectangle.Axis0);
                double           num5            = affineTransform.AxisY.Dot(rectangle.Axis1);
                double           num6            = affineTransform.AxisY.Dot(vector);
                double           num7            = 1.0 / (num * num5 - num2 * num4);
                double           num8            = (num5 * num3 - num2 * num6) * num7;
                double           num9            = (num * num6 - num4 * num3) * num7;
                if (Math.Abs(num8) <= rectangle.Extent0 && Math.Abs(num9) <= rectangle.Extent1)
                {
                    double num10 = direction.Dot(rectangle.Axis0);
                    double num11 = direction.Dot(rectangle.Axis1);
                    double num12 = line.Direction.Dot(vector);
                    this.LineParameter           = num8 * num10 + num9 * num11 - num12;
                    this.RectCoord0              = num8;
                    this.RectCoord1              = num9;
                    this.ClosestPointOnLine      = line.Origin + this.LineParameter * line.Direction;
                    this.ClosestPointOnRectangle = rectangle.Center + num8 * rectangle.Axis0 + num9 * rectangle.Axis1;
                    this.SquaredDistance         = 0.0;
                    return;
                }
            }
            double num13 = double.MaxValue;

            Vector3[] array = new Vector3[]
            {
                rectangle.Extent0 *rectangle.Axis0,
                rectangle.Extent1 *rectangle.Axis1
            };
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    Vector3               origin               = rectangle.Center + (double)(2 * j - 1) * array[i];
                    UnitVector3           direction2           = (i == 0) ? rectangle.Axis1 : rectangle.Axis0;
                    double                extent               = (i == 0) ? rectangle.Extent1 : rectangle.Extent0;
                    Segment3              segment              = new Segment3(origin, direction2, extent);
                    DistanceLine3Segment3 distanceLine3Segment = new DistanceLine3Segment3(line, segment);
                    double                squaredDistance      = distanceLine3Segment.SquaredDistance;
                    if (squaredDistance < num13)
                    {
                        this.ClosestPointOnLine      = distanceLine3Segment.ClosestPointOnLine;
                        this.ClosestPointOnRectangle = distanceLine3Segment.ClosestPointOnSegment;
                        num13 = squaredDistance;
                        this.LineParameter = distanceLine3Segment.LineParameter;
                        double num14 = distanceLine3Segment.SegmentParameter / segment.Extent;
                        this.RectCoord0 = rectangle.Extent0 * ((double)((1 - i) * (2 * j - 1)) + (double)i * num14);
                        this.RectCoord1 = rectangle.Extent1 * ((double)((1 - j) * (2 * i - 1)) + (double)j * num14);
                    }
                }
            }
            this.SquaredDistance = num13;
        }
コード例 #8
0
        // Token: 0x060000F3 RID: 243 RVA: 0x000058E0 File Offset: 0x00003AE0
        public DistanceLine3Triangle3(Line3 line, Triangle3 triangle)
        {
            this = default(DistanceLine3Triangle3);
            Vector3     vector  = triangle.V1 - triangle.V0;
            Vector3     vector2 = triangle.V2 - triangle.V0;
            UnitVector3 unitVector;

            if (vector.TryGetUnitCross(vector2, out unitVector) && Math.Abs(unitVector.Dot(line.Direction)) > 1E-08)
            {
                Vector3          vector3         = line.Origin - triangle.V0;
                UnitVector3      direction       = line.Direction;
                AffineTransform3 affineTransform = Transform3Factory.CreateOrthonormalBasis(direction);
                double           num             = affineTransform.AxisX.Dot(vector);
                double           num2            = affineTransform.AxisX.Dot(vector2);
                double           num3            = affineTransform.AxisX.Dot(vector3);
                double           num4            = affineTransform.AxisY.Dot(vector);
                double           num5            = affineTransform.AxisY.Dot(vector2);
                double           num6            = affineTransform.AxisY.Dot(vector3);
                double           num7            = 1.0 / (num * num5 - num2 * num4);
                double           num8            = (num5 * num3 - num2 * num6) * num7;
                double           num9            = (num * num6 - num4 * num3) * num7;
                double           num10           = 1.0 - num8 - num9;
                if (num10 >= 0.0 && num8 >= 0.0 && num9 >= 0.0)
                {
                    double num11 = direction.Dot(vector);
                    double num12 = direction.Dot(vector2);
                    double num13 = line.Direction.Dot(vector3);
                    this.LineParameter          = num8 * num11 + num9 * num12 - num13;
                    this.TriangleBary0          = num10;
                    this.TriangleBary1          = num8;
                    this.TriangleBary2          = num9;
                    this.ClosestPointOnLine     = line.Origin + this.LineParameter * line.Direction;
                    this.ClosestPointOnTriangle = triangle.V0 + num8 * vector + num9 * vector2;
                    this.SquaredDistance        = 0.0;
                    return;
                }
            }
            Segment3 segment = new Segment3(triangle.V2, triangle.V0);
            DistanceLine3Segment3 distanceLine3Segment = new DistanceLine3Segment3(line, segment);

            this.ClosestPointOnLine     = distanceLine3Segment.ClosestPointOnLine;
            this.ClosestPointOnTriangle = distanceLine3Segment.ClosestPointOnSegment;
            this.SquaredDistance        = distanceLine3Segment.SquaredDistance;
            this.LineParameter          = distanceLine3Segment.LineParameter;
            this.TriangleBary2          = 0.5 * (1.0 - distanceLine3Segment.SegmentParameter / segment.Extent);
            this.TriangleBary0          = 1.0 - this.TriangleBary2;
            this.TriangleBary1          = 0.0;
            Segment3 segment2 = new Segment3(triangle.V0, triangle.V1);
            DistanceLine3Segment3 distanceLine3Segment2 = new DistanceLine3Segment3(line, segment2);

            if (distanceLine3Segment2.SquaredDistance < this.SquaredDistance)
            {
                this.ClosestPointOnLine     = distanceLine3Segment2.ClosestPointOnLine;
                this.ClosestPointOnTriangle = distanceLine3Segment2.ClosestPointOnSegment;
                this.SquaredDistance        = distanceLine3Segment2.SquaredDistance;
                this.LineParameter          = distanceLine3Segment2.LineParameter;
                this.TriangleBary0          = 0.5 * (1.0 - distanceLine3Segment2.SegmentParameter / segment2.Extent);
                this.TriangleBary1          = 1.0 - this.TriangleBary0;
                this.TriangleBary2          = 0.0;
            }
            Segment3 segment3 = new Segment3(triangle.V1, triangle.V2);
            DistanceLine3Segment3 distanceLine3Segment3 = new DistanceLine3Segment3(line, segment3);

            if (distanceLine3Segment3.SquaredDistance < this.SquaredDistance)
            {
                this.ClosestPointOnLine     = distanceLine3Segment3.ClosestPointOnLine;
                this.ClosestPointOnTriangle = distanceLine3Segment3.ClosestPointOnSegment;
                this.SquaredDistance        = distanceLine3Segment3.SquaredDistance;
                this.LineParameter          = distanceLine3Segment3.LineParameter;
                this.TriangleBary1          = 0.5 * (1.0 - distanceLine3Segment3.SegmentParameter / segment3.Extent);
                this.TriangleBary2          = 1.0 - this.TriangleBary1;
                this.TriangleBary0          = 0.0;
            }
        }
コード例 #9
0
        // Token: 0x06000459 RID: 1113 RVA: 0x00013A04 File Offset: 0x00011C04
        public bool Test()
        {
            Vector3[] array = new Vector3[3];
            array[0] = this.triangle.V1 - this.triangle.V0;
            array[1] = this.triangle.V2 - this.triangle.V0;
            Vector3 axis = array[0].Cross(array[1]);
            double  num  = axis.Dot(this.triangle.V0);
            double  num2 = num;
            double  num3;
            double  num4;

            IntersectionUtility3.GetProjection(axis, this.box, out num3, out num4);
            if (num4 < num || num2 < num3)
            {
                return(false);
            }
            UnitVector3 unitVector = this.box.Axis0;

            IntersectionUtility3.GetProjection((Vector3)unitVector, this.triangle, out num, out num2);
            double num5 = unitVector.Dot(this.box.Center);

            num3 = num5 - this.box.Extent0;
            num4 = num5 + this.box.Extent0;
            if (num4 < num || num2 < num3)
            {
                return(false);
            }
            unitVector = this.box.Axis1;
            IntersectionUtility3.GetProjection((Vector3)unitVector, this.triangle, out num, out num2);
            double num6 = unitVector.Dot(this.box.Center);

            num3 = num6 - this.box.Extent1;
            num4 = num6 + this.box.Extent1;
            if (num4 < num || num2 < num3)
            {
                return(false);
            }
            unitVector = this.box.Axis2;
            IntersectionUtility3.GetProjection((Vector3)unitVector, this.triangle, out num, out num2);
            double num7 = unitVector.Dot(this.box.Center);

            num3 = num7 - this.box.Extent2;
            num4 = num7 + this.box.Extent2;
            if (num4 < num || num2 < num3)
            {
                return(false);
            }
            array[2] = array[1] - array[0];
            for (int i = 0; i < 3; i++)
            {
                Vector3 axis2 = array[i].Cross(this.box.Axis0);
                IntersectionUtility3.GetProjection(axis2, this.triangle, out num, out num2);
                IntersectionUtility3.GetProjection(axis2, this.box, out num3, out num4);
                if (num4 < num || num2 < num3)
                {
                    return(false);
                }
                Vector3 axis3 = array[i].Cross(this.box.Axis1);
                IntersectionUtility3.GetProjection(axis3, this.triangle, out num, out num2);
                IntersectionUtility3.GetProjection(axis3, this.box, out num3, out num4);
                if (num4 < num || num2 < num3)
                {
                    return(false);
                }
                Vector3 axis4 = array[i].Cross(this.box.Axis2);
                IntersectionUtility3.GetProjection(axis4, this.triangle, out num, out num2);
                IntersectionUtility3.GetProjection(axis4, this.box, out num3, out num4);
                if (num4 < num || num2 < num3)
                {
                    return(false);
                }
            }
            return(true);
        }