This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Buho's profile picture

Digging a ring

Started by Buho, 13 December 2013 - 07:58 AM
Buho #1
Posted 13 December 2013 - 08:58 AM
I wrote a program that digs a 1-block ring of a specified radius and depth. I used 20 turtles to carve out a subeterranean (squared-off) torus of a radius between 44 and 64 blocks.

This mostly worked great. However, at the diagonals (NE, SE, SW, NW) there was an imprecision and hundreds of undug columns were left behind (while other columns were dug more than once). The problem can be seen when you overlay multiple pixel-circles of different radii on top of each other: some pixels in the middle don't get drawn.



I was wondering if other people have run into this and how they solved it? This is mostly theoretical, as my chamber is dug now; I just have a lot of manual cleanup work to do (which grates me, the turtles should be doing my work). Maybe I should have implemented a completely different algorithm such as one written for drawing thick circles? But I have no clue what it would be.
Csstform #2
Posted 13 December 2013 - 12:55 PM
Not sure but check this link:
http://www.computercraft.info/forums2/index.php?/topic/11520-the-versatile-shape-builder-updated-040713-now-with-resume-function/page__view__getnewpost
Buho #3
Posted 13 December 2013 - 01:51 PM
Yeah, I saw that. The closest it comes to my problem is cylinders. I've written that algorithm, too, simple Pythagorean formula. The unique problem I have is to leave the center part of the structure intact while digging a ring around it.

My question is more of an algorithms one: how to draw a thick, hollow circle with a cursor you can't pick up and move (the turtle).
Csstform #4
Posted 13 December 2013 - 02:24 PM
You could use a gps system to tell the turtle where to go, an how deep. Additionally, you could try this.

depth = read()
width = read()
circleCircumference = read()

currentDepth = depth

while currentDepth = not 0 do
   turtle.digDown()
   currentDepth = currentDepth - 1
end

while currentDepth = not depth do
   turtle.up()
   currentDepth = currentDepth + 1
end

currentWidth = width
if width = not 0 do
   while currentWidth = not 0 do
      turtle.left()
      currentWidth = currentWidth - 1
   end
end

--loop the above then add logic to have
--the turtle walk the circumference of the circle
Sorry, I'm not the best turtle programmer.
Bomb Bloke #5
Posted 13 December 2013 - 07:14 PM
So if I've got this right, you have it dig out a ring, then dig out a ring of a different radius, then another, and so on until it's completed a loop along the lines of "for i=44,64 do"?

I would go with digging lines from the edge of the wider circle to the edge of the of the smaller.

Have it move out from the origin point (the center of the loop) along the x-axis. For every block moved, it then calculates the corresponding y-locations of the perimeter of the two circles that are eg to its left, and digs a line from one of those points to the other. It then moves another block along the x-axis and repeats until it's moved a distance equal to the larger circle's radius, at which point it'd go back to the origin, turn right, and repeat the whole operation another three times.
Csstform #6
Posted 13 December 2013 - 10:38 PM
That is what I was trying to code by using the width of the ring, but as I said, I'm not the greates with turtles, and this was coded on the run.