fer*_*jsg 34
基本上你需要获得两点之间的方向向量(D),将其标准化,然后你将用它来获得新的点:NewPoint = PointA + D*Length.
您可以使用长度归一化(0..1)或作为从0到方向向量长度的绝对值.
在这里您可以看到使用两种方法的一些示例:
使用绝对值:
function getPointInBetweenByLen(pointA, pointB, length) {
var dir = pointB.clone().sub(pointA).normalize().multiplyScalar(length);
return pointA.clone().add(dir);
}
Run Code Online (Sandbox Code Playgroud)
并使用百分比(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);
}
Run Code Online (Sandbox Code Playgroud)
看到它在行动:http://jsfiddle.net/0mgqa7te/
希望能帮助到你.