在sph曲面上绘制点

2024-04-25 19:46:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个由点组成的球面。我已经知道如何用点做一个圆的表面,但不知道如何用它来建造一个球体。我用一个代码来画一个圆。这里还有一个circle的例子。我用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()

Tags: 代码def表面points例子opengl球面球体
1条回答
网友
1楼 · 发布于 2024-04-25 19:46:00

使用2个嵌套循环计算 Horizontal coordinate system的方位角和高度角

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()

相关问题 更多 >