示例#1
0
        public MyPolygonSyncedRotation(MyVector[] uniquePoints, Triangle[] triangles, MyQuaternion rotation)
            : base(uniquePoints, triangles)
        {
            MyVector[] clonedPoints = Utility3D.GetClonedArray(uniquePoints);
            _rotatedPoly = new MyPolygon(clonedPoints, Utility3D.GetClonedArray(clonedPoints, triangles));

            SyncRotation(rotation);
        }
示例#2
0
        public virtual MyPolygon Clone()
        {
            //TODO:  Support children.  This will require a separate overload (probably private) that takes the subset of
            //unique points

            MyVector[] clonedPoints = Utility3D.GetClonedArray(_uniquePoints);

            return(new MyPolygon(clonedPoints, Utility3D.GetClonedArray(clonedPoints, _triangles)));
        }
示例#3
0
        public static MyPolygon CreateTetrahedron(double size, bool centered)
        {
            // Sketchup and MathWorld are cool

            //double height2D = Math.Sqrt((size * size) - ((size * size) / 4d));
            double height2D = size * (Math.Sqrt(3) / 2d);
            double height3D = Math.Sqrt(6d) * (size / 3d);
            double halfSize = size / 2d;

            MyVector[] uniquePoints = new MyVector[4];

            uniquePoints[0] = new MyVector(0, 0, 0);
            uniquePoints[1] = new MyVector(size, 0, 0);
            uniquePoints[2] = new MyVector(halfSize, height2D, 0);
            uniquePoints[3] = new MyVector(halfSize, Math.Tan(Utility3D.GetDegreesToRadians(30)) * halfSize, height3D);

            if (centered)
            {
                double   negHalfHeight3d = height3D * -.5d;
                MyVector offset          = new MyVector(negHalfHeight3d, negHalfHeight3d, negHalfHeight3d);

                for (int cntr = 0; cntr < uniquePoints.Length; cntr++)
                {
                    uniquePoints[cntr].Add(offset);
                }
            }

            Triangle[] triangles = new Triangle[4];

            triangles[0] = new Triangle(uniquePoints, 0, 1, 3);
            triangles[1] = new Triangle(uniquePoints, 1, 2, 3);
            triangles[2] = new Triangle(uniquePoints, 0, 3, 2);
            triangles[3] = new Triangle(uniquePoints, 0, 2, 1);

            return(new MyPolygon(uniquePoints, triangles));
        }
示例#4
0
        /// <summary>
        /// This function takes in a destination double vector, and I will tell you how much you need to rotate me in order for me to end up
        /// along that destination double vector.
        /// </summary>
        /// <remarks>
        /// This function is a mutated copy of MyVector.GetAngleBetweenVectors.  It is almost identical, but slightly more complex  :)
        ///
        /// If I am already aligned with the vector passed in, then I will return an arbitrary orthoganal, and an angle of zero.
        /// </remarks>
        /// <param name="destination">This is the double vector you want me to align myself with</param>
        public MyQuaternion GetAngleAroundAxis(DoubleVector destination)
        {
            #region Standard

            // Get the angle
            double rotationRadians = MyVector.GetAngleBetweenVectors(this.Standard, destination.Standard);
            if (Double.IsNaN(rotationRadians))
            {
                rotationRadians = 0d;
            }

            // I need to pull the cross product from me to the vector passed in
            MyVector rotationAxis = MyVector.Cross(this.Standard, destination.Standard);

            // If the cross product is zero, then there are two possibilities.  The vectors point in the same direction, or opposite directions.
            if (rotationAxis.IsNearZero)
            {
                // If I am here, then the angle will either be 0 or PI.
                if (Utility3D.IsNearZero(rotationRadians))
                {
                    // The vectors sit on top of each other.  I will set the orthoganal to an arbitrary value, and return zero for the radians
                    rotationAxis.X  = 1d;
                    rotationAxis.Y  = 0d;
                    rotationAxis.Z  = 0d;
                    rotationRadians = 0d;
                }
                else
                {
                    // The vectors are pointing directly away from each other, because this is a double vector, I must rotate along an axis that
                    // is orthogonal to my standard and orth
                    rotationAxis = this.Orth; //MyVector.Cross(this.Standard, this.Orth);
                }
            }

            MyQuaternion quatStandard = new MyQuaternion(rotationAxis, rotationRadians);



            //return quatStandard;



            #endregion

            // I only need to rotate the orth, because I already know where the standard will be
            MyVector rotatedOrth = quatStandard.GetRotatedVector(this.Orth, true);

            #region Orthogonal

            // Grab the angle
            rotationRadians = MyVector.GetAngleBetweenVectors(rotatedOrth, destination.Orth);
            if (Double.IsNaN(rotationRadians))
            {
                rotationRadians = 0d;
            }

            // Since I've rotated the standards onto each other, the rotation axis of the orth is the standard (asumming it was truely orthogonal
            // to begin with)
            rotationAxis = destination.Standard.Clone();

            MyQuaternion quatOrth = new MyQuaternion(rotationAxis, rotationRadians);

            #endregion

            // Exit Function
            //return MyQuaternion.Multiply(quatOrth, quatStandard);
            return(MyQuaternion.Multiply(quatStandard, quatOrth));
        }
示例#5
0
 public override MyPolygon Clone()
 {
     MyVector[] clonedPoints = Utility3D.GetClonedArray(base.UniquePoints);
     return(new MyPolygonSyncedRotation(clonedPoints, Utility3D.GetClonedArray(clonedPoints, base.Triangles), _rotationForClone.Clone()));
 }