The components of a quaternion are not angles. You can convert a quaternion to Euler angles using the .toAngles() method and convert to degrees using FastMath.RAD_TO_DEG . I’m not sure that’s what you want, but it’s probably closer.
I never had success myself using the “FastMath.DEG_TO_RAD” to rotate stuff, but Ive used “FastMath.pi” multiplied by fractions and it worked. Quaternions always confuse me, so anytime I need to do any rotating with them I have to look back to slide 33 in the Math for Dummies slide and I can usually figure out how to get the rotations I need https://jmonkeyengine.github.io/wiki/tutorials/math/assets/fallback/index.html
Paul, you’re correct that Euler angles introduce ambiguity in the representation of 3-dimensional orientations. But so do quaternions.
In fact, there are an infinite number of quaternions that describe any particular orientation (or rotation) in 3-D: the orientation described by a quaternion Q is equivalent to that described by kQ for any scalar k. Even if you limit your representations to normalized (unit) quaternions, there’s still ambiguity because Q and -Q represent the same rotation. Quaternions offer many advantages over angles, but complete absence of ambiguity isn’t among them.
In yn97’s case, it appears that all the rotation is around the Y axis. If so, the quaternion represents a 2-D rotation, for which it’s relatively easy disambiguate the angle. Just remember that adding multiples of TWO_PI radians (or 360 degrees) results in an equivalent orientation.
If the rotation isn’t entirely around the Y axis, then it’s a tough problem. @yn97, before calculating the Y rotation angle for a rotation around some other axis, you’ll need to carefully define what you mean by that.
Not really. Other then the Q = -Q “ambiguity”, a Quaternion is a unique rotation. You will never find another Quaternion (other than -Q) that points a vector in that particular direction, for example. It’s similar to a normalized angle-axis in that respect.
Even in one plane you cannot expect to get your yaw back if you put it in. That particular orientation could have been reached by rotations in the other plane or some contribution of rotations in the other planes.
For example, a yaw rotation of 90 degrees can also be a pitch and roll rotation. (In fact, yaw > 90 or < -90 will often return quaternions just like that.)
So, if you put yaw into it and want to get that same yaw -180 to 180 out again… then you have to keep the yaw separately or do some more complicated math with the direction vector.
Edit: and frankly, if you need that sort of yaw for anything other than displaying to a user, 99% of the time there was a better way to do what you are doing using the quatenion/direction vectors themselves and bypassing angles completely.
It is true that kQ=Q and -Q=Q,where k is a scalar and Q a quaternion.
For example Q(0.5,0,0,0.5) equals Q(1,0,0,1) which equals Q(-0.5,0,0,-0.5) which all equal Pitch 90.
That indeed makes an infinite number of quaternions representing the exact same rotation.
Euler angles are not unique. For example, yaw can be the same as pitch and a roll. You can’t do that with quaternions no matter how hard you try. Since the quaternion will be unique, you are not guaranteed to get the same euler angles out again… it has made them compact and disambiguous beyond just normalizing the angles.
I automatically assume when talking about rotations that we are talking about normalized quaternions… because you end up with issues with the unnormalized ones.
It seems your ask for help might have been derailed a bit by a Euler Mathematics throw down.
Just curious if you got the answer you needed or do you still need some guidance?
If you still need some help I’d ask what you’re planning on using this for? To me it vaguely sounds like you might want to create a compass of some sorts. Is that correct?