Placing display objects in a circular path ?

Hi Geeks,

I am looking to place a set of display objects , say circles or rectangles , in a circular orbit. 

One way is to manually do a trial and error, another way is by a equation of a circle…

is there any other simpler , efficient way to achieve this in corona ?

Thanks!

Regards,

Joel

You would have to do the calculations. 

Rob

It depends on how flexible you like it (:
The most flexible solution would be to use sin and cos to calculate the various angles. You multiply them for a specific radius, and get back the position of your circles. Trigonometry is quite taxing though, so if performance are very important (like if you’re doing this on a regular basis during your runtime) it might not be the best choice.
Another one is to preset these angles. Say you always need 16 circles to form up a circle shape, you store the math.sin and math.cos results in advance within a table, and then you loop through that table to get the results. This way you still have the ability to specify a radius by multiplying the results for it.
Then you can also directly specify the x and y offset of the circle from an origin point, and directly read these as x and y for your circles.

Last, but I’m not sure if it works 100% (; Is to use the new outlineShape from Corona. I never even tested it, so it’s pure guessing d: But if ideally it returns a series of points outlining the shape of your image, you could have for example a pentagon in a .png, outline its shape and get the points of the pentagon. Then you loop through them and position your circles. This is more of a gimmick though d:

There are even more ways to achieve what you want in one way or another, it just really depends on your needs (basically wether you need it to be as performant as possible or not).

Thanks Rob and Raqdoq!

You would have to do the calculations. 

Rob

It depends on how flexible you like it (:
The most flexible solution would be to use sin and cos to calculate the various angles. You multiply them for a specific radius, and get back the position of your circles. Trigonometry is quite taxing though, so if performance are very important (like if you’re doing this on a regular basis during your runtime) it might not be the best choice.
Another one is to preset these angles. Say you always need 16 circles to form up a circle shape, you store the math.sin and math.cos results in advance within a table, and then you loop through that table to get the results. This way you still have the ability to specify a radius by multiplying the results for it.
Then you can also directly specify the x and y offset of the circle from an origin point, and directly read these as x and y for your circles.

Last, but I’m not sure if it works 100% (; Is to use the new outlineShape from Corona. I never even tested it, so it’s pure guessing d: But if ideally it returns a series of points outlining the shape of your image, you could have for example a pentagon in a .png, outline its shape and get the points of the pentagon. Then you loop through them and position your circles. This is more of a gimmick though d:

There are even more ways to achieve what you want in one way or another, it just really depends on your needs (basically wether you need it to be as performant as possible or not).

Thanks Rob and Raqdoq!