I'm trying to write a program for building half spheres (eventually spheres) with different dimensions, using the equation x^2 + y^2 + z^2 = r^2 (the center of the sphere is always consider (0,0,0)).
So this is what i got so far: http://pastebin.com/ppH53JN9
It's kinda a mess i know, but i'm not an expert at coding. And i'm not very good at math too, so…
Basically the turtle goes forward and backward, passing every combination of x,y and z coordinates and when the equation is true it places a block. Everything works, kinda.
My first attempt was with the function sphere():
function sphere()
realz = z + 1
equation1 = x^2 + y^2 + z^2
equation2 = radius^2
if equation1 == equation2 then
return true
else
return false
end
end
and this was the result: http://imgur.com/hydQfDb
The shape is there, but too much empty space :( i figured the problem was that i was working only with integers so i add decimals left and right and i wrote the function sphere2()
function sphere2()
minx = math.abs(x) - 0.5
maxx = math.abs(x) + 0.5
miny = math.abs(y) - 0.5
maxy = math.abs(y) + 0.5
minz = math.abs(z) - 0.5
maxz = math.abs(z) + 0.5
minr = radius - 0.5
maxr = radius + 0.5
for ix = minx,maxx,0.1 do
for iy = miny,maxy,0.1 do
for iz = minz,maxz,0.1 do
for ir = minr,maxr,0.1 do
equation1 = ix^2 + iy^2 + iz^2
equation2 = ir^2
if equation1 == equation2 then
return true
end
end
end
end
end
end
trying to make the program check at intervals of 0.1 between x -0.5 and +0.5, y - 0.5 an +0.5 etc… with a mess of for loops because why not. And the result: http://imgur.com/6IiJEBm
Closer, but still full of holes.
and with increments of 0.05: http://imgur.com/OdQ4F2E i kinda got a negative version of the last one.
I tried increments of 0.01 but my turtle just stopped working, probably for the crazy amount of cycles it went through.
So questions: Is it even possible to build a half sphere like this in minecraft using an equation that usually draws points and not 1*1*1 m cubes? Is there something i can change in the code to get better results or should I change my approach? Is there a smarter way to do my function without 4 loops in a row? Is my math completely wrong like I think it is? Thank you guys in advance :P
P.S. I know there are a couple of dome builder program around the interwebz, but i kinda want to write the code by myself