# finding pitch/roll/yaw from Quaternions

I’m using YEI 3-Space Sensor which gives me x,y,z,w Quaternions.
Converting that to Euler angles is done by assigning Quaternions to an object then you can see Euler angles.
I thought I could use Euler format as pitch/roll/yaw, but since Euler is dependent on the sequence those rotations are applied… I now have only “Pitch”(X) since it’s the first applied rotation.

I’ve seen matrices to solve this but isn’t there just a straight forward 1 or 2 equations to solve this?

I think I just need pointing to where i should be looking.

TL;DR:
if you have Quaternions ,Euler Angles and pitch.
How would you find pitch/roll/yaw?

Thanks!

I guess I should avoid using Euler angles just because you may face gimbal lock issues.
I solved it using these equations that use Quaternion(x,y,z,w):

``````roll  = Mathf.Atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z);
pitch = Mathf.Atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z);
yaw   =  Mathf.Asin(2*x*y + 2*z*w);
``````

although I have not understood why roll and pitch values range from 3.14 to -3.14 and yaw is 1.52~ to -1.52, but anyway it’s working like a charm !
thanks for the help

Quaternion q = transform.rotation;
float Pitch = Mathf.Rad2Deg * Mathf.Atan2(2 * q.x * q.w - 2 * q.y * q.z, 1 - 2 * q.x * q.x - 2 * q.z * q.z);
float Yaw = Mathf.Rad2Deg * Mathf.Atan2(2 * q.y * q.w - 2 * q.x * q.z, 1 - 2 * q.y * q.y - 2 * q.z * q.z);
float Roll = Mathf.Rad2Deg * Mathf.Asin(2 * q.x * q.y + 2 * q.z * q.w);

Pitch - yaw - Roll :: X - Y - Z