程序生成一个球体网格 [英] procedurally generate a sphere mesh
问题描述
我正在寻找一种算法(在伪代码中),它可以像这样生成球体网格的 3d 坐标:
i am looking for an algorithm ( in pseudo code) that generates the 3d coordinates of a sphere mesh like this:
水平和横向切片的数量应该是可配置的
the number of horizontal and lateral slices should be configurable
推荐答案
如果有 M 条纬度线(水平)和 N 条经度线(垂直),则在
If there are M lines of latitude (horizontal) and N lines of longitude (vertical), then put dots at
(x, y, z) = (sin(Pi * m/M) cos(2Pi * n/N), sin(Pi * m/M) sin(2Pi * n/N), cos(Pi *米/米))
(x, y, z) = (sin(Pi * m/M) cos(2Pi * n/N), sin(Pi * m/M) sin(2Pi * n/N), cos(Pi * m/M))
对于 { 0, ..., M } 中的每个 m 和 { 0, ..., N-1 } 中的 n 并相应地在点之间绘制线段.
for each m in { 0, ..., M } and n in { 0, ..., N-1 } and draw the line segments between the dots, accordingly.
可能根据需要将 M 调整 1 或 2,因为您应该决定是否计算极点处的纬度线"
edit: maybe adjust M by 1 or 2 as required, because you should decide whether or not to count "latitude lines" at the poles
这篇关于程序生成一个球体网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!