This site uses strictly necessary cookies. More Information

X- Home /

# Quaternions rotating the wrong way

Hello,

I'm making a physics simulation that uses quaternions to calculate the rotation of the objects involved. I've written the following method for constructing a quaternion:

```
static Quaternion quatCons(Vector3 axis, float angle) {
axis = axis.normalized;
float s = Mathf.Sin(angle / 2f);
Quaternion result = new Quaternion(s * axis.x, s * axis.y, s * axis.z, Mathf.Cos(angle / 2f));
return result;
}
```

Where `axis`

is the axis around which the rotation takes place, and `angle`

the angle/second at which the rotation happens (in radians).

When trying to simulate the rotation of earth, I use the following code:

```
static Vector3 earthAx = new Vector3(0, 1, 0);
static Quaternion earthRot = quatCons(earthAx, Mathf.PI/43200f*Time.deltaTime);
earthTrans.transform.rotation = earthRot * earthTrans.transform.rotation;
```

According to the rules of quaternion multiplication, this should result in the sphere rotating eastward right? Clockwise rotation when looking in the same direction the axis vector is pointing. The sphere rotates westward though (or anticlockwise), and I have no idea why. Does it have something to do with the way unity multiplies by quaternions? It doesn't really make sense to me.

**Answer** by Bunny83
·
Jan 04, 2018 at 12:34 AM

Uhm, the usual rotation direction is counter clockwise. What makes you think the rotation should be clockwise? Keep in mind that Unity uses a left handed system, not a right handed system.

"The rotation is clockwise if our line of sight points in the same direction as u→" From https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation But if unity rotates counter clockwise I guess I'll just have to keep that in mind, thanks!

The mathematical definition of most concepts uses a right handed system. In a left-handed system most concepts are inverted when compared to a right handed system. This even applies to the vector crossproduct. While you usually use the right-hand-rule, in a left handed system you have to use the left hand rule. C = Cross(A, B) --> A == thumb, B == index finger, C == middle finger.

ps: Unity already has a method to convert and angle and axis into a quaternion: Quaternion.AngleAxis. So there's no need to manually setup the quaternion. Note that AngleAxis takes an angle in degree, not in radians.

**Answer** by OneCept-Games
·
Jan 03, 2018 at 09:09 PM

Rotating an object by the Quaternion directly is complex math. Why not use the Eular method of the Quaternion class and use Vector3 objects instead?

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