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 inter-tile 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 row-wise 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
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 inter-tile 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 row-wise 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
Back to
Seekers of Perl Wisdom