Quaternion to euler returns wrongs angles

Hi all, i hope this is the right place to ask for my problem.
I want to convert a quaternion into euler angles but values looks wrong.
This is the piece of code

// values are in x, y, z, w order
var rot = new BABYLON.Quaternion(-0.1245631, 0.7443593, -0.6470615, -0.108281);
var euler = rot.toEulerAngles();

if i print euler, the content is
X: 1.4311703869613368 Y: 3.141592409759389 Z: -0.33161295970567284
and if i converted in degrees with BABYLON.Angle(angle_rad).degrees(), they are around
X: 82 Y: 179 Z:340

but the values are wrong. The values i expect are X: 98 Y: 0 Z: 161
I tested the quaternion value also in Unity3D and online tools and all returns 98, 0, 161.

But another stranger thing is if i set the values (-0.1245631, 0.7443593, -0.6470615, -0.108281)
to a quaternion of an object in Unity3D, the object rotate correctly,
while if i set the values in a quaternion of Babylon, the rotation object is different.
Maybe the euler problem is just an effect and the real problem is the quaternion itself.

What’s wrong? I spent a whole day figuring out what’s wrong.
Thanks at all

Welcome aboard!

If I use MathLab to do the conversion, it yields the same results than in Babylon, save for Y/Z inversion and the values being negated (I think we don’t use the same coordinate system):

Values are not exactly the same, maybe it’s a precision problem in the computation, but the values are still close to X: 1.4311703869613368 Z: -0.33161295970567284 Y: 3.141592409759389.

I guess it depends on the coordinate system: the values returned by Babylon are offseted by 180° from the values you expect.

1 Like

Hi @Qualcuno and welcome from me.

This docs page Rotation Quaternions | Babylon.js Documentation has a playground Babylon.js Playground showing that the conversion matches in Babylon.js.

1 Like

I will take a look at the start of next week.
Thanks at all for the support and have a good weekend :wink: