Markus Siebeneicher
Markus Siebeneicher

Reputation: 765

Three.JS: Get position along direction vector

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?

Upvotes: 4

Views: 4184

Answers (1)

gaitat
gaitat

Reputation: 12642

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 ) );

Upvotes: 12

Related Questions