AngleAxis is to convert from axis-angle representation, itâs not necessarily the same thing.
think of it like this, you said 45 degrees around ârightâ⌠45 degrees off what though? Whatâs 0 degrees around ârightâ? Well axis-angle representation has a definition for what is the 0 position around an axis⌠but itâs nothing like euler angles.
but thatâs 45 deg. around âxâ in World space. Since âtransform.rotationâ in doc says that it rotates around World coords.
The rotation Iâm getting with my quaternion equation is around local and thatâs why I canât get it in world.
Anywhay I have tried the equation you submitted and it is still the same rotation I get with AngleAxis.
Is there maybe some other way to rotate with quaternions and get the initial rotation with Rotate ?
45 degrees OFF WHAT though? What do you think AngleAxis thinks 0 degrees around ârightâ looks like? AngleAxis is NOT Euler angles, and itâs NOT the same as 45 degrees pitch (which is 45 degrees around right-axis off the forward-axis). Sometimes they may appear similar, but not always, what do you think 45 degrees around <0.707, 0.707, 0> looks like (a valid axis-angle)? If you want to deal with Euler angles, deal with Euler angles.
As for your continuing problem, it may be because of order operations. Quaternion * appends one rotation to the next.
Itâd be like doing âSpace.Selfâ on the transform.Rotate method.
So combine them into one:
transform.rotation = Quaternion.Euler(45,90,0);
and if you donât have the initial rotation to append to world space wise like this⌠well get it as eulers
var e = transform.rotation.eulerAngles;
e.y += 90;
transform.rotation = Quaternion.Euler(e);
0 degrees around ârightâ is no rotation. In AngleAxis first parameter is angle that is in degrees and the second is the axis as sad in doc. But that angle is around axis you choose. It can be any rotation. So if you want it you can make AngleAxis to rotate same as Euler angle as Euler angles is only a rotation around base vectors, am I right ?
Like Euler(20, 0, 0) is the same as AngleAxis(20, Vector3.right) and that being around current frame of reference, usualy local coord system.
Last rotation that you submitted works. Thx very much.
It is the same rotation as the first one.
Now Iâm beginning to wonder what is Euler(45, 90, 0) function doing inside ? What is the quaternion math to arrive at that result ?
Ok, I see Iâm missing something out here. Becase I would say that 0 pitch, 0 yaw, 0 roll is no rotation.
This is how I would do it before:
quaternion = new Quaternion(Mathf.Sin(angle/2.0f)*v.x, Mathf.Sin(angle/2.0f)*v.y, Mathf.Sin(angle/2.0f)*v.z, Mathf.Cos(angle/2.0f));
Here âangleâ is the angle to rotate in radians, and âvâ is the axis to rotate about.
This equation si the same as AngleAxis exept that AngleAxis takes angles in degrees.
Well anywhay, to not go too deep, what my first intention was is to see how could I rotate with quaternion math (with using quaternion combinations or something else) an object around only world coords. Becase when you start to use combinations (*) you no longer rotate around world coords but instead around previous quaternion.
You sad that I can use Quaternion.Euler() which does rotate around world coords since there is no quaternion used in combination before. And I can use three rotations here.
So the last thing that I wanted to ask you how would you rotate using multiple rotations around world coord ? Using Quaternion.Euler() in combination wont work since the next rotation will depend on previous Quaternion.Euler() rotation and not on world coord.
0 pitch, 0 yaw, and 0 roll IS a rotation. Itâs the default rotational position.
No rotation would mean⌠No orientation. This is a very different case. Try doing this somewhere:
var v = new Vector3(0.7071f,0.7071f,0f);
var q = Quaternion.AngleAxis(0, v);
transform.rotation = q;
And youâll see NOTHING happens. (note the arbitrary axis)
This is important to know⌠when you attempt to create this quaternion, the default quaternion is set for you. But this is mathematically different. You canât define what 0 degrees around axis N looks like, because thereâs infinite possibilities. Where as we know EXACTLY what 0 roll, 0 pitch, and 0 yaw looks like⌠itâs looks like default rotation (thatâs not NO rotation, thatâs DEFAULT rotation⌠or the origin).
As for your question about local vs global rotation with quaternions.
With quaternions doing world rotations vs local rotations is just an order of multiplication.
//do on update message or something for animating representation
var q = Quaternion.AngleAxis(5, Vector3.right);
obj1.transform.rotation = obj1.transform.rotation * q; //rotate to obj1's local space
obj2.transform.rotation = q * obj2.transform.rotation; //rotate to obj2's global space
I was suggesting earlier using euler angles earlier because you seem to like to think about things in euler angles. Quaternions are NOT euler angles.
Rotation is merely an orientation in N dimensional space (in this case 3 dimensional space).
Orientation is not numeric, it can be described in numerics. Just like translation/position can be described in numerics and isnât the numbers themselves.
For instance translation can be described in various coordinate systems:
cartesian - these are the x,y,z you are used to
spherical coords - describing points on a series of sphere shells
cylindrical coords - describing points on a series of cylinder shells
WELL
orientation has various representations
Euler angles - the pitch, roll and yaw youâre used to. This is to orientation that cartesian is to translation
Axis Angle - an axis and the angle around the axis
I did try the example you suggested. I got no rotation. Than I tried with 0 yaw, 0 pitch, 0 roll and still no rotation. So I assume it is the same as 0 around axis that points in yaw direction (y coord), 0 around axis thats points in roll direction and 0 around axis that points in roll direction.
I have tried using âoppositeâ combination with quaternions (world coord) and I did get the same results as with the last one that I posted.
Now I have to figure out why the âoppositeâ combination results in rotation around world coords.
Yes, I know that quaternions are not in euler angles. I like more to work with quaternions becose I feel I have more freedom. Before when I did not know about Unity I used rotation with matrices but I never had to rotate an object like this around world coord.
So I assume this also works when multiplying matrices.