One way to determine the angle between two vectors is by using this formula: v1•v2 = |v1||v2| cos(angle)
. To calculate the angle, you can use the acos
function on the dot product of the two vectors.
In ThreeJS, the dot product can be calculated as follows: dotproductV1V2 = V1.dot(V2)
You can then apply acos
to the result in order to determine the angle: Math.acos(dotproductV1V2)
Edit :
Here's an example that illustrates how to find the angle for each component of a vector:
var V1x = new THREE.Vector3(1, 0, 0)
var V1y = new THREE.Vector3(0, 1, 0)
var V1z = new THREE.Vector3(0, 0, 1)
var V2 = new THREE.Vector3(6, -10, 20)
var V2xz = new THREE.Vector3(V2.x, 0, V2.z)
var V2xy = new THREE.Vector3(V2.x, V2.y, 0)
//angle in radian between origin X axis and X axis of V2
var angle_V1V2x = Math.acos(V1x.dot(V2xz.normalize()))
//angle in radian between origin Y axis and Y axis of V2
var angle_V1V2y = Math.acos(V1y.dot(V2xy.normalize()))
//angle in radian between origin Z axis and Z axis of V2
var angle_V1V2z = Math.acos(V1z.dot(V2xz.normalize()))