I am using System.Numerics and I am trying to build a rotation matrix using methods such as CreateFromAxisAngle(Vector3, Single)
and CreateRotationY(Single)
.
Let's say I want to build a rotation matrix that represents a rotation of 90° aroud the y axis. The output I would expect is:
0 0 1 0
0 1 0 0
-1 0 0 0
0 0 0 1
This is, for example, the output generated by Matlab, and the result suggested by the formula on Wikipedia.
However, when I execute Matrix4x4.CreateRotationY((float)(Math.PI / 2))
or, alternatively, Matrix4x4.CreateFromAxisAngle(new Vector3(0, 1, 0), (float)(Math.PI / 2))
the output I get is:
0 0 -1 0
0 1 0 0
1 0 0 0
0 0 0 1
I can easily implement my own function to creare the rotation matrix, but I am trying to understand if System.Numerics uses a different standard or if I am missing something.
Thanks
I can add here the implementation of CreateRotationY(Single)
, where it is clear they use -sine in position 1,3 of the matrix, where it should be sine.
float num1 = (float) Math.Cos((double) radians);
float num2 = (float) Math.Sin((double) radians);
Matrix4x4 rotationY;
rotationY.M11 = num1;
rotationY.M12 = 0.0f;
rotationY.M13 = -num2;
rotationY.M14 = 0.0f;
rotationY.M21 = 0.0f;
rotationY.M22 = 1f;
rotationY.M23 = 0.0f;
rotationY.M24 = 0.0f;
rotationY.M31 = num2;
rotationY.M32 = 0.0f;
rotationY.M33 = num1;
rotationY.M34 = 0.0f;
rotationY.M41 = 0.0f;
rotationY.M42 = 0.0f;
rotationY.M43 = 0.0f;
rotationY.M44 = 1f;