Find specific point between 2 points - three.js

Basically you need to get the direction vector between the two points (D), normalize it, and you'll use it for getting the new point in the way: NewPoint = PointA + D*Length.

You could use length normalized (0..1) or as an absolute value from 0 to length of the direction vector.

Here you can see some examples using both methods:

Using absolute value:

function getPointInBetweenByLen(pointA, pointB, length) {

    var dir = pointB.clone().sub(pointA).normalize().multiplyScalar(length);
    return pointA.clone().add(dir);

}

And to use with percentage (0..1)

function getPointInBetweenByPerc(pointA, pointB, percentage) {

    var dir = pointB.clone().sub(pointA);
    var len = dir.length();
    dir = dir.normalize().multiplyScalar(len*percentage);
    return pointA.clone().add(dir);

}

See it in action: http://jsfiddle.net/0mgqa7te/

Hope it helps.


I know the question is for THREE.JS and I end up looking for something similar in Babylon JS.

Just in case if you are using Babylon JS Vector3 then the formula would translate to:

function getPointInBetweenByPerc(pointA, pointB, percentage) {

    var dir = pointB.clone().subtract(pointA);
    var length = dir.length();
    dir = dir.normalize().scale(length *percentage);
    return pointA.clone().add(dir);

  }

Hope it help somebody.