Algorithms for positioning objects in canvas

Where can I find some algorithm for positioning some objects in the canvas in a smart way? I use javascript (with the Raphael svg library), but examples with other languages ​​(or a pseudo-language) are welcome. Geometry is not my strong point =)

For example, a canvas of size 600x800, and I want to place n objects of size 60x60 in clever ways, for example:
- an algorithm for positioning objects along m concentric circles with o offset.
- an algorithm for positioning objects along m concentric squares, but an alternative frequency (the result can be like a chessboard)

And similar examples .. I'm just looking for some working examples to adapt to my case. Thanks in advance =)

+3
source share
1 answer

For a circle:

Inputs: CenterPt (presumably 300,400), RadiusLargestCircle (presumably 270 to ensure that all objects are on the screen) RadiusDelta (60 ensures there are no overlapping objects if the objects are circles)

calculate the number of circles ((RadiusLargestCircle -2 * RadiusDelta) / RadiusDelta)

for each circle

  RadCir= RadiusLargestCircle - (CircleNum*RadiusDelta)

(I will finish this later, now I will head)

but essentially the first centerpt object goes to x = radiusLargestCircle, y = 0

divide the radius of the object 2 * by the circle circumference

for num objects

using the parametric equation of a circle, the place of the object in x radians from the previous one

next round

+1
source

Source: https://habr.com/ru/post/1711411/


All Articles