Strange behaviour of quaternions

Could someone run this piece of code and tell me what is wrong?



[java]

public static void main(String[] args) {

float[] angles = new float[] {-FastMath.HALF_PI, FastMath.PI, FastMath.HALF_PI};

Quaternion q = new Quaternion(angles);

System.out.println(Arrays.toString(angles));

System.out.println(q);

System.out.println(Arrays.toString(q.toAngles(null)));

}

[/java]



I get the following results:

[-1.5707964, 3.1415927, 1.5707964]

(0.50000006, 0.50000006, 0.5, 0.5)

[0.0, 1.5707965, 1.5707964]

i confirm i get the same results. I don’t know enough of the details, but i will say it looks a bit strange that toAngles() doesn’t return the same initial values.

That it doesn’t return the same values is actually normal. Whether or not it is returning incorrect values is another question entirely.



I believe the sets of euler angles are actually equivalent but my brain has trouble working after the second rotation. Combining multiple 180 and 90 degree rotations is likely to produce some kind of gimbal lock, though.



Another good test would be to see if feeding them back into another quaternion produces the same quaternion…

Is there a techy Blender forum where such questions might be asked?