Given two vectors:
V1 = { x: 3.296372727813439, y: -14.497928014719344, z: 12.004105246875968 }
V2 = { x: 2.3652551657790695, y: -16.732085083053185, z: 8.945905454164146 }
How can I determine the angle at which V1 needs to be rotated in order to face directly towards V2?
To simplify, imagine knowing your exact position in space and that of another individual elsewhere... How could you calculate the angles necessary to point directly at them using mathematics?
Visual representation of my axis here
The formula I am currently using (which is incorrect)
v2.x -= v1.x;
v2.y -= v1.y;
v2.z -= v1.z;
v1.x = 0;
v1.y = 0;
v1.z = 0;
var r = Math.sqrt(Math.pow(v2.x,2) + Math.pow(v2.y,2) + Math.pow(v2.z,2));
var θ = Math.acos((Math.pow(v2.x,2) + Math.pow(v2.z,2))/(r*Math.sqrt(Math.pow(v2.x,2) + Math.pow(v2.z,2))));
var ϕ = Math.acos(v2.x/Math.sqrt(Math.pow(v2.x,2) + Math.pow(v2.z,2)));
My current process involves rotating V1 based on the calculated theta and phi angles.
v1.rotation.y = θ;
v2.rotation.x = ϕ;
However, this method results in inaccurate rotations.
θ = 0.6099683401012933
ϕ = 1.8663452274936656
Conversely, when utilizing THREE.js and the lookAt function, the following correct rotations are produced:
y/θ: -0.24106818240525682
x/ϕ: 2.5106584861123644
I appreciate all assistance provided! While THREE.js works well, I aim to achieve this functionality using pure vanilla JS for portability across different languages.