首页 > 解决方案 > 在球体表面上绘制点

问题描述

我正在尝试制作由点组成的球体表面。我已经想出了如何用点制作一个圆形表面,但不知道如何使用它来构建一个球体。我用一个代码来做一个圆圈。这也是一个的例子。我使用 opengl 库来绘制。

def DrawCircle():
glBegin(GL_POINTS)
for i in range(0,300,10):
    angle = 2 * 3.14 * i / 300
    x = cos(angle)
    y = sin(angle)
    glVertex3d(x, y, 0)
glEnd()

标签: pythonopenglmath

解决方案


使用 2 个嵌套循环来计算 水平坐标系的方位角和高度角:

def DrawSphere():
    glBegin(GL_POINTS)
    glVertex3d(0, -1, 0)          # south pole
    for i in range(-90+10,90,10): # -90 to 90 south pole to north pole
        alt = math.radians(i)
        c_alt = math.cos(alt)
        s_alt = math.sin(alt)
        for j in range(0,360,10): # 360 degree (around the sphere)
            azi = math.radians(j)
            c_azi = math.cos(azi)
            s_azi = math.sin(azi)
            glVertex3d(c_azi*c_alt, s_alt, s_azi*c_alt)
    glVertex3d(0, 1, 0)           # north pole
    glEnd()

推荐阅读