Hi, three.js developers!

I made two cubes and rotated them using TransformControls to make them look the same. But their rotation is different.

Why does it happen? How do I compare two rotation values?

Thank you in advance.

The most obvious reason is the symmetry – i.e. if you rotate a cube 90° around any of its local axes, … the result will look the same.

If this is not the case, comparing rotations is tricky, as they are not a single number, but a set of numbers. More over, rotations have different representations:

- as
**Euler angles**– in this case you must compare 3 numbers, but only after ensuring the order is the same. Also, angles may contain revolution info, that you must strip out before comparison. - as
**Quaternions**– in this case the rotation is represented as 4 numbers. But here there are also some strange cases, like*q*and*-q*are the same rotation. - as
**Matrices**– you must check the 9 values in the top-left 3x3 submatrix (scaled by the value in the bottom-right corner).

In all three cases you might assume that if the numbers are close enough, the rotations are close too.

Beware, that such comparing might give non intuitive results, because the opposite is not necessarily true.

If I had to compare two rotations, I would start with three perpendicular vectors (e.g. the unit vectors of a coordinate system). Then I will transform them by both rotations. And only after then I will compare the resulting pairs of vectors whether they are close. Two vectors are close if the angle between them is small enough. That angle is proportional to the sine (because sin(x)≈x for small x) and that sine is given by the vector product of the vectors.

I hope you do not find all this as confusing as I think it is.

If there is a simpler and robust way, I hope someone will share it.

Here they can try it out.

It occurs to me now that this can be roughly illustrated by this article and the examples.

Quaternion - method .setFromBasis( e1, e2, e3 )

https://hofk.de/main/discourse.threejs/2021/CarRacing/FlightRouteQuaternion.html

Thank you very much for your correct answer, hofk.