AS3 Polar Coordinates and Radians


Many times I’ve set up interfaces where I need to place different objects equidistant around a central object. The solution to this problem is to first calculate the angle of each object by converting Radians to Degrees. This can be expressed by the following formula


So, you simply need to loop through your collection of objects and assign each a different angle. After that you plug that angle into a new Polar Point.

for(var i=0;i

Here’s the complete source:

        import flash.ui.*;
        import flash.display.*;
        import flash.geom.*;

        public class Main extends Sprite

                | Private Variables                         | Data Type

                private var array:Array = new Array()
                private var circumference:int;

                | Constructor

                public function Main ()
                        stage.align = StageAlign.TOP_LEFT;

                        // make some balls
                        addParticle( 100 )

                        menu.txtParticles.text = 'Particles: 100';

                        stage.addEventListener( Event.ENTER_FRAME, runParticle )

                        menu.slideCircumference.addEventListener( Event.CHANGE, changeCircumference );
                        menu.particles.addEventListener( Event.CHANGE, changeParticles );


                private function addParticle( num )
                        stage.removeEventListener( Event.ENTER_FRAME, runParticle )

                        var tot:Number = array.length

                        // kill mc's
                        for( var t=0;t