John Fekoter
John Fekoter

Reputation: 35

Drawing points on a surface of a sphere

I'm trying to make a surface of a sphere that consists of points. I've figured out how to make a circle surface out of points but dont know how to use that to build a sphere. There is a code that I use to make a circle. And here's also example of a circle. I use opengl library to draw.

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

Upvotes: 0

Views: 700

Answers (1)

Rabbid76
Rabbid76

Reputation: 210978

Use 2 nested loops to calculate the azimuth and an altitude angle of a 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()

Upvotes: 1

Related Questions