A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Dynamically placing points on a circle

  1. #1
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29

    Dynamically placing points on a circle

    Need a mathamagician here...

    Let's say I have x number of points (which will vary each time the flash loads) and I want to evenly dipsperse these points around a circle with a known radius. I have a vague idea from the searching I've done that I need to divide the radians into equal amounts and then calculate the x,y for each based on the radians and radius. However, the math is beyond me - don't even really know where to begin with this. Can anyone help?

    Thanks in advance -

    Moge

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Code:
    var PI2 = Math.PI * 2;
    var radiusSize = 100;
    var numOfPoints = 10;
    function doDots() {
    	var myHolder = this.createEmptyMovieClip("holder", 1);
    	myHolder._x = 150;
    	myHolder._y = 150;
    	var angleMod = PI2 / numOfPoints;
    	var myDepth = 1;
    	for (var newAngle = 0; newAngle < PI2; newAngle += angleMod) {
    		var myDot = myHolder.attachMovie("dotMC", "dot" + ++myDepth, myDepth);
    		myDot._x = Math.cos(newAngle) * radiusSize;
    		myDot._y = -Math.sin(newAngle) * radiusSize;
    	}
    }
    doDots();
    Last edited by dawsonk; 08-22-2007 at 10:50 AM.

  3. #3
    Junior Member
    Join Date
    Jan 2005
    Location
    San Francisco
    Posts
    29
    Cool - thanks very much. I still don't entirely get the math, but I get the code enough that I can modify it for my purposes and pass in dynamic variables.

    Moge

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