Finding a random point on a circle
Posted: Mon Mar 30, 2009 12:55 pm
Bee Ant asked me how to do this, and we thought that everyone should know. So thank him if its useful to you.
First, pick a number from 0 to 359. Store it in a variable. I used i.
Next, use two variables to store floats. that is variable type real. Call them xr and yr for radius. Next you need an integer to store distance from center. I used d.
After these lines of code you can use xr and yr to add to an actor's x and y. This is good for special effects.
visual demonstration here.
http://www.dreade.org/applets/circlerandom/
Thanks to DST for the hosting.
First, pick a number from 0 to 359. Store it in a variable. I used i.
Next, use two variables to store floats. that is variable type real. Call them xr and yr for radius. Next you need an integer to store distance from center. I used d.
After these lines of code you can use xr and yr to add to an actor's x and y. This is good for special effects.
- Code: Select all
i = rand(360);
xr = cos(degtorad(i))*d;
yr = sin(degtorad(i))*d;
visual demonstration here.
http://www.dreade.org/applets/circlerandom/
Thanks to DST for the hosting.