TBN frame to quaternion

I am trying to convert 3 basis vectors to a rotation. My expectation is that:

const rotationMatrix = new THREE.Matrix4().set(
  0.3511234415884646,  0.9363291775690172,  0,  0,
  0.9363291775690172,  -0.3511234415884646,  0,  0,
  0,  0,  1,  0,
  0,  0,  0,  1

const quaternion = new THREE.Quaternion().setFromRotationMatrix(rotationMatrix);


Should yield me something other than the 90 degree rotation. I have different matrices with different values but setFromRotationMatrix() seems to always return the same quaternion.

Those basis vectors in your example there look very close to an identity… i.e.
which looks very much like a 90 degree rotation of Y onto X, so 90 degrees around Z

So I suspect your data. Perhaps also a row/column swap? but yeah…

In your case, try conversion matrix → euler → quaternion:

const euler = new THREE.Euler().setFromRotationMatrix(rotationMatrix);
const quaternion = new THREE.Quaternion().setFromEuler(euler);

However, to be honest, the matrix does not contain pure rotation (or has XY swapped). The matrix looks like rotation around Z axis, but in this case it should be something like:

cos -sin  0  0
sin  cos  0  0
 0    0   1  0
 0    0   0  1

so, the diagonal two values must be the same, like this:

0.3511234415884646,  0.9363291775690172,  0,  0,
-0.9363291775690172,  0.3511234415884646,  0,  0,
0,  0,  1,  0,
0,  0,  0,  1

and the resulting quaternion will be

0, 0, -0.5695948377625694, 0.8219256175556473

Yeah i think i swapped some axis. After i swizzlwd i started getting a rotation. I don’t quite understand what’s going on.

This may be very basic, but my expectation was that any three orthogonal vector will give me a rotation. It may not be the rotation that I expect but it will be a rotation. However, that’s not true right? I could set them up in such a way that it has a rotation and a scale in say negative x, in which case setFromRotationMatrix fails because, well, it’s not a rotation matrix?

How would you rotate a left-handed coordinate system into a right-handed coordinate system?

1 Like

Right :slight_smile: I will not, that;s why i got the different diagonal, I flipped it.

1 Like