arpo arpo - 1 year ago 111
Javascript Question

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?

Answer Source

A little bit of math : direction = v2 - v1

Plus, a little bit of ThreeJS of documentation :

Aannd ... Paf ! Solution !

 var direction = new THREE.Vector3();
 direction.subVectors( v2, v1 ) ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download