从旋转矩阵Y轴旋转旋转矩阵

2023-09-08 10:45:07 作者:泪已成海却未蓝

下面是我的轴。我不知道该怎么称呼它。 (它是ZXY?) (这是摄像头看到的)

Here are my axes. i dont know what to call it. (is it ZXY?) (this is what camera sees)

我想知道绕Y轴的平面旋转。目前,它是绕Y 0度。

i want to know plane rotation around Y axis. Currently it is 0 degree around Y.

下面是我做的,

Matrix33 orientmatrix = body->getGlobalOrientation();
return Degree(-asin(orientmatrix[2][0]));

这将返回不正确的角度,逆时针:  0..45..90..45..0 ..- 45 ..- 90 ..- 45..0

this returns incorrect angles, in counterclockwise: 0..45..90..45..0..-45..-90..-45..0

应该是: 0 ... 45..90..135..180 ..- 45 ..- 90 ..- 135..0

it should be: 0...45..90..135..180..-45..-90..-135..0

我在做什么错了?

感谢你。

(这是OGRE,code是C ++)

(this is OGRE, code is C++)

推荐答案

你在做什么错的是你正在使用 ASIN 。它返回-pi / 2之间的值至+ pi / 2之间,或-90度到90度。

What you are doing wrong is that you are using asin. It returns a value between -pi/2 to +pi/2, or -90 degrees to +90 degrees.

如果你想有一个值,跨越360度,你需要使用 ATAN2 。假设你的方向的确是一个关于Y轴旋转,你可以使用

If you want a value that spans 360 degrees you need to be using atan2. Assuming your orientation truly is a rotation about y, you could use

Degree(atan2(orientmatrix[0][2], orientmatrix[0][0]))