Esempio n. 1
0
        public static System.Windows.Media.Media3D.Matrix3D SetTilt(
            this System.Windows.Media.Media3D.Matrix3D matrix, double tilt)
        {
            Vector3D translation = new System.Windows.Media.Media3D.Vector3D(matrix.OffsetX, matrix.OffsetY, matrix.OffsetZ);

            /*
             * var orientation = matrix.GetOrientation();
             * var spin = matrix.GetSpin();
             *
             * var newMatrix = new Matrix3D();
             * newMatrix = newMatrix.RotateOTS(new Vector3D(orientation, tilt,spin));
             * newMatrix.Translate(translation);
             * return newMatrix;*/

            // backoff translation
            matrix.Translate(new System.Windows.Media.Media3D.Vector3D(-translation.X, -translation.Y, -translation.Z));
            Vector3D localX = matrix.Transform(new System.Windows.Media.Media3D.Vector3D(1, 0, 0));

            // backoff exiting tilt
            matrix.Rotate(new System.Windows.Media.Media3D.Quaternion(localX, matrix.GetTilt() * -1.0));
            matrix.Rotate(new System.Windows.Media.Media3D.Quaternion(localX, tilt));
            // add back translation
            matrix.Translate(translation);
            return(matrix);
        }
Esempio n. 2
0
        public static double GetSpin(this System.Windows.Media.Media3D.Matrix3D matrix)
        {
            // get the rotatoin about the Z`` axis: angle between localX and tiltedX
            Vector3D localX     = matrix.Transform(new System.Windows.Media.Media3D.Vector3D(1, 0, 0));
            Matrix3D tiltMatrix = new System.Windows.Media.Media3D.Matrix3D()
                                  .SetOrientation(matrix.GetOrientation())
                                  .SetTilt(matrix.GetTilt());
            Vector3D tiltedX = tiltMatrix.Transform(new System.Windows.Media.Media3D.Vector3D(1, 0, 0));

            double   multiplier = 1.0;
            Vector3D zcross     = Vector3D.CrossProduct(tiltedX, localX);

            if (zcross.Z < 0)
            {
                multiplier = -1.0;
            }

            return(System.Windows.Media.Media3D.Vector3D.AngleBetween(localX, tiltedX) * multiplier);
        }