Пример #1
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);
        }
Пример #2
0
        public static System.Windows.Media.Media3D.Matrix3D SetOrientation(this System.Windows.Media.Media3D.Matrix3D matrix, double orientationDegrees)
        {
            Vector3D translation = new System.Windows.Media.Media3D.Vector3D(matrix.OffsetX, matrix.OffsetY, matrix.OffsetZ);

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

            // back off any existing Z rotation
            matrix.Rotate(new System.Windows.Media.Media3D.Quaternion(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), matrix.GetOrientation() * -1.0));
            matrix.Rotate(new System.Windows.Media.Media3D.Quaternion(new System.Windows.Media.Media3D.Vector3D(0, 0, 1), orientationDegrees));
            // add back translation
            matrix.Translate(translation);
            return(matrix);
        }
Пример #3
0
        public static double GetTilt(this System.Windows.Media.Media3D.Matrix3D matrix)
        {
            // get the rotation about the X` local axis
            Vector3D localX = matrix.Transform(new System.Windows.Media.Media3D.Vector3D(1, 0, 0));
            Vector3D localY = matrix.Transform(new System.Windows.Media.Media3D.Vector3D(0, 1, 0));

            Matrix3D orientMatrix = new System.Windows.Media.Media3D.Matrix3D().SetOrientation(matrix.GetOrientation());
            Vector3D orientedY    = orientMatrix.Transform(new System.Windows.Media.Media3D.Vector3D(0, 1, 0));

            double   multiplier = 1.0;
            Vector3D xcross     = Vector3D.CrossProduct(orientedY, localY);
            double   xangle     = Vector3D.AngleBetween(localX, xcross);

            if (xangle > 90.0)
            {
                multiplier = -1.0;
            }
            //if(xcross.X < 0.0) { multiplier = -1.0; }
            // rotation about the X' axis = angle between localY and orientedY
            double angle = System.Windows.Media.Media3D.Vector3D.AngleBetween(localY, orientedY) * multiplier;

            return(angle);
        }