I know there are several other questions and articles on the internet, but they wern't quite enough. My problem is, that right now, i'm calculating the points of a sphere by stacking circles with a ascending/descending radius, made with bresenham's circle drawing algorithm. This is my code, but it should'n be important.
def drawCircle(self, xyz, r): #Draws circle with radius "r" from midpoint "xyz". Note: Circle is parallel to x-axis
xc, yc, zc = xyz
coords = []
def drawC(xc, yc, zc, x, y):
coords.append((xc+x, yc+y, zc))
coords.append((xc-x, yc+y, zc))
coords.append((xc+x, yc-y, zc))
coords.append((xc-x, yc-y, zc))
coords.append((xc+y, yc+x, zc))
coords.append((xc-y, yc+x, zc))
coords.append((xc+y, yc-x, zc))
coords.append((xc-y, yc-x, zc))
x = 0
y = r
d = 3 - 2 * r
drawC(xc, yc, zc, x, y)
while y >= x:
x += 1
if (d > 0):
y -= 1
d = d + 4 * (x - y) + 10
else:
d = d + 4 * x + 6
drawC(xc, yc, zc, x, y)
for c in coords:
self.drawPixel(c)
return coords
def drawSphere(self,xyz,r): #Draws sphere. Not quite functional yet
x, y, z = xyz
for sr in range(-1,r):
self.drawCircle((x,y,z-r+sr),sr)
index = list(range(-1,r))
for sr in index:
self.drawCircle((x,y,z+sr),index[-sr])
When I render one of these spheres this happens:
If I increase the thickness to 2 layers
and to 3 layers:
There are holes. :( The thiccer the sphere has less holes, but is much slower to create. Is there a way to have hole-less sphere?