- Home /

# Quaternion rotations don't add up

My team has been trying for a day to get rotations to work on a vector. We read Quaternions can easily be multiplied with a vector to get the desired rotation. However, there seems to be something we don't quite understand. For example we'd expect the following code to rotate vector x to its original orientation, since each rotation axis adds up to a rotation of 360 degrees.

```
Vector3 x = new Vector(13,4,5); // Just an example
x = Quaternion.Euler(new Vector(180,300,350)) * x;
x = Quaternion.Euler(new Vector(180, 60, 10)) * x;
```

This however is not the case. After the rotation, x reads (-2.4,-0.3,-14.3). Can someone explain how Quaternions do work?

**Answer** by meat5000
·
Nov 20, 2013 at 07:01 PM

The rotations in Q-Euler are around the world axes I believe (in the order z, x, y). Work through with this on paper and you'll probably find it's correct. On paper treat Vector x as a point in space.

Place a cube at the point in space determined by your x vector. Apply the two rotations you created to the cube via script and you will see the same results.

Place the following onto a script and place it on a cube with position 13,4,5. It simply performs each rotation one axis at a time so you can see whats going on a bit better.

```
#pragma strict
var timer : float = 0.0;
var stage1 : boolean = true;
var stage2 : boolean = true;
var stage3 : boolean = true;
var stage4 : boolean = true;
var stage5 : boolean = true;
var stage6 : boolean = true;
function Update()
{
timer += Time.deltaTime;
if (timer >= 3.0 && stage1)
{
transform.position = Quaternion.Euler(0,0,350) * transform.position;
stage1 = false;
}
if (timer >= 6.0 && stage2)
{
transform.position = Quaternion.Euler(180,0,0) * transform.position;
stage2 = false;
}
if (timer >= 9.0 && stage3)
{
transform.position = Quaternion.Euler(0,300,0) * transform.position;
stage3 = false;
}
if (timer >= 12.0 && stage4)
{
transform.position = Quaternion.Euler(0,0,10) * transform.position;
stage4 = false;
}
if (timer >= 15.0 && stage5)
{
transform.position = Quaternion.Euler(180,0,0) * transform.position;
stage5 = false;
}
if (timer >= 18.0 && stage6)
{
transform.position = Quaternion.Euler(0,60,0) * transform.position;
stage6 = false;
}
}
```

Hello meat5000, thanks for your reply. If quaternions are meant to rotate around the world axes, some questions pop to my mind. Do you mind if I fire them at you? No matter what you turn in or around, shouldn't rotating 360 degrees in total always rotate back to the original state? What do you think I do not get here? And to solve my problem: I'm simply tring to rotate the direction of a vector, not a point in space. How would you suggest I do that if not like this? Thanks a lot for your time.

Quaternion.Euler rotates around the World axes. If you are trying to rotate the object itself apply your quaternion to transform.rotation instead :)

Manipulating Vectors is a little more complex and often requires the use of matrices. As you have seen, your first rotation performs three separate rotations and each one changes the position of the object in world space. They are simply not commutable like straight forward algebra. When you come to perform your second (three) rotation(s) the object is not in the place you expected to begin :)

A circle always requires 2 axes. Performing a circular motion on an object (rotating in a circle around an axis) will always change the position in two axis. And this is where you misconception applies. The only way to not affect 2 axes is to move in a straight line parallel to an axis, ofc.

In Unity a Vector and a point in space are basically one and the same. What makes your Point in space equal a Vector is that it's relative to 0,0,0, which is what gives it a direction. Of course, this is a generalisation.

I really should ask...what exactly is it that you are trying to do? :D

Currently I'm just trying to rotate a vector. For example (0,1,0) turned 90 degrees (clockwise) around the z-axis would give (1,0,0). Turning it 90 degrees back would again give (0,1,0) and turning that 360 degrees in any way would also give (0,1,0).

That is really all I want to get to work now, but if you're interested what I'm using it for: the reason I want to rotate a vector is that I'd like to store a point in space, relative to a specific mobile object. For this I calculate the distance between the object and the point (at a certain moment in time). I store this distance, which is basically a vector from the object to the point I have in mind. Because I have to take into account the rotation of the object at that moment in time, I want to "undo" that rotation on the vector I store. So I want the vector that would point from object to my point in space, if the object would have a rotation of 0,0,0. This way I can find my point in any frame, simply by applying the rotation of the object at that time to the vector stored and adding that rotated vector to the position of the object.

The steps of "undoing" and later reapplying a rotation is where I thought to use Quaternions. But it seems I still don't get what they actually do when multiplied to a vector. I would expect that turning 360 degrees around any axis would leave a vector untouched. I haven't found anything to suggest Quaternions do not work like this, but it seems they don't. So that leaves me with these questions:

Why don't quaternion rotations add up? (Meaning 360 degrees would make a full circle.)

What ARE quaternions meant for if not for rotating things in the way I expect and think is intuitive?

Can I still use quaternions for my purpose or is that not what they are for and do I need something else and what would that be?

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