【问题标题】:Drawing points on a surface of a sphere在球体表面上绘制点
【发布时间】:2020-11-02 01:21:14
【问题描述】:

我正在尝试制作由点组成的球体表面。我已经想出了如何用点制作一个圆形表面,但不知道如何使用它来构建一个球体。我用一个代码来做一个圆圈。这也是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()

【问题讨论】:

  • 你能解释一下a1、a2代表什么以及如何计算它们吗?
  • 它们是球面极角。 a1[-pi/2, pi/2]a2 范围内[0, 2pi)

标签: python opengl math


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多