Find a specific point between 2 points - three.js

How to find the point (C (x, y, z)) between 2 points (A (x, y, z), B (x, y, z)) in the thgree.js script?

I know what this is about: the midpoint I can find the midpoint between them, but I do not need the midpoint, I want to find the point that is between them, as well as the distance a from point A?

In this figure you can see what I mean:

enter image description here

Thanks.

+7
vector distance points
source share
1 answer

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.

+23
source share

All Articles