Nu/Nu.Math/Matrix3x3.cs
/// <summary>
/// Build a rotation matrix from the specified axis/angle rotation.
/// </summary>
/// <param name="axis">The axis to rotate about.</param>
/// <param name="angle">Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).</param>
/// <param name="result">A matrix instance.</param>
Build a rotation matrix from the specified axis/angle rotation.
Build a rotation matrix from the specified axis / angle rotation .
public static void CreateFromAxisAngle(Vector3 axis, float angle, out Matrix3x3 result)
        {
            var axisN = Vector3.Normalize(axis);
            float axisX = axisN.X, axisY = axisN.Y, axisZ = axisN.Z;
            float cos = (float)System.Math.Cos(-angle);
            float sin = (float)System.Math.Sin(-angle);
            float t = 1.0f - cos;
            float tXX = t * axisX * axisX,
            tXY = t * axisX * axisY,
            tXZ = t * axisX * axisZ,
            tYY = t * axisY * axisY,
            tYZ = t * axisY * axisZ,
            tZZ = t * axisZ * axisZ;
            float sinX = sin * axisX,
            sinY = sin * axisY,
            sinZ = sin * axisZ;
            result.Row0.X = tXX + cos;
            result.Row0.Y = tXY - sinZ;
            result.Row0.Z = tXZ + sinY;
            result.Row1.X = tXY + sinZ;
            result.Row1.Y = tYY + cos;
            result.Row1.Z = tYZ - sinX;
            result.Row2.X = tXZ - sinY;
            result.Row2.Y = tYZ + sinX;
            result.Row2.Z = tZZ + cos;
        }
public static void CreateFromAxisAngle ( Vector3 axis , float angle , out Matrix3x3 result ) { var axisN = Vector3 . Normalize ( axis ) ; float axisX = axisN . X , axisY = axisN . Y , axisZ = axisN . Z ; float cos = ( float ) System . Math . Cos ( - angle ) ; float sin = ( float ) System . Math . Sin ( - angle ) ; float t = 1.0f - cos ; float tXX = t * axisX * axisX , tXY = t * axisX * axisY , tXZ = t * axisX * axisZ , tYY = t * axisY * axisY , tYZ = t * axisY * axisZ , tZZ = t * axisZ * axisZ ; float sinX = sin * axisX , sinY = sin * axisY , sinZ = sin * axisZ ; result . Row0 . X = tXX + cos ; result . Row0 . Y = tXY - sinZ ; result . Row0 . Z = tXZ + sinY ; result . Row1 . X = tXY + sinZ ; result . Row1 . Y = tYY + cos ; result . Row1 . Z = tYZ - sinX ; result . Row2 . X = tXZ - sinY ; result . Row2 . Y = tYZ + sinX ; result . Row2 . Z = tZZ + cos ; }
Build a rotation matrix from the specified axis/angle rotation.
Build a rotation matrix from the specified axis / angle rotation .
//normalize and create a local copy of the vector. //calculate angles //do the conversion math once
axis
Vector3
The axis to rotate about.
The axis to rotate about .
angle
float
Angle in radians to rotate counter-clockwise (looking in the direction of the given axis).
Angle in radians to rotate counter - clockwise ( looking in the direction of the given axis ) .
Matrix3x3
out
result
A matrix instance.
A matrix instance .