Hey all. Math problem help requested! Given the following: Code: float Quaternion::getYaw() { return asin(-2*(x*z - w*y)); } I get in the range -Pi/2 to Pi/2, however I want the value in absolute range from 0..2Pi My problem is that I cant just translate and scale the value because the angles returned are not continuous but form a series of curves (like a sin/cos curve if you will). I'm sure there's an easy way to transform a sin/cos curve into a 0..X value, but its escaping me. Anyone know?

I'm not completly sure what you are trying to achieve, but I understand it like this: You want to create a function f:[-1, 1] -> [0, 2PI], so that sin(f(x)) = x. (I hope I don't overcomplicate things here). If this is right, then I'm afraid, that this won't work, since the problem is ambigous. 0 could for example be mapped to 0 or to PI. Thus f would not be a well defined function. In order to map to the full range between 0 and 2PI, you would need more parameters. I hope I didn't get it completly wrong! Kind regards, Sebastian

Probably this is better: Since all values of sin(x) for x between 0 and PI are positive, you can't map [-1, 1] to [0,PI] using asin. Regards, Sebastian

The yaw method I'm using above returns -90 to +90 (in degrees), which isnt really what I'm after. I'm after a point on the circle 0..360 degrees. Given that its a yaw, that makes sense. Trouble is that I pass in a 0..360 when I create the quaternion, I now want to get it back out again only this is giving me -90..90 which isnt really that useful. Its basically the phase of the angle I'm getting, where as I want an absolute angle.

Judging by http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion it seems like you're computing the pitch, not the yaw. Try the last equation on that page. OTOH, your coordinate frame is quite likely different from the traditional one that page uses, so you might be stuck having to re-derive the conversion, which is a bit beyond me right at this moment. Or just mess around until you hit on a formula that works!

I know little maths, but perhaps you have an entity with rotation as a quaternion and you want to get its "look angle" in the ground plane? If so, make a unit vector, rotate it by the quaternion, then you can use the X,Z components and trigonometry to calculate the yaw angle. Using the Irrlicht engine maths library I do something like this:- Code: // Extract the Y component from a rotation. // Rotation starting at {0,0,1} f32 extract_y_rotation(const core::quaternion &quat) { // Rotate a unit vector by the quaternion core::vector3df vec(0,0,1); vec = quat * vec; // Then get the yaw angle from that unit vector core::vector2df vec2d(vec.X,vec.Z); vec2d.normalize(); return vec2d.getAngle(); }