问题描述
我有 3 个轴的加速度计值(通常当只有重力包含 -1.0 和 1.0 之间的数据时):
I have accelerometer values for the 3 axes (usually when there is only gravity contains data between -1.0 and 1.0 ):
float Rx;
float Ry;
float Rz;
我做了一些计算,然后得到每个轴的角度.
I make some calculations, then I get the angles for each axis.
float R = sqrt(pow(Rx,2)+pow(Ry,2)+pow(Rz,2));
float Arx = acos(Rx/R)*180/M_PI;
float Ary = acos(Ry/R)*180/M_PI;
float Arz = acos(Rz/R)*180/M_PI;
然后我在 opengl 中设置盒子角度的值
Then I set the values for the box angles in opengl
rquad = Arx;
yquad = Ary;
哪个旋转我的盒子:
glRotatef(yquad,1.0f,0.0f,0.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
它适用于半球.我想使用完整的球体,我知道我必须使用 Arz 值才能使其工作,但我不知道如何将其用于此旋转.你能帮我吗?
It works on a hemisphere. I would like to use the full sphere and I know that I have to use the Arz value to make it work, but I don't know how can I use that for this rotation. Could you help me?
更新:最后的答案是在我的情况下:
Update: The final answer is in my case:
rquad = -atan2(Rx/R, Rz/R)*180/M_PI;
yquad = -atan2(Ry/R, Rz/R)*180/M_PI;
推荐答案
正确答案是:
Roll = atan2(Y, Z) * 180/M_PI;
Pitch = atan2(-X, sqrt(Y*Y + Z*Z)) * 180/M_PI;
来源:http://www.freescale.com/files/sensor/doc/app_note/AN3461.pdf(第 10 页,方程 25 和 26)
Source: http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf (page 10, Eqn. 25 & 26)
uesp 的回答是错误的.在俯仰和滚转都超过 45 度之前,这看起来是一个可以接受的近似值.
uesp's answer is wrong. It looks like an acceptable approximation until pitch and roll both go above 45 degrees.
我可能假设了不同的方向约定,但即使您以任何一致的方式交换轴和反转值,uesp 的计算也永远不会等效.
I may be assuming a different orientation convention, but even if you swap axes and invert values in any consistent way, uesp's computations will never be equivalent.
这篇关于3d 加速度计计算方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2