Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get direction between two 3d vectors using Three.js?

I have two points:

v1 = (0, 0, 0);
v2 = (10, 4, -3);

I want to get the direction between these two points so I can rayCast from point v1 to v2.

How do I do that?

like image 906
arpo Avatar asked Nov 08 '16 14:11

arpo


1 Answers

The pattern to follow to create a direction vector from v1 to v2 is this:

var dir = new THREE.Vector3(); // create once an reuse it

...

dir.subVectors( v2, v1 ).normalize();

Direction vectors in three.js are assumed to have unit-length. In other words, they must be normalized. If the direction vector you use when raycasting does not have length equal to 1, you will not get accurate results.

three.js r.82

like image 168
WestLangley Avatar answered Oct 01 '22 14:10

WestLangley