- Home /

# I am missing 1 quaternion dimension; ways to minimize information loss?

Hey everyone,

I built a VR app that lets me capture some gameplay metrics as well as head rotation.. or at least so I thought before I mindlessly logged transform.rotation.x, transform.rotation.y and transform.rotation.z, without considering logging transform.rotation.w as well.

Now I am interested in how much people rotated their head, but the only information I have available are head xyz coordinates and transform.rotation.x/y/z values.

Is there a way I can go about using those as a rough measure of how much head rotation was involved during gameplay?

**Answer** by Bunny83
·
Dec 28, 2019 at 03:00 PM

Well, you should be able to "kind of" recover the real part of the quaterion but not completely since some information might be missing. A quaternion is a 4 dimensional number. It consists of 3 imaginary units (x,y,z) and the real part (w). The imaginary / vector part defines the rotation axis while the real part essentially specifies the angle how much to rotate around that axis. Since only unit quaternions are used to describe rotations we can deduce the magnitude of the rotation but not the sign.

The general relation is essentially `sin(A/2)*(X,Y,Z), cos(A/2)`

where (X,Y,Z) is a unit vector describing the axis of rotation. So if you only have the x,y,z components of your quaternion you can get the magnitude of that vector and use Asin to get the angle of rotation. However you can not derive the rotation direction. Since for example +30° and -30° result in the same sin value you can not know which direction you actually rotated.

So to kind of reconstruct the rotation you can do:

```
Vector3 dir = new Vector3(X,Y,Z);
float halfAngle = Mathf.Asin(dir.magnitude);
Quaternion q = new Quaternion(X, Y, Z, Mathf.Cos(halfAngle));
```

As I said we don't know the sign of the w part so it could also be

```
Quaternion q2 = new Quaternion(X, Y, Z, -Mathf.Cos(halfAngle));
```

If you have a lot of data over time you might be able to deduce the sign considering the rotation usually doesn't change that quickly. Though this might be a bit tricky and is not watertight.

Might also be worth noting: Unit-Quaternions are "normalized" Vector4's.. meaning it's magnitude is always 1. so: 1=sqrt(xx+yy+zz+ww) Regarding not knowing the direction or the rotation: note that BOTH +w and -w work to make this magnitude equation true.

Yes, you're right. This is a direct result of the Pythagorean identity. Since sin²(a) + cos²(a) == 1 and the the unit axis vector also has a length of 1 the overall euclidean distance / length is still 1. Actually you can recover any of the 4 quaternion components if the other 3 are given and you know the sign of the missing component.

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

How to ROTATE an object without slowing the ends (lerp) 2 Answers

Make a side of an object LookAT another object 1 Answer

How to fix this strange child 3D rotation? 0 Answers

Random.rotationUniform clarification 4 Answers

How to rotate on one axis while keeping the other axes open to be rotated by other scripts? 1 Answer