2

I can't comment other posts yet. ShawnFeatherly in this post wrote:

Here's a way to get the local rotation of just the y-axis. This function can be modified to get the x or z-axis.

/// <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));
}

It works for me! But how can I change this to get xRotation and zRotation? My quaternion representation is (x, y, z, w). Thanks!

m5willmax
  • 41
  • 1
  • 3
  • Look here https://stackoverflow.com/questions/3684269/component-of-a-quaternion-rotation-around-an-axis/22401169#22401169 – minorlogic Jan 24 '19 at 08:26

1 Answers1

1

As far as I know you can do the same with the other components:

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));