How to determine the increase in the Z-Axis. Of a tessellated sphere

130 Views Asked by At

I have been tasked with drawing the sphere below for a programming assignment using openGL.

I have the assignment mostly completed however I am having issues figuring out the math for the sphere. For example when I drew the cone (second image) it was simple. Our canvas is between the values -0.5 and 0.5. So to calculate the z increase at each level I simply did

((0.5 - -0.5) / number_of_cone_stacks) = Z axis change per stack in the cone

My last attempt (third image) which calculated the z value as:

((0.5)/number_of_sphere_stacks) = z axis change per stack in the cone

finally got me thinking that I need to increase the z by a variable amount at each stack. I just cannot think of the math to do this. Can anyone point me in the right direction about what I may be missing?

Assignment Goal (What I am trying to draw): Sphere

My Cone (I drew this) Cone

My attempt at a sphere using ( 0.5 / number_of_sphere_stacks)

Fail sphere

EDIT: So after implemeing @antolys suggestions My sphere is looking more spherical! the remaining issues are simple programming errors. Thanks!

enter image description here

2

There are 2 best solutions below

3
On BEST ANSWER

Hint: for each stack, interpret changes in the $z$ value as changes in the cosine of the angle identified by the $z$-axis and a line connecting the center of the sphere with the stack edge. Using a constant variation in the angle, calculated as $\pi$ divided by the total number of stacks, you can easily get the $z$ changes.

1
On

You don't have to change the $z$ increment per layer-your sphere looks fine. You need to define what the objective is. For example, you might want the area of the triangles to be (approximately) constant as you approach the pole-currently they get much smaller, but they do on the cone as well. Maybe you want some side of the triangle to have constant length, which you do with the cone.

With the addition, it appears the problem is not in the $z$ spacing, it is that your points are not on the sphere. If you choose $z$ first, then you need $\sqrt{x^2+y^2}=\sqrt {1-z^2}$ so you can do $r=\sqrt{1-z^2}, x=r \cos \phi, y = r\sin \phi$ with the increment in $\phi$ so you get the right number of points around the circle.