c# - 沿 3d 向量查找点

标签 c# vector unity-game-engine 3d

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

最佳答案

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()中使用它

关于c# - 沿 3d 向量查找点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36056760/

相关文章:

unity-game-engine - RayCast2D 忽略撞击自己的碰撞体

c# - 在 C# 中循环 SimpleJSON 数组

c# - 如何在 VS 2015 中获取选定的错误描述

c# - 为什么 BluetoothLEDevice.GattServices 为空

c# - 如何简化 Silverlight 4 中的 WCF 调用

c# - 转换 bool[] -> "false, true, true, false"的简洁代码

arrays - Matlab 将向量转换为二进制矩阵

c++ - 自定义对象的 vector

c++ - 如何模拟任意大小的 vector ?

android - 统一错误 : Exporting to Android