A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: trying to find coordinates for points around a circle

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Location
    BC, Canada
    Posts
    29

    trying to find coordinates for points around a circle

    How do I find the x,y coordinates for nNumber of equally spaced points around the circumference of a circle?

  2. #2
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    you make use of 2 facts. first, there are 2 pi radians in a circle- so to divide the circle up evenly you find an interval of 2 pi / n. secondly, a point in polar coordinates (radius,angle) can be converted to cartesian coordinates (x,y) by:
    ( Math.cos( angle ) * radius, Math.sin( angle ) * radius ). The algorithm below adds a center argument so that you can specify the circle's position.
    PHP Code:
    public static function getNPointsOnCirclecenter:Pointradius:Numbern:Number 10 ) : Array
    {
        
        var 
    alpha:Number Math.PI n;
        var 
    points:Array = new Array( );
        
        var 
    i:int = -1;
        while( ++
    )
        {
            var 
    theta:Number alpha i;
            var 
    pointOnCircle:Point = new PointMath.costheta ) * radiusMath.sintheta ) * radius );
            
    points] = center.addpointOnCircle );
        }
        
        return 
    points;
        


  3. #3
    Junior Member
    Join Date
    Jul 2008
    Location
    BC, Canada
    Posts
    29
    Thanks, worked great!

  4. #4
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    hi, could any one tell me how i could run this in java as when i compile it, it throws an error.
    thanks in advance

  5. #5
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    This is a Flash forum. Try asking

    Quote Originally Posted by hafunui View Post
    How do I find the x,y coordinates for nNumber of equally spaced points around the circumference of a circle?
    in a Java forum.

  6. #6
    Junior Member
    Join Date
    Sep 2001
    Posts
    14
    Hi
    Can someone please tell me how I might use this function to actually display something around a circle? say for instance I want to display numbers around the circle.
    I see the math and how it works fine but I'm not making the connection of how to implement it to a display.

    Please forgive me I'm trying to get a grip on ActionScript..
    Any help would be much appreciated.

  7. #7
    Member
    Join Date
    Feb 2010
    Posts
    59
    The formula for a circle:

    (x-h)^2+(y-k)^2=r^2

    (h,k) is the center

    r is the radius

    dmschenk. I can help you get a grip:

    http://board.flashkit.com/board/show...56#post4241856

  8. #8
    Member
    Join Date
    Nov 2000
    Location
    South East UK
    Posts
    91
    newblack, I'm trying to use your code with AS3, but whereas I'm fairly good with AS2 I'm getting the usual confusing errors in AS3!

    this is the class I'm creating with your code....

    PHP Code:
    package getNPointsOnCircle
    {
       
    // class contents (methods and properties) will go here
      
    public static function getNPointsOnCirclecenter:Pointradius:Numbern:Number 10 ) : Array    {

        var 
    alpha:Number Math.PI n;
        var 
    points:Array = new Array( );

        var 
    i:int = -1;
        while( ++
    )
        {
            var 
    theta:Number alpha i;
            var 
    pointOnCircle:Point = new PointMath.costheta ) * radiusMath.sintheta ) * radius );
            
    points] = center.addpointOnCircle );
        }
        
        return 
    points;
        
        } 


    Then I'm using this to call it in my .fla

    getNPointsOnCircle(0,100,10);
    trace("points="+points)

    only problem is... getting a nasty error I don't really understand (I'm a beginner with AS3)
    PHP Code:
    getNPointsOnCirlce.as, Line 6 1012The static attribute may only be used on definitions inside a class 
    Source: public static function getNPointsONCircle(center:Pointradius:Numbern:Number=10) : Array { 
    Last edited by derekcfoley; 04-30-2010 at 12:02 PM.

  9. #9
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    you need to put static method definitions in a class definition, so wrap the method in "public class YourClass { }" then reference via YourClass.getNPointsOnCircle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center