Hossein has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have an object. this object has several other objects linked to it.

I need to draw the main object in the center and all the rest ( < 20 ) in a circular around the main object.

How do/should I do it?

(I think of sin/cos)

Thanks :)

/Hossein

Replies are listed 'Best First'.
Re: draw objects in circle
by choroba (Cardinal) on Aug 27, 2013 at 09:19 UTC
    Yes, sin and cos are the functions you need.
    #!/usr/bin/perl use warnings; use strict; use Tk; use constant PI => 4 * atan2(1, 1); my ($center_x, $center_y) = (25, 25); my $radius = 20; my $object_count = 19; my $mw = 'MainWindow'->new(-title => 'Objects in circle'); $mw->Label(-text => 'Center')->grid(-row => $center_x, -column => $center_y, ); my @objects = map "Object $_", 1 .. $object_count; my $step = 2 * PI / (1 + $#objects); for my $i (0 .. $#objects) { my $angle = $i * $step; my $x = $center_x + $radius * cos $angle; my $y = $center_y + $radius * sin $angle; $mw->Label(-text => $objects[$i])->grid(-row => $y, -column => $x, ); } MainLoop();
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thank you :)

      /Hossein
Re: draw objects in circle
by hdb (Monsignor) on Aug 27, 2013 at 09:00 UTC

    If you are asking how to calculate x/y coordinates for the positions of your objects on a circle, then sin and cos are the way to go. Multiply the results with the radius of desire.