Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.JS: Get position along direction vector

Tags:

three.js

I have a position vector:

var startPos = new THREE.Vector3(1.2, -2.34, 0.5);

A direction vector:

var direction = new THREE.Vector3(0.657873735, -0.2497291683, 0.71051916);

And a distance:

var distance = 1;

How to calculate a new position vector, starting from startPos that is moved the distance along the direction?

like image 766
Markus Siebeneicher Avatar asked Dec 15 '22 15:12

Markus Siebeneicher


1 Answers

var startPos = new THREE.Vector3(1.2, -2.34, 0.5);
var direction = new THREE.Vector3(0.6578737359955765, -0.24972916834682138, 0.710519166466616);
var distance = 1;

var newPos = new THREE.Vector3();
newPos.addVectors ( startPos, direction.multiplyScalar( distance ) );
like image 180
gaitat Avatar answered Feb 07 '23 10:02

gaitat