如何隔离四元数旋转的x和z分量?

时间:2019-01-22 15:54:33

标签: split rotation quaternions euler-angles

我无法评论其他帖子。 ShawnFeatherly中的post说:

  

这是一种仅获取y轴局部旋转的方法。可以修改此功能以获取x轴或z轴。

/// <summary> isolate the y-Component of a rotation </summary>
private Quaternion yRotation(Quaternion q)
{
    float theta = Mathf.Atan2(q.y, q.w);

    // quaternion representing rotation about the y axis
    return new Quaternion(0, Mathf.Sin(theta), 0, Mathf.Cos(theta));
}

对我有用!但是,如何更改它以获得xRotation和zRotation?我的四元数表示为(x,y,z,w)。谢谢!

1 个答案:

答案 0 :(得分:0)

据我所知,您可以对其他组件执行相同的操作:

float theta_y = Mathf.Atan2(q.y, q.w);

Quaternion yRotation = Quaternion(0, Mathf.Sin(theta_y), 0, Mathf.Cos(theta_y));

float theta_x = Mathf.Atan2(q.x, q.w);

Quaternion xRotation = Quaternion(Mathf.Sin(theta_x), 0, 0, Mathf.Cos(theta_x));

float theta_z = Mathf.Atan2(q.z, q.w);

Quaternion zRotation = Quaternion(0, 0, Mathf.Sin(theta_z), Mathf.Cos(theta_z));