algorithm - 在球体上均匀生成点

标签 algorithm

我对生成围绕球体“均匀”(且非随机)分布的点很感兴趣,就像高尔夫球的酒窝或足球的六边形顶点一样。是否有明确定义的算法来执行此操作?

注意:我知道这些点并不是真正“均匀”分布在一个球体上,但它们的分布方式是从任何方向直视任何一个点,这些点的分布看起来都是一样的——这是我感兴趣的。

最佳答案

分割八面体并在之后对顶点进行归一化会产生非常好的结果。 Look here更多细节。 Paul Bourke 有很多有趣的东西。

这是我在五分钟内编写的一些伪 C++ 代码:

/* Assume 'data' initially holds vertices for eight triangles (an octahedron) */
void GenerateSphere(float radius, std::vector<Vector3f>& data, int accum=10)
{
    assert( !(data.size() % 3) );

    std::vector<Vector3f> newData;

    for(int i=0; i<data.size(); i+=3){
        /* Tesselate each triangle into three new ones */
        Vector3f centerPoint = (data[i] + data[i+1] + data[i+2]) / 3.0f;

        /* triangle 1*/
        newData.push_back(data[i+0]);
        newData.push_back(data[i+1]);
        newData.push_back(centerPoint);
        /* triangle 2*/
        newData.push_back(data[i+1]);
        newData.push_back(data[i+2]);
        newData.push_back(centerPoint);
        /* triangle 3*/
        newData.push_back(centerPoint);
        newData.push_back(data[i+2]);
        newData.push_back(data[i+0]);
    }
    data = newData;
    if(!accum){
        /* We're done. Normalize the vertices,
             multiply by the radius and return. */
        for(int i=0; i<data.size(); ++i){
            data[i].normalize();
            data[i] *= radius;
        }
    } else {
        /* Decrease recursion counter and iterate again */
        GenerateSphere(radius, data, accum-1);
    }
    return;
}

此代码适用于任何由逆时针三角形组成的多面体,但八面体是最好的。

关于algorithm - 在球体上均匀生成点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4349727/

相关文章:

c++ - 编织链表元素的转轮技术

c++ - 如何正确构造和继承类?

python - 计算要获取的最佳项目数的算法

学习发展算法

java - 数组内的除数

python - 多交易所、多币种、多金额的套利算法

algorithm - 对图书馆中几乎已排序的书籍进行排序的最佳算法是什么

javascript - 如何为 Web 上的自定义 DSL 设计丰富的编辑器

algorithm - 我的数组等边算法出现意外结果

algorithm - 给定一个平面上的 n 个点,我如何找到一个等间距的共线三元组(如果存在)?