Notes:
as this method uses a series of lines to construct the curve, a low angular change will result in a smoother curve. however, if a higher value is used, this will construct what appear to be “warped” polygons. for example, an angular change of 45 degrees (Pi/4 rad) will give an eight sided polygon. changing the dx and dy will still result in an elliptical shape.
ActionScript:
with( MovieClip_Object ) {
//center of ellipse
var x0 = Stage.width/2;
var y0 = Stage.height/2;
//ellipse bounds
var dx = 300;
var dy = 100;
//angular change
var dn = 1 * (Math.PI/180);
var r,x,y;
lineStyle(1, 0x000000);
for( var n=0; n<2*Math.PI; n+=dn ) {
x = dx*Math.cos(n);
y = dy*Math.sin(n);
moveTo(x0+x,y0+y);
x = dx*Math.cos(n+dn);
y = dy*Math.sin(n+dn);
lineTo(x0+x,y0+y);
}
}
var angle_deg = angle_rad * 180/Math.PI;
var angle_rad = angle_deg * Math.PI/180;
find (x,y) from angle and radius:
var x = radius * cos( angle_rad );
var y = radius * sin( angle_rad );
a minor issue you will come across in ActionScript is that all of trigonometry functions in Math are based on the angle in radians, and a MovieClip’s _rotation property is based on the angle in degrees (this is not a bug or a flaw, but rather a design decision).