Jump to content

Quaternion to Euler Changes!


JohnK
 Share

Recommended Posts

It seems that from BJS2.3 to BJS2.4 to BJS2.5 the function toEulerAngles when applied to a quaternion has been reinterpreted and changed.

The confusion has probably arisen because there can be many interpretations of Euler Angles and how they are applied.

In BJS2.3 the toEulerAngles function was - given an orientation in quaternion form supply the Euler Angles that can be applied using the ZXZ convention to produce the same rotation.

In BJS2.5 the function toEulerAngles is - given an orientation in quaternion form supply the Euler Angles in the order x, y, z that can be used as parameters for mesh.rotation

In BJS2.4 I can see the reasoning was to add potentially more conventions but work with the same intention as for BJ2.3.

In other words I think the intention for BJS2.3 and BJS2.4, in a limited way, was knowing an orientation through a quaternion, then for any given convention quaternion.toEulerAngles(convention) would return the alpha, beta, gamma to be used for that convention to produce the same rotation,

ie an inverse function EULER-->QUATERNION, CONVENTION-->EULER.

In BJS2.5 knowing an orientation through a quaternion, then quaternion.toEulerAngles() returns three angles to be plugged into mesh.rotation

ie EULER-->QUATERNION-->NEW EULER ANGLES FOR CONVENTION ZXY in order x, y, z

My questions are -

  1. Is the interpetation used in BJS2.5 the one wanted? IMHO the answer is yes it is probably what most people expect, though the original author will, I expect, not agree?
  2. Any breaking changes issues that anyone is worried about?
  3. Anybody require the inverse type interpretation as of 2.3 and 2.4 (if so new additional functions will be necessary)

If 1 and not 2 then I would drop the order parameter entirely and make sure that in the documentation for the classes BJS2.5 toEulerAngles and  toEulerAnglesToRef it is clear that the intention is to return three Euler Angles that can be plugged into mesh.rotation.

@adam you may like to consider the above as I believe you PRd the changes for BJS2.5

 

More words for those who wish to read further.

In BJS mesh.rotation uses one particular interpretation which is - for three "Euler Angles" alpha, beta and gamma with alpha about axis x, beta about axis y and gamma about axis z then

mesh.rotation = new BABYLON.Vector3(alpha, beta, gamma)

applies these in the order about z, about x about y using world axes

This can be seen by applying

mesh.rotate(BABYLON.Axis.Z, gamma, BABYLON.Space.WORLD);
mesh.rotate(BABYLON.Axis.X, alpha, BABYLON.Space.WORLD);
mesh.rotate(BABYLON.Axis.Y, beta, BABYLON.Space.WORLD);

directly after the mesh has been created.

Since using rotate produces a rotationQuaternion for the mesh you then do

mesh.rotationQuaternion.toEulerAngles() which in BJS 2.5 returns alpha, beta, gamma (in order x, y, z) but didn't in BJS2.3 or BJS2.4

___________________________________________________________________________________________________________

Now take a different convention with alpha, beta, gamma as Yaw, Pitch, Roll about y (as vertical), x and z all applied around local axes.

Applying

mesh.rotate(BABYLON.Axis.Y, Yaw, BABYLON.Space.LOCAL);
mesh.rotate(BABYLON.Axis.X, Pitch, BABYLON.Space.LOCAL);
mesh.rotate(BABYLON.Axis.Z, Roll, BABYLON.Space.LOCAL);

directly after mesh creation then

mesh.rotationQuaternion.toEulerAngles() returns Pitch, Yaw, Roll which are the angles  in the order  x, y, z for slotting into mesh.rotation

mesh.rotate = new BABYLON.Vector3(Pitch, Yaw, Roll) 

produces the same rotation.

Note BJS2.3 and BJS2.4 do not produce useful values for the convention ZXY.

____________________________________________________________________________________________________________________________________

Finally take a third convention alpha, beta, gamma in the order around z, then x then z as world axes. Apparently this is a fairly standard convention when used with local axes but for reasons that should become apparent I will stick with world axes.

Applying

mesh.rotate(BABYLON.Axis.Z, alpha, BABYLON.Space.WORLD);
mesh.rotate(BABYLON.Axis.X, beta, BABYLON.Space.WORLD);
mesh.rotate(BABYLON.Axis.Z, gamma, BABYLON.Space.WORLD);

directly after mesh creation then

mesh.rotationQuaternion.toEulerAngles() returns alpha, beta, gamma in BJS2.3, nothing useful in BJS2.4 and

in BJS2.5 three angles theta, phi, psi in the order x, y, z which can be plugged straight into mesh.rotation to give the same orientation eg

mesh.rotation = new BABYLON.Vector3(theta, phi, psi);

Summary

So in BJS2.3 the function toEulerAngles  when given an orientation in quaternion form returns the Euler Angles that can be applied using the ZXZ convention to produce the same rotation.

In BJS2.5 the functionf toEulerAngles when given an orientation in quaternion form returns the Euler Angles in the order x, y, z that can be used as parameters for mesh.rotation

Link to comment
Share on other sites

21 minutes ago, JohnK said:

In BJS2.5 the function toEulerAngles is - given an orientation in quaternion form supply the Euler Angles in the order x, y, z that can be used as parameters for mesh.rotation

Isn't the order y, x, z ?

I can add the old YZX code back to the toEulerAngles function.  I don't think it should be the default though since the framework doesn't use that order by default.

Link to comment
Share on other sites

Somewhere along the lines we have crossed wires about the meaning of order x, y, z. I want @adam's PG to stay.

In the following PG angles are chosen at random, axes are chosen at random and whether they are world or local is chosen at random. The box is rotated according to these results. From the rotationQuaternion Euler Angles are obtained and used in the order x, y, z within box1.rotation and the orientation of the two boxes match. This is what I mean by the order x, y, z.

http://www.babylonjs-playground.com/#1ST43U#7

Link to comment
Share on other sites

Still trying to be clear what you mean by

1 hour ago, adam said:

BJS use the order y, x, z

because if you take mesh.rotation = new BABYLON.Vector3(x, y, z) then the rotations are done in the order z, x, y as seen in the match between box and box1 in this

http://www.babylonjs-playground.com/#1ST43U#2

Swapping the individual rotations to order y, x, z gives a mismatch

http://www.babylonjs-playground.com/#1ST43U#8

Mind you I have been playing around with this most of the afternoon ,so as well as the meshes my head is spinning and as you did all the work on sorting toEulerAngles and that works excellently then I think it is only a communication problem as you are happy and I am happy that in practice it all now works as expected.:D

 

Light Dawns (perhaps) if you do y, x, z in local axes then this matches with  mesh.rotation = new BABYLON.Vector3(x, y, z)

http://www.babylonjs-playground.com/#1ST43U#4

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...