Get Euler between two Vector3's

Hello,
I am looking for a way to get the Euler Angle necessary to get from one Vector3 to another.

You can rotate a Vector3 using

let vector_negZ = new THREE.Vector3(0,0,-1);
let rotation = new THREE.Euler(pitch,yaw,0,"ZYX")
let vector_rotated = vector_negZ.applyEuler(rotation);

In this instance the starting vector (vector_negZ) and the Euler angle are given.

Looking at the Euler and Vector3 documentation I could not find any function that takes a starting vector and the rotated vector and gives you the Euler between these two vectors. There is Euler.setFromVector3 but this function just sets the Euler x y and z based on the Vector3’s components.

TLDR: Is there something like this?

let rotation = new THREE.Euler().setFromTwoVectors(beginningVector,rotatedVector,eulerOrder);

You can’t compute this with vectors since they do not represent an orientation in 3D space. You can just calculate the angle between two vectors via Vector3.angleTo().

If you have two orientations expressed as quaternions (q1 and q2), then the rotation that will rotate from q1 to q2 is:

q = q1-1 * q2

So the inverse of q1 multiplied with q2. You can then create an euler object from the result via Euler.setFromQuaternion().

1 Like

ADLADS (A Day Late, A Dollar Short):

Maybe you want “the Euler Angles” instead of “the Euler Angle”.

You can get the quaternion that rotates V1 into V2:

  var qrot = new THREE.Quaternion();
  qrot.setFromUnitVectors(V1,V2); // (unit vectors)

Then you can get the Euler angles from qrot – goto:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm