I cobbled together a poor hack for plotting equidistant points on an
ellipse. I'm going to post the code here, with comments, so future archive
searches will yield something. This might be ugly in email, but it is
complete. It requires a library mc with linkage "circle."

/*
background:

ellipse: http://www.devx.com/webdev/Article/28728
circle: http://www.devx.com/webdev/Article/28502

Rich Shupe, FMA http://www.fmaonline.com
*/
//
//initial values
var i:Number = 0;
var j:Boolean = true;
var angle:Number = 0;
//
//degrees to radians
function deg2rad(degree:Number):Number {
  return degree * (Math.PI / 180);
}
//
//distance between two points
function pDp(x1:Number, y1:Number, x2:Number, y2:Number):Number {
  return Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
}
//
//draw ellipse using param values
function drawEllipseWithPoints(eWidth:Number, eHeight:Number,
eCenterX:Number, eCenterY:Number, dotGap:Number) {
  //horz and vert "radii" of ellipse, based on width and height
  var xRadius:Number = eWidth / 2;
  var yRadius:Number = eHeight / 2;
  while (true) {
    //convert theta degrees to radians
    var radian:Number = deg2rad(angle);
    //use flag to create one point until next point required
    if (j) {
      //create first point, known as circle 0 for later use
      var dot:MovieClip = this.attachMovie("circle", "circle" + i, i + 1);
      //mostly legit calculation of point on ellipse
      dot._x = eCenterX + xRadius * Math.cos(radian);
      dot._y = eCenterY + yRadius * Math.sin(radian);
      //increment counter for unique instance names and level
      i++;
      //disable point creation until next use
      j = false;
    }
    //calculate each point with 1-degree change in theta,
    //  but only plot point when desired
    var tempX:Number = eCenterX + xRadius * Math.cos(radian);
    var tempY:Number = eCenterY + yRadius * Math.sin(radian);
    var myD:Number = pDp(dot._x, dot._y, tempX, tempY);
    //only create next point if distance is greater than desired gap
    if (myD > dotGap) {
      j = true;
    }
    //points don't continue to overlap when plotted equidistantly.
    //  stop drawing when ellipse is complete.
    var quitD:Number = pDp(circle0._x, circle0._y, tempX, tempY);
    if (myD > dotGap && quitD < dotGap) {
      //last point doesn't look right, so put it midway between first and
      //  second to last point.
      dot._x = this["circle" + (i - 2)]._x + (this["circle0"]._x -
this["circle" + (i - 2)]._x) / 2;
      dot._y = this["circle" + (i - 2)]._y + (this["circle0"]._y -
this["circle" + (i - 2)]._y) / 2;
      //use B.S. "magic number" of .07 * ration of width/height for wide
      //  and height/width for tall ellipses
      dot._x += dotGap * (.07 * (eWidth / eHeight));
      dot._y += dotGap * (.07 * (eHeight / eWidth));
      //  when finished, break out of the loop.
      break;
    }
    //increase theta by 1
    angle++;
  }
}
//

drawEllipseWithPoints(400, 200, (Stage.width / 2), (Stage.height / 2), 10);
//
stop();


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to