Jump to content

Quaternion.RotationYawPitchRoll parameters and toEulerAngles result should be the same ?


Maxence
 Share

Recommended Posts

Hi,

 

I am working on decomposing the world matrix of a mesh,

I need it in order to keep rotation, scale and position of a mesh in world space (because these parameters are relative to the parent) if you import it without importing its parents.

 

By testing different codes to decompose the matrix and to transform it into a quaternion, I notice that when you create a BABYLON.quaternion.RotationYawPitchRoll(yaw, pitch, roll) and you call the toEulerAngles() method on this quaternion, it does not return the passed yaw, pitch and roll.

 

I wonder if this behavior is normal ? if yes can you explain me why ?

 

I made a JsFiddle to explain my question.

 

http://jsfiddle.net/Gc7n8/1/

 

Please look at the console line to see the log.

Link to comment
Share on other sites

I try something using math and conventions from here : http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm

Euler to Quaternion : http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm

Quaternion to Euler : http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm

 

I get right Euler to Quaternion and Quaternion to Euler conversions but ... i got also some issues with the world matrix.

 

http://jsfiddle.net/JulienGobin/BZ4A4/42/

 

It seems that the quaternion compute currently with the babylon js way are wrong :wacko: (i hope it's not and i'm wrong, but after double-triple check the math and the convention ...).

 
Link to comment
Share on other sites

If you're right, it means some changes may be needed in other places of the code to correct the maths but unfortunately the exporters may need to be updated too to get the right quaternions stored in the .babylon file. Moreover old scenes may not load as before (different rotations) and may need to be exported again.

Link to comment
Share on other sites

I'm not absolutely sure. Here my test :
 

First on babylon js using BABYLON.Quaternion.YawPitchRoll with yaw = 0.1, pitch = 0.2, roll = 0.3 (assuming it's in radians)

 

q = (x: 0.10602051106179562, y: 0.034270798550482096, z: 0.1435721750273919, w: 0.9833474432563558).

 

Second using the Calculator on this page http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm (at "Angle Calculator and Further examples"):

 

- with heading = yaw, attitude = -roll, bank = pitch cause of the two differents conventions using by BabylonJS and euclideanspace.com (http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm)

- after radian to degree conversion (using this : http://www.unitjuggler.com/convertir-angle-de-rad-en-deg.html) heading = 5.7295779513082, attitude = -17.188733853925, bank = 11.459155902616.

 

q = (real: 0.9833474432563557, i: 0.0911575493429866, j: 0.034270798550482165, k: -0.153439302024225).

If w = real and y = j (sounds logical) x != i and z != k (sounds a bit less logical).

 

Did i miss something ? (wrong conversion maybe ?)

Link to comment
Share on other sites

Deltakosh, could we imagine that the quaternion in the .babylon file (using BabylonJS exporter for Blender) is wrong and that the functions to compute the matrices correct it? Something like: a multiplication of two negative numbers gives a positive number but they should have been positive from the beginning.

 

I haven't looked deeper in the exporter code neither in the functions to compute the matrices so it's just a suggestion.

Link to comment
Share on other sites

The quaternion code should be good because they works well with quaternion exported from blender for instance.

 

Could you precise where could be the error?

 

I had a look to https://raw.github.com/BabylonJS/Babylon.js/master/Exporters/Blender/io_export_babylon.py. Apparently you always store rotation (euler angles) and not rotationQuaternion. My previous answer should be:

 

"Deltakosh, could we imagine that the rotation (euler angles) in the .babylon file (using BabylonJS exporter for Blender) is wrong and that the functions to compute the matrices correct it? Something like: a multiplication of two negative numbers gives a positive number but they should have been positive from the beginning"

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 2 weeks later...

(Sorry, again, for the long time past)

I still have some issue.

I got the good euler -> quaternion and quaternion -> euler conversion (and the good quaternion -> matrix and matrix -> quaternion conversions)

But, currently my math use a XYZ and not a YXZ euler order rotation, i'm working on it.

Link to comment
Share on other sites

Here my problem : http://jsfiddle.net/JulienGobin/BZ4A4/

As i said I got the good euler <-> quat <-> matrix conversions, you can see that trying to use these commands in the console after clicking on the "Use euclideanspace conversions" button :

 

euler <-> quat

var e = new BABYLON.Vector3(0.1, 0.2, 0.3);
var q = BABYLON.Quaternion.RotationYawPitchRoll(e.y, e.x, e.z);

 

console.log(e);                 // BABYLON.Vector3 {x: 0.1, y: 0.2, z: 0.3}

console.log(q.toEulerAngles()); // BABYLON.Vector3 {x: 0.09999999999999999, y: 0.2, z: 0.30000000000000004}

 

quat <-> mat

 

var m = BABYLON.Matrix.Identity();
q.toRotationMatrix(m);

 

console.log(q);              // BABYLON.Quaternion {x: 0.06407134770607098, y: 0.09115754934299045, z: 0.14357217502739153, w: 0.983347443256353}

console.log(m.toQuaternion); // BABYLON.Quaternion {x: 0.06407134770607098, y: 0.09115754934299045, z: 0.14357217502739153, w: 0.983347443256353}

 

 

But i don't got the good rotation (euler order are wrong). I'm working trying to fixe that.
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...