0

I'm looking for a way to change the matrix4 that I have rotated and get the rotation value back. here is my code snippet.

const degree = 240;
const matrix = new THREE.Matrix4();
const rotated = matrix.makeRotationZ(degree * (Math.PI / 180));

let vec = new THREE.Quaternion();
vec.setFromRotationMatrix(rotated);
const test2 = vec._w;
const test3 = 2 * Math.acos(test2);

const radToDegree = (test3 * 180) / Math.PI;
console.log(radToDegree);

Everything works fine. But the strange value when I convert at an angle of more than 240 degree.

2pha
  • 9,798
  • 2
  • 29
  • 43
surya kumara
  • 185
  • 1
  • 11
  • Is it an option? https://threejs.org/docs/index.html?q=euler#api/en/math/Euler.setFromQuaternion – prisoner849 Oct 22 '21 at 11:25
  • Inverse Cos function will work as expected for angles from 0 to Pi. If you want to recover all angles you need to use inverse tangent. From quaternion you can recover cos from the w coordinate ans sin from the vector part. Then you can use atan2 to recover the angle. – Mauricio Cele Lopez Belon Oct 23 '21 at 11:02
  • 1
    Does this answer your question? [Get euler rotation from Quaternion?](https://stackoverflow.com/questions/12784807/get-euler-rotation-from-quaternion) and [How do you get the axis and angle representation of a quaternion in three.js?](https://stackoverflow.com/questions/62457529/how-do-you-get-the-axis-and-angle-representation-of-a-quaternion-in-three-js) – Bergi Oct 30 '21 at 02:36

0 Answers0