# Simple question (I hope) about Quaternions

Hello there,

If I have rotated an object, and I later want to work out the rotations, how do I get back the andles (in degrees) for the x, y and z?

Example: So I've done this first:

``` Quaternion rotation = new Quaternion(); rotation.fromAngles(FastMath.PI * (xAngle/180f), FastMath.PI * (yAngle/180f), FastMath.PI * (zAngle/180f)); spatial.setLocalRotation(rotation); ```

Great, now if I do this:

``` Quaternion rotation = spatial.getLocalRotation(); ```

How do I get my xAngle, yAngle and zAngle again? I have tried all sorts. I thought something like:

``` float[] radians = rotation.toAngles(null); float xAngle = SceneController.radiansToDegrees(radians); float yAngle = SceneController.radiansToDegrees(radians); float zAngle = SceneController.radiansToDegrees(radians); ```

But that ain't right (unless I'm missing something!).

Cheers
Richard

``` float xAngle = FastMath.RAD_TO_DEG * radians; ```

should work

Thanks dhdd, but that isn't working either.

I think I'm homing in on the problem, but my mathematical skills just do not have the capacity to understand how to solve the problem. The long and short of it is that "Quaternion.toAngles()" will not always (in fact, hardly ever) directly translate the rotation back from the rotation created in "Quaternion.fromAngles()".

Example:
Before (degrees): xDeg=15 yDeg=160 zDeg=170

Quaternion rotation = new Quaternion();

After (degrees): xDeg=-165 yDeg=-20 zDeg=10

You'll notice (maybe) that by adding or subtracting 180 from the "After (degrees)" values, you can get back to the original value. But there doesn't seem to be any consistency on whether it needs subtracting or not. At least, I haven't spotted it yet!

I've created a test class that illustrates the point.

``` import com.jme.math.FastMath; import com.jme.math.Quaternion; public class QuaternionTest {     public static void main(String[] args) {         Quaternion rotation = new Quaternion();         float xRad = FastMath.DEG_TO_RAD * 15.0f;         float yRad = FastMath.DEG_TO_RAD * 160.0f;         float zRad = FastMath.DEG_TO_RAD * 170.0f;         System.out.println("xrad=" + xRad + " yrad=" + yRad + " z=" + zRad);         rotation.fromAngles(xRad, yRad, zRad);         System.out.println("rot=" + rotation);         float[] toRads = rotation.toAngles(null);         System.out.println("x=" + toRads + " y=" + toRads + " z=" + toRads);         System.out.println("xdeg=" + (toRads * FastMath.RAD_TO_DEG));         System.out.println("ydeg=" + (toRads * FastMath.RAD_TO_DEG));         System.out.println("zdeg=" + (toRads * FastMath.RAD_TO_DEG));     } } ```

So come on you clever folk... What am I missing!?

Richard