繁体   English   中英

在 3d 中沿向量查找点

[英]finding points along a vector in 3d

我在 3d 空间中有两个点,我想获得它们之间的点列表,这些点彼此之间的距离为“r”。 如何使用统一功能最轻松地做到这一点? 在此处输入图片说明

Vector3[] GetPointsInbetween(Vector3 a, Vector3 b, float offset){
    int count = (int)((b - a).magnitude / offset);
    Vector3[] result = new Vector3[count];

    Vector3 delta = (b - a).normalized * offset;

    for (int i = 0; i < count; i++) {
        result[i] = a + delta * i;
        Debug.Log(result[i]);
    }

    return result;
}

但是.magnitude.normalized是非常昂贵的操作,尽量避免在Update()使用它

您可以通过使用Vector3.MoveTowards http://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html来完成它

我不熟悉 Unity 函数,但正式地描述了两点之间的线性插值。 AB之间的线段可以用参数化形式来描述

A * s + B * (1-s)

其中s来自区间[0,1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM