 # What exactly is a rotationQuaternion, in layman's terms?

I had a simple glTF model that I was importing into my scene and was having trouble with getting it to render properly (it was being rendered with an inverted Y axis), and stumbled across a fix by setting the `mesh.rotationQuaternion = null`. So it seems like that `rotationQuaternion` was included as part of the file.

I don’t quite understand what exactly it is and how it differs to `rotation`, would someone be able to explain in layman’s terms? I’ve looked through some docs and there’s mentions of clearing this if we want to set our own rotation on a mesh, but haven’t been able to find a clear definition.

2 Likes

So when you think about a 3D position, it’s easy to picture a vector3 representing that position in space, right? That same way of thinking translates well to the familiar `rotation` Property, but while useful when picturing rotation mentally, this way of representing rotation suffers from a few problems, mainly that adding rotations is less than straightforward, and another problem known as gimbal lock.

A `rotationQuaternion` Is a different way of representing a rotation that doesn’t have those problems. Instead of a single vector3 representing a radial value for each axis, you have a vector3 and a scalar number parameter. The vector represents the axis of rotation, while the scalar represents the angle of rotation.

Without getting into the maths involved too much, (You said you wanted layman’s explanation!) this structure can be quickly, efficiently, and easily added together with any other needed transformations to compute e.g., a bone’s orientation in relation to its parent and to world space by plopping it into a Matrix.

Here’s a technical definition from my fave resource Essemtial Mathematics for Games and Interactive Applications:

In a unit quaternion, w can be thought of as representing the angle of rotation θ. More specifically, w = cos (θ/2). The vector v represents the axis of rotation, but normalized and scaled by sin (θ/2). So, v = sin (θ/2)rˆ.

HTH!

4 Likes

Hi @Joseph15, and welcome to the forum ! Feel free to ask if you have any question, there will be people with answers and explanations !

@jelster said it all, I just wanted to give my 2 cents about the quaternion question, because I’ve long had trouble figuring out why there were two ways of describing an angle. I didn’t know about the gimbal lock (thanks for that !) but understanding the issue of adding rotations helped me out, so I though I’d try to explain how I see it :

• Rotation as Vector3 is called Euler angles. It is useful because it is easily broken down to 3 individual dimensions. So you can easily set `rotation.x = radiansValue`.
The important and not so obvious drawback is that the order in which rotations are applied matters. You can easily experiment that at home with say a pen : hold it vertically, then apply first a rotation on the Y axis, then a rotation on the X axis. The final state will be different than if you applied the X rotation first and then the Y rotation. That is the main issue with Euler angles, and it’s specific to rotations (translates and scales do not care for the order of theirs transforms) Therefore in various languages, you might find rotation options like “xyz”, “yzx”, “zyx” and such, that is the order of the rotations.
• Rotation as a Quaternion can’t be interpreted in different ways. There is only one orientation in space that fits a quaternion’s value. Also the information being composed of an axis and a angle makes some situation way more comfortable. A good example of this is animation bones. As you can see, having the axis and angle of the quaternion is really easy, since each bone can inherit the value from it’s parent by default.

Have a nice week-end !

2 Likes

Let me just add the caveat that the four values of a quaternion do not literally describe the rotation axis and angle. But axis-angle is a good analogy. I think BJS has a helper function to compute a quaternion from axis-angle. Yes: Quaternion | Babylon.js Documentation

3 Likes