janDD has asked for the
wisdom of the Perl Monks concerning the following question:
Hi,
I am currently struggeling with the task to place rectangular tiles "nicely" in a circle with radius = 100 ....
Starting point is a hash %hash{$x}{$y}=$color which associates a color to a coordinate.
My current approach is to calculate the distinct number of x and y and determine the tile size for a square 100x100. Then I walk through the coordinates and determine the outermost point with respect to the center of the square. I then calculate the shrinkage factor so that this outermost point fits in the circle. After that, I can resize each tile using this factor and the tiles fit in the circle.
This approach works nicely with regular tile arrays, see for instance this picture:
http://www.myimg.de/?img=tile136472.png
If the tile array is irregular, however, the algorithm fails. The problem is that the algorithm always implies that the tile array is a square. This leads to different distances of the tile points to the circle in the following picture:
http://www.myimg.de/?img=tile2a1863.png
The algorithm calculates assuming the presence of the blue tiles:
http://www.myimg.de/?img=tile316d1d.png"
With these few tiles, one might argue that this still looks ok. If there are really many tiles, no intertile distance and the arrangement is asymmetric, it looks strange, see this picture:
http://www.myimg.de/?img=tile417dd5.png
I can't really think of an algorithm that somehow puts the tiles in the "middle" of the circle, meaning that in average all outer points of a tile have the same distance to the circle. I want to achieve, that the tiles "look" centered.
I thought of walking through the coordinates rowwise and calculate the outermost points for each row. with some geometry it is easy the get the distance to the circle. i then have an array of distances of the outermost point/tile for each row. the tricky part (where i am stuck) is, how to move/resize the tiles now ... ;(
maybe you guys have an idea
Best regards
Jan
Re: Placeing Tiles in a Circle by BrowserUk (Pope) on Nov 29, 2013 at 17:22 UTC 
There are only four positions to consider. If you view this image, you see that there are 4 circles drawn over a grid of squares:
 The green circle, is centered at the green dot, which aligns with a crossover point of the grid.
It contains 4 full tiles.
 The blue circle, is centered at the blue dot, which is aligned with the grid in the yaxis and misaligned by half a tile in the xaxis.
It encompasses 6 full tiles in a 3 x 2 arrangement.
 The yellow circle, is centered at the yellow dot, which is aligned with the grid in the xaxis and misaligned by half a tile in the yaxis.
It also encompases 6 full tiles, this time in a 2 x 3 arrangement.
 And the magenta circle, is centered at the magenta dot, which is the center of a tile.
It encompasses 5 full times.
Whether you need full tetrameric (quadrilateral) symmetry (green or magenta) or will settle for bilateral symmetry (blue or yellow), those really are the only 4 points to consider regardless the proportions of the tiles.
How you choose between them is really just a case of deciding upon your criteria and a little math.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks  Silence betokens consent  Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
 [reply] 

Hi BrowserUK,
your analysis is perfectly true and you are describing the algorithm I just implemented. The magenta circle is essentially picture 1 of my post.
But lets consider again this picture: http://www.myimg.de/?img=tile2a1863.png  how would you achieve that the distance of the uppermost green tile has the same distance to the circle as the lower left green tile? I don't think that this can be achieved by placing the center of the circle to any of the four points you mention ...
The tricky think is to move the center of the circle such that the beholder "thinks", the tiles are centered. Please look at my last pic (http://www.myimg.de/?img=tile417dd5.png) where the optical glitch of a nonsymmetric tile array becomes obvious ...
Best regards
Jan
 [reply] 

I don't think that this can be achieved by placing the center of the circle to any of the four points you mention ...
Let me restate this. If you want symmetry, then positioning the circle at one of those 4 points will ensure that. No other point will give you symmetry. Full stop.
The problem with this (please learn to use the links), is that you are comparing eggs with oranges. That is to say why are you comparing the 'gap' of the bottom square in column 1 with a 'gap' of the top square in column 2? It doesn't make any sense at all.
If you fill in the rest of the tiles, you'll see that once you compare like with like (ie. caps top and bottom of the same columns), that "problem" goes away.
And you'll also see that once like for like gaps are equalised, the circle is centered at the halftile offset in both xaxis and yaxis (the magenta circle on my plot). And for a full grid, it will always be one of those 4 positions.
Only now, having typed that last sentence does the word "irregular" from your OP ring alarms in my head....
What you real want is an algorithm to evenly encircle any pattern of tiles on a grid, partial or full. Yes?
(Assuming so, I'll let my brain mull that completely different problem to the one I was solving and get back to you if I come up with anything :)
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks  Silence betokens consent  Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
 [reply] 


 Re: Placeing Tiles in a Circle by BrowserUk (Pope) on Nov 29, 2013 at 15:37 UTC 
 [reply] 

Yes, all tiles have the same size (width and height) and orientation
 [reply] 
Re: Placeing Tiles in a Circle by GrandFather (Sage) on Nov 30, 2013 at 23:07 UTC 
Why? Why are you doing this? BrowserUK has given you the hint you need if we understand what you are asking correctly, but the terms you use ("regular" and "irregular" in particular) and the mention of calculating a "shrinkage factor" suggests that maybe we don't have any idea what the actual constraints on your problem are. If you tell us what you want to do this for it may give enough context that we can give the answer you are looking for.
True laziness is hard work
 [reply] 
Re: Placeing Tiles in a Circle by oiskuu (Friar) on Nov 30, 2013 at 18:50 UTC 
You are looking for a circle drawing algorithm then, one that runs on a rectangular grid?
Update. More precisely, it seems you want a filled ellipse, which, because of the "stretched" grid, appears as a circle. (Ahh. Memories of BASIC resurfacing.)  [reply] 

