Basically you need to get the direction vector between two points (D), normalize it, and you will use it to get a new point in the path: NewPoint = PointA + D*Length .
You can use the normalized length (0..1) or as an absolute value from 0 to the 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 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 in action: http://jsfiddle.net/0mgqa7te/
Hope this helps.
fernandojsg
source share