Page 1 of 1

Random Point on a Circle

PostPosted: Wed Jan 29, 2014 12:02 am
by CrackedP0t
I need a way to get the X and Y coordinates of random point on a circle with an origin of (0,0) and a radius of 420px.

This gets 1/2 of the circle.

Code: Select all
const int sr = 420; // Radius
int sx = sr - rand(sr * 2); // X-coordinate
int sy = sqrt(pow(sr, 2) + pow(sx, 2)); // Y-coordinate

Re: Random Point on a Circle

PostPosted: Thu Jan 30, 2014 2:30 am
by skydereign
Take the center, a random angle, and a random radius. Then use sin/cos to find the coordinates.
Code: Select all
double ang = rand(360);
double radius = rand(420);
int sx = 0 + cos(ang)*radius;
int sy = 0 + sin(ang)*radius;

Re: Random Point on a Circle

PostPosted: Thu Jan 30, 2014 2:54 am
by CrackedP0t
Thanks!
This made my game very hard... heehee.