从四元数中提取偏航 [英] Extracting Yaw from a Quaternion
问题描述
我有一个旋转四元数,并且想要提取绕Up轴(偏航角)的旋转角度.我正在使用XNA,据我所知,没有内置功能.最好的方法是什么?
I have a rotation quaternion and want to extract the angle of rotation about the Up axis (the yaw). I am using XNA and as far as I can tell there is no inbuilt function for this. What is the best way to do this?
感谢您的帮助, 韦纳图
Thanks for any help, Venatu
推荐答案
旋转的四元数表示形式是轴线和角度的变化.因此,如果绕轴 x , y , z 旋转 r 弧度,则四元数 q 是:
The quaternion representation of rotation is a variation on axis and angle. So if you rotate by r radians around axis x, y, z, then your quaternion q is:
q[0] = cos(r/2);
q[1] = sin(r/2)*x;
q[2] = sin(r/2)*y;
q[3] = sin(r/2)*z;
如果要创建仅绕 y 轴旋转的四元数,可以将 x 和 z 轴归零,然后重新-对四元数进行归一化:
If you want to create a quaternion that only rotates around the y axis, you zero out the x and z axes and then re-normalize the quaternion:
q[1] = 0;
q[3] = 0;
double mag = sqrt(q[0]*q[0] + q[2]*q[2]);
q[0] /= mag;
q[2] /= mag;
如果想要得到的角度:
double ang = 2*acos(q[0]);
这假设四元数表示形式已存储:w,x,y,z.如果q [0]和q [2]都为零或接近零,则四元数应为{1,0,0,0}.
This assumes that the quaternion representation is stored: w,x,y,z. If both q[0] and q[2] are zero, or close to it, the resulting quaternion should just be {1,0,0,0}.
这篇关于从四元数中提取偏航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!