示例#1
0
        /// <summary>
        /// Constructs the rotation matrix for an angle counter-clockwise (right-handed) about an arbitrary axis
        /// </summary>
        /// <param name="angle">Angle in radians</param>
        static public Matrix RotationMatrix(Vector axis, double angle)
        {
            axis = axis.UnitVector();
            var    matrix      = new Matrix(3, 3);
            double cos         = Math.Cos(angle);
            double sin         = Math.Sin(angle);
            double oneMinusCos = 1 - cos;

            matrix[0, 0] = cos + UtilityFunctions.Square(axis.X) * oneMinusCos;
            matrix[0, 1] = axis.X * axis.Y * oneMinusCos - axis.Z * sin;
            matrix[0, 2] = axis.X * axis.Z * oneMinusCos + axis.Y * sin;
            matrix[1, 0] = axis.Y * axis.X * oneMinusCos + axis.Z * sin;
            matrix[1, 1] = cos + UtilityFunctions.Square(axis.Y) * oneMinusCos;
            matrix[1, 2] = axis.Y * axis.Z * oneMinusCos - axis.X * sin;
            matrix[2, 0] = axis.Z * axis.X * oneMinusCos - axis.Y * sin;
            matrix[2, 1] = axis.Z * axis.Y * oneMinusCos + axis.X * sin;
            matrix[2, 2] = cos + UtilityFunctions.Square(axis.Z) * oneMinusCos;
            return(matrix);
        }