Orient's rotations via quaternions

   2735   2   0
User Avatar
Member
16 posts
Joined: March 2017
Offline
Friends, please help me solve the problem with quaternions. The task is quite simple - to rotate the orient by two angles around X-axis and Y-axis.
For this I applied the following code

vector N, up;
 N = {0,0,1};
 up = {0,1,0};
 @orient = quaternion(maketransform(N,up));
 vector4 xrot = quaternion(radians(ch('anglex')*360),{1,0,0});
 vector4 yrot = quaternion(radians(ch('angley')*360),{0,1,0});
 @orient = qmultiply(@orient, xrot);
 @orient = qmultiply(@orient, yrot);

This code seems to work, but with some oddities. For example, if you first set some value of the Y angle in the "angley" channel (for example, 0.1), and then change the X angle values in the "angelx" channel, then all the orient's axes will rotate around the global X axis.
However, if you do the opposite and first set the angle X value on the "anglex" channel, and then change the value of the Y angle, then the Z and Y axes of the orient will rotate around the "local" Y axis of the orient, which in turn will remain stationary. (see screenshots)
Why, in this case, all the orientat's axes do not rotate around the global Y-axis?
Is this some kind of mathematical feature of quaternion multiplication? Or a bug in my code? Or a glitch?
Thanks in advance!

Attachments:
pic1.png (946.1 KB)
pic2.png (952.9 KB)
pic3.png (949.4 KB)
pic4.png (946.9 KB)
pic5.png (954.8 KB)
pic6.png (954.3 KB)
quaternion.hip (115.6 KB)

User Avatar
Member
9376 posts
Joined: July 2007
Offline
nothing odd going on
the rotations are applied sequentially
in your case both of your rotations are applied in local space of the p@orient at the point of when it's applied
so
 @orient = qmultiply(@orient, xrot); // will rotate around local x axis of @orient, which will look like around global x if your initial @orient is aligned with object space
 @orient = qmultiply(@orient, yrot); // will afterwards rotate in local Y space of the previously computed @orient, which in case of any value in Anglex will not be aligned with global Y

you can also apply your rotations in object space by flipping the arguments:
 @orient = qmultiply(xrot, @orient); // will rotate @orient around global x axis
 @orient = qmultiply(yrot, @orient); // will afterwards rotate previously computed @orient in global Y space, in which case the effect will seem to have opposite order in case the original @orient was aligned with object space and if you rotate first around Y and then X it will look like X rotates around local X since at the point where X is applied globally, the @orient axes are still aligned

you can also replace use eulertoquaternion() to define your X, Y, Z rotations and their order, but the principle will always be of sequentially applying those individual rotations in a specific order whether in local or global space
Edited by tamte - Dec. 11, 2022 14:50:37
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
16 posts
Joined: March 2017
Offline
Many thanks for such detailed reply, Thomas! Now it is clear ))
  • Quick Links