找到2点之间的具体点 - three.js

9 vector distance points three.js

如何在thgree.js场景中的2个点(A(x,y,z),B(x,y,z))之间找到一个点(C(x,y,z))?

我知道这个:中点我可以找到它们之间的中间点,但我不想要中间点,我想找到它们之间的点,并且距离A点的距离是多少?

在这张图片中你可以看到我的意思:

在此输入图像描述

谢谢.

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/

希望能帮助到你.