球体表面均匀分布

在球体的表面上最优分配N个点算法

function uniform_spherical_distribution( N )
    local points = {}
    local inc = math.pi * (3.0 - math.sqrt(5.0))
    local off = 2.0 / N
    for i = 0, N-1 do
        local y = i * off - 1 + (off / 2.0)
        local r = math.sqrt(1 - y * y)
        local phi = i * inc
        local pos = {}
        pos.x = math.cos(phi) * r
        pos.y = y
        pos.z = math.sin(phi) * r
        table.insert(points, pos)
    end
    return points
end

 

posted @ 2021-12-24 10:59  Ring_1992  阅读(223)  评论(0编辑  收藏  举报