简体   繁体   English

在 3d 中沿向量查找点

[英]finding points along a vector in 3d

I have two points in 3d space, and i want to get a list of points between them which are located with "r" distance from each other.我在 3d 空间中有两个点,我想获得它们之间的点列表,这些点彼此之间的距离为“r”。 How can I do it most easily using the unity functions?如何使用统一功能最轻松地做到这一点? 在此处输入图片说明

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;
}

but .magnitude and .normalized are very expensive operations, try to avoid using this in Update()但是.magnitude.normalized是非常昂贵的操作,尽量避免在Update()使用它

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

I'm not familiar with the Unitiy functions, but formally you describe linear interpolation between the two points.我不熟悉 Unity 函数,但正式地描述了两点之间的线性插值。 The line segment between the points A and B can be described by the parameterized formAB之间的线段可以用参数化形式来描述

A * s + B * (1-s)

where s is from the interval [0,1] .其中s来自区间[0,1]

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

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