How the Quaternion Works?

Somebody can explain me what its a Quaternion, and how can i use it to rotate my 3d objects? I really frustated about it, and a i need it for a project i actually doing to the college. Thanks…

A Quaternion represents a rotation. The underlying math is quite complicated but you don’t need to understand that to use them with Unity.

Here are the docs for the Quaternion class:

The documentation for Ogre explains some of the advantages of Quaternions:

  • Axis/angle representation avoids gimbal lock.

  • Modifying a rotation is easy. Say we have a rotation describing a -45 degree yaw (left turn). By creating a new quaternion describing a 10 degree yaw (right turn) and multiplying the two, we now have a rotation describing a -35 degree turn. You might use this when applying the same rotation to a number of different objects, or even multiple times to the same object (i.e. the player). The rotation factor increases or decreases depending on circumstances.

  • Avoids costly alignment of matrix drift. This drift occurs when performing lots of operations on matrices using finite point precision, which is used in your computer. Rounding of real numbers graudally builds up and inevitably mucks up the matrix. Abnormalities in the rotation will start to appear due to this drift. The matrix must be normalized in order to reset this, however it is a costly operation. Quaternions on the other hand can still suffer from this drift, but it is much cheaper to normalize having only 4 values instead of 9 or more.

  • Interpolation of rotations. When rotating an object, we might want the object to rotate smoothly over time. We’d like to say, “From your current orientation, rotate to face this point. But take about 300 frames to do it, so only move 1/300th of the rotation right now.” Interpolation with matrices is possible, but then so is anything, isn’t it? Quaternions provide two methods of interpolation: linear(slerp) and cubic(squad). Ogre provides three implementations: slerp, nlerp and squad. Linear interpolation allows one to specify the percentage of interpolation between the two quaternions. Linear means your “velocity” of movement is constant, which may feel jerky if used for a camera or object. Slerp and nlerp are both linear. Slerp is more accurate, but slower. Squad or cubic interpolation allows one to specify four quaternions a,p,q,b. P and Q are used to define a curve of interpolation “velocity” between points A and B. This allows us to slowly increase speed, stay constant, then decrease it during interpolation. See the External Resources section for links that will elaborate on this.

Taken from:

Here is a youtube video of a guy that explains it pretty well :slight_smile:

EDIT : Here’s a more thorough one from site I was told of today…

A quaternion is a vector with a rotation angle attached…

So think about a Quaternion to be a Vector3 that points anywhere in the XYZ Dimension. Its direction actually is a rotation itself (Imagine every point on the unit circle can be displayed as a simple Vector2, so the same goes for 3D). Additionaly the Vector has another Angle parameter that lets it rotate around its personal Z axis (or roll it like a cigarette^^).

Actually I don’t know yet how to directly manipulate the parameters, but don’t be afraid to play around with it, Quaternions actually aren’t some ungraspable mathematical divinity you mustn’t touch as long as you don’t have a PhD.

There are many people out there that tell you shit to block you on your way, like in primary school when everybody told you math is soo hard and you believed it and made school math an unbeatable giant.

MYTH busted, so go out there and program the shit out of your game :wink:
(Grow, Grow my little Sprouts for only personal growth is infinite^^)