Flex/Actionscript Function to Calculate Random Point IN Circle -
not sure i'm doing wrong here looking see if had thoughts or suggestions. i'm trying create function returns random point within circle. following code gives me random points along edge of circle. thoughts on i'm doing wrong here? thanks!
private function getpointincircle(tmpradius:int):point { var x:int; var y:int; var a:number = math.random() * 360; x = radius * math.cos(a * (math.pi / 180)); y = radius * math.sin(a * (math.pi / 180)); trace("x: " + x + "y: " + y); return new point(x, y); }
you need 2 degrees of freedom, 1 angle, had, , other distance center:
var d:number = math.random()*radius var a:number = math.random()*2*math.pi; x = d*math.cos(a); y = d*math.sin(a);
if have circle centered in (x0,y0)
, not in (0,0)
modify this:
x = x0 + d*math.cos(a); y = y0 + d*math.sin(a);
trivia: circle border line. if want refer area delimited border, disk.
Comments
Post a Comment