Posted 14 October 2013 - 02:51 PM
Hi guys i just wrote a little programme to build a quarter of the under half of a sphere. If i run it i get about 9 times a "nan" and then it goes on…but this part doesn't matter.
I think something with the goSide function is wrong, because if i use it and then print the result i get "nan". But i really don't know how to solve it, maybe you got a tip with x^0.5?
I hope you can help me. Here the programm:
Pastebin: http://pastebin.com/xqfbzerh
Code:
I think something with the goSide function is wrong, because if i use it and then print the result i get "nan". But i really don't know how to solve it, maybe you got a tip with x^0.5?
I hope you can help me. Here the programm:
Pastebin: http://pastebin.com/xqfbzerh
Code:
Spoiler
-------------------------------------- configurable
local r = 10 --r = Radius -0.5
local refuel = 15--Slot with Ender for Fuel
local mat = 16--slot with Ender for Buildingmaterial
local matTurtle = 1--free Slot
---------------------------------- not configurable
local matTurtle2 = matTurtle + 1 --free Slot
local emh = r --Entfernung zur Mitte horizontal
local emv = 0 --Entfernung zur Mitte vertikal
local aEMH = emh
---------------------------------------------- math
function round(a)
if (a - math.floor(a)) < 0.5 then
return math.floor(a)
else
return math.ceil(a)
end
end
function goSide(r, emh, emv)
local xGoSide = ((r ^ 2 - emv ^ 2) ^ 0.5 - emh ^ 2) ^ 0.5
if xGoSide < 0 then
return xGoSide * -1
else
return xGoSide
end
end
----------------------------------------------- re-
function recharge()
while turtle.getFuelLevel() < r + 100 do
turtle.select(refuel)
turtle.placeDown()
turtle.suckDown()
turtle.refuel()
turtle.digDown()
end
while turtle.getItemCount(matTurtle) == 0 do
turtle.select(mat)
turtle.placeDown()
turtle.select(matTurtle)
turtle.suckDown()
turtle.select(matTurtle2)
turtle.dropDown()
turtle.select(mat)
turtle.digDown()
end
end
-------------------------------------- move / place
function build()
for i = 1, emh do
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
print(round(goSide(aEMH, emh, emv)))
for i = 1, round(goSide(aEMH, emh, emv)) do
recharge()
turtle.select(matTurtle)
turtle.placeUp()
if i > 1 then
turtle.forward()
end
end
aEMH = aEMH - 1
end
end
for i = 1, r do
recharge()
for i = 1, emh + 1 do
turtle.forward()
end
turtle.turnLeft()
build()
turtle.turnLeft()
for i = 1, emh do
recharge()
turtle.forward()
end
turtle.turnLeft()
turtle.down()
emv = emv + 1
emh = round(r^2-emv^2)
aEMH = emh
end