在程序上生成一个球体网 [英] procedurally generate a sphere mesh

查看:163
本文介绍了在程序上生成一个球体网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种算法(伪code)产生一个球的三维坐标网格是这样的:

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)CO​​S(二皮* N / N),罪(PI * M / M)罪(二皮* N / N),COS(PI * M / M))

(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和n在{0,...,N-1},绘制点之间的线段,因此

for each m in { 0, ..., M } and n in { 0, ..., N-1 } and draw the line segments between the dots, accordingly.

编辑:也许调整米长,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆