gpt4 book ai didi

c++ - 我可以从这个矩阵算法中得到旋转吗

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:19 25 4
gpt4 key购买 nike

我可以从这个矩阵算法中获得旋转(偏航、俯仰、滚动)吗?谢谢

matrix[0][0] = cos(pitch)*cos(yaw);
matrix[0][2] = cos(pitch)*sin(yaw);
matrix[0][1] = sin(pitch);
matrix[0][3] = 0;
matrix[1][0] = -cos(roll)*sin(pitch)*cos(yaw)+sin(roll)*sin(yaw);
matrix[1][1] = cos(roll)*cos(pitch);
matrix[1][2] = -cos(roll)*sin(pitch)*sin(yaw)-sin(roll)*cos(yaw);
matrix[1][3] = 0;
matrix[2][0] = -sin(roll)*sin(pitch)*cos(yaw)-cos(roll)*sin(yaw);
matrix[2][1] = sin(roll)*cos(pitch);
matrix[2][2] = cos(roll)*cos(yaw)-sin(roll)*sin(pitch)*sin(yaw);
matrix[2][3] = 0;
matrix[3][0] = 0;
matrix[3][1] = 0;
matrix[3][2] = 0;
matrix[3][3] = 1;

编辑:我使用了这段代码,但它不起作用:

D3DXMATRIX matrix2 = D3DXMATRIX(matrix);
yaw = atan2(matrix2._13, matrix2._11);
pitch = asin(matrix2._12);
roll = atan2(matrix2._32, matrix2._22);

编辑 3:这是我的旧功能,它有效但不是 100%

VECTOR getAnglefromMatrix(float* m)
{
float pitch, yaw, roll;

D3DXMATRIX matrix = D3DXMATRIX(m);

if (matrix._11 == 1.0f)
{
yaw = todegree(atan2f(matrix._13, matrix._34));
pitch = 0;
roll = 0;
}
else if (matrix._11 == -1.0f)
{
yaw = todegree(atan2f(matrix._13, matrix._34));
pitch = 0;
roll = 0;
}
else
{

yaw = todegree(atan2(-matrix._31,matrix._11));
pitch = todegree(asin(matrix._21));
roll = todegree(atan2(-matrix._23,matrix._22));
}

return vector3d(yaw,pitch,roll);
}

我做错了什么?

最佳答案

我们可以浏览这些条目并找到一些对回溯计算有用的条目:

matrix[0][0] = cos(pitch)*cos(yaw);
matrix[0][2] = cos(pitch)*sin(yaw);

这给了我们:

yaw = atan2(matrix[0][2], matrix[0][0])

对于球场:

matrix[0][1] = sin(pitch);

这给了我们:

pitch = asin(matrix[0][1])  //this assumes pitch is between -pi/2 and +pi/2

然后

matrix[1][1] = cos(roll)*cos(pitch);
matrix[2][1] = sin(roll)*cos(pitch);

这给了我们:

roll = atan2(matrix[2][1], matrix[1][1])

我省略了 atan2 的参数变为零的情况。我相信你能弄明白。在这些情况下,欧拉角不是唯一定义的。

关于c++ - 我可以从这个矩阵算法中得到旋转吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58173768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com