四元数和球面旋转坐标之间的正确转换? [英] Proper conversion between Quaternions and Spherical Rotation Coordinates?

查看:40
本文介绍了四元数和球面旋转坐标之间的正确转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在了解更多四元数转换,但我对本网站以下部分的四元数到球面旋转转换代码有疑问:

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?

如果这是一个返回带有球面旋转数据的浮点数组的函数,那么 [angle, latitude, longitude] 是否是转换后的四元数的合适表示?

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.

  • 从旋转轴 [tx,ty,tz] 和角度 theta 构造四元数是
    • 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 angle theta is
      • X = 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 variable angle stores the rotation angle.

      这篇关于四元数和球面旋转坐标之间的正确转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆