四元数和球面旋转坐标之间的正确转换? [英] Proper conversion between Quaternions and Spherical Rotation Coordinates?
问题描述
我正在学习更多的四元数转换,并且在本网站的以下部分中有一个关于四元数到球面旋转转换代码的问题:
I'm learning about more quaternion conversions and I have a question regarding quaternion to spherical rotation conversion code at the following section of this website:
http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q59
此代码中的angle和sin_angle应该是什么?角度从未使用过,所以我猜它是旋转角度.是sin_angle应该是sin_a吗?
What are angle and sin_angle in this code supposed to be? Angle is never used so I was guessing it's the rotation angle. Is sin_angle supposed to be sin_a?
如果这是一个返回带有球面旋转数据的float数组的函数,[角度,纬度,经度]是转换后的四元数的合适表示吗?
If this was a function returning an array of float with the spherical rotation data, would [angle, latitude, longitude] be an appropriate representation of the converted quaternion?
cos_a = W;
sin_a = sqrt( 1.0 - cos_a * cos_a );
angle = acos( cos_a ) * 2;
if ( fabs( sin_angle ) < 0.0005 ) sin_a = 1;
tx = X / sin_a;
ty = Y / sin_a;
tz = Z / sin_a;
latitude = -asin( ty );
if ( tx * tx + tz * tz < 0.0005 )
longitude = 0;
else
longitude = atan2( tx, tz );
if ( longitude < 0 )
longitude += 360.0;
推荐答案
四元数是四个数字 [X,Y,Z,W]
,它们编码旋转方向和角度.该代码提取此信息,并将旋转轴转换为纬度和经度.
A quaternion is four numbers [X,Y,Z,W]
that encode a rotation direction and an angle. The code extracts this information and converts the rotation axis into a latitude and longitude.
- 从旋转轴
- 四元数构造为
-
X = tx * SIN(theta/2)
-
Y = ty * SIN(theta/2)
-
Z = tz * SIN(theta/2)
-
W = COS(theta/2)
- Quaternion construction from rotation axis
[tx,ty,tz]
and angletheta
isX = tx*SIN(theta/2)
Y = ty*SIN(theta/2)
Z = tz*SIN(theta/2)
W = COS(theta/2)
由于
angle = 2 * ACOS(W)= 2 *(theta/2)= theta
,因此此代码执行相反的操作.因此,变量angle
存储旋转角度.This code does the reverse, since
angle = 2*ACOS(W) = 2*(theta/2) = theta
. So the variableangle
stores the rotation angle.这篇关于四元数和球面旋转坐标之间的正确转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-
[tx,ty,tz]
和角度 theta
的