# Quaternion angle calculation

I'm working on a programming project, in this project I'm receiving an angle as a quaternion value, I partially understand how they work but I don't find any math to get the values I need.
What I would need is the angle between a fictional line/vector going to the the quaternion point from the origin (yes I know what you are thinking, but I couldn't think of a better explanation) and the "earth" a plane that is perpendicular to the gravitational vector, in this case one of your planes of reference.
Also I would need to get the rotation of the line/vector, this time the rotation should be according to the plane perpendicular to itself.
If possible all angles should be described as an angle between -180° and 180° (that's were my troubles are from.

If someone could help me by this it would be awesome
~TJ

In this picture γ complementary angle of the first questing and R is the secondary angle.
Angles

• Do you mean something like Conversion between quaternions and Euler angles? – Somos Jan 15 at 23:13
• I actualy tried implementing that a few times but it did't give me a result between -180° and 180°, I alsways had -90° to 90°. These are the formulas I used. – Tim Jager Jan 16 at 6:12
• gx = 2 * (xz - wy) || gy = 2 * (wx + yz) || gz = ww - xx - yy + zz || yaw = atan2(2*xy - 2*wz, 2*ww + 2*xx - 1) || pitch = atan(gx / sqrt(gygy + gzgz)) || float roll = atan(gy/gz) – Tim Jager Jan 16 at 6:19
• You should always use atan2(y,x) instead of atan(y/x). It is a common mistake. – Somos Jan 16 at 14:59
• That did it. Thank you Somos. – Tim Jager Jan 16 at 19:49