- Home /

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

I've been using them for years, I have a superior knowledge of Linear Algebra / Vector mathematics, and I don't have the slightest clue as to how quaternions are able to do what they do.

Yeah, Quaternions are a black box for most people (me included).

You create them from functions using rotations and other vars, then you apply that to other rotations, but you don't need to know what's in the box, just that this box will change your rotation 60 degrees to the left, and that box will rotate you to the right, etc...

**Answer** by _Petroz
·
Jun 23, 2011 at 05:01 AM

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: http://unity3d.com/support/documentation/ScriptReference/Quaternion.html

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: http://www.ogre3d.org/tikiwiki/Quaternion+and+Rotation+Primer&structure=Tutorials

**Answer** by Meltdown
·
Jun 23, 2011 at 05:41 PM

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

http://www.youtube.com/watch?v=WkBno2c06ZU

EDIT : Here's a more thorough one from site I was told of today...

That is a great explanation. I still don't fully get them but definitely understand them better. Good shout Greg!

**Answer** by deCalle
·
Mar 25, 2016 at 05:55 PM

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 ;-) (Grow, Grow my little Sprouts for only personal growth is infinite^^)

Quaternions really aren't that difficult ^^. See this Numberphile video

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Manual Quaternions 3 Answers

Child versus Parent rotations 3 Answers

3D nested Turret Prefab Rotation 1 Answer

Instantiate based on RaycastHit.normal 1 Answer

Figuring out the correct amount of torque to apply? 2 Answers