我從一些軟件中得到一個變換矩陣,我必須提取軸旋轉。我不確定確切的名稱,但我想要有與Matrix4d.rotX(a)相反的功能。從矩陣4d提取旋轉
比方說,我有這樣的代碼:
Matrix4d matrix = new Matrix4d();
matrix.setIdentity();
Matrix4d m = new Matrix4d();
m.rotX(a);
matrix.mul(m);
m.rotY(b);
matrix.mul(m);
m.rotZ(c);
matrix.mul(m);
我希望能夠得到的值,b和c的矩陣。會有人有想法嗎?我在3D中幾乎沒有任何經驗,我查看了java vecmath包,但找不到任何東西。
我試着用下面的:
public static float[] getRotation(Matrix4f matrix) {
float Yaw;
float Pitch;
float Roll;
if (Math.abs(matrix.m00 + 1.0f) < 0.01f)
{
Yaw = (float) Math.atan2(matrix.m02, matrix.m23);
Pitch = 0;
Roll = 0;
}else if (Math.abs(matrix.m00 -1.0f) < 0.01f)
{
Yaw = (float) Math.atan2(matrix.m02, matrix.m23);
Pitch = 0;
Roll = 0;
}else
{
Yaw = (float) Math.atan2(-matrix.m20,matrix.m00);
Pitch = (float) Math.asin(matrix.m10);
Roll = (float) Math.atan2(-matrix.m12,matrix.m11);
}
return new float[] { Yaw, Pitch, Roll};
}
和
public static float[] GetRotation(Matrix4f matrix) {
float Yaw;
float Pitch;
float Roll;
if (matrix.m00 == 1.0f)
{
Yaw = (float) Math.atan2(matrix.m20, matrix.m32);
Pitch = 0;
Roll = 0;
}else if (matrix.m00 == -1.0f)
{
Yaw = (float) Math.atan2(matrix.m20, matrix.m32);
Pitch = 0;
Roll = 0;
}else
{
Yaw = (float) Math.atan2(-matrix.m02,matrix.m00);
Pitch = (float) Math.asin(matrix.m01);
Roll = (float) Math.atan2(-matrix.m21,matrix.m11);
}
return new float[] { Yaw, Pitch, Roll};
}
但價值是錯誤的
相關:http://gamedev.st ackexchange.com/questions/50963/how-to-extract-euler-angles-from-transformation-matrix –
我已經嘗試過,但無法讓它工作。 – kelto
你還沒有分享你的代碼,所以我不能提供任何提示錯誤的地方。 –