Finding a random point on a circle

You must understand the Game Editor concepts, before post here.

Finding a random point on a circle

Postby Fuzzy » 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.

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Finding a random point on a circle

Postby Kalladdolf » Mon Mar 30, 2009 1:06 pm

Thanks a bunch, this is way less complicated than the formula my brother-in-law once came up with!
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Finding a random point on a circle

Postby Fuzzy » Mon Mar 30, 2009 4:09 pm

Kalladdolf wrote:Thanks a bunch, this is way less complicated than the formula my brother-in-law once came up with!


You will find it develops holes when the radius gets big.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Finding a random point on a circle

Postby Kalladdolf » Mon Mar 30, 2009 6:33 pm

And if you use i as a float (or is that what you're already doing)?
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Finding a random point on a circle

Postby Fuzzy » Tue Mar 31, 2009 2:51 am

It doesnt matter if i is a float or an int.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Finding a random point on a circle

Postby Bee-Ant » Sat Apr 04, 2009 1:15 pm

Fuzzy wrote:WE thought that everyone should know

I didn't think about it... :arrow:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Finding a random point on a circle

Postby Kalladdolf » Sat Apr 18, 2009 12:30 pm

Anyway... until now it's worked great so far.
Are those holes regular or irregular?
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Finding a random point on a circle

Postby Bee-Ant » Sat Apr 18, 2009 10:12 pm

Whaddya mean with regular or irregular?
I used this code to make recharge effect.
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Finding a random point on a circle

Postby Fuzzy » Sun Apr 19, 2009 9:52 am

Kalladdolf wrote:Anyway... until now it's worked great so far.
Are those holes regular or irregular?


Regular.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: Finding a random point on a circle

Postby Bee-Ant » Sun Apr 19, 2009 11:35 am

Btw fuz,do you know how to make formula that has the same function with "MoveTo" using angle and directional_velocity?
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Finding a random point on a circle

Postby Kalladdolf » Sun Apr 19, 2009 11:38 am

Fuzzy wrote:
Kalladdolf wrote:Anyway... until now it's worked great so far.
Are those holes regular or irregular?

Regular.


From that I would conclude that with a certain radius, normal angle values (like 1,2,3,4, 89, 134, 343) become too unspecific.
I think I might try a float variable with more precise numbers, maybe the holes'll get smaller.
EDIT:
@Bee-ant: You mean just the simple MoveTo function without avoid? I always used:
Code: Select all
angle = direction(x,y,destination.x,destination.y); directional_velocity = whatever;

And then some coordinates to stop the actor from moving once it's there.
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Finding a random point on a circle

Postby Bee-Ant » Sun Apr 19, 2009 5:03 pm

What!!!
Ehm...thanks
Thats what i need...
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Finding a random point on a circle

Postby Kalladdolf » Sun Apr 19, 2009 5:26 pm

You sure that wasn't sarcastic?
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Re: Finding a random point on a circle

Postby Bee-Ant » Sun Apr 19, 2009 11:55 pm

Huh?course not...

Hmmm,actualy i was thinking about direction,but just dont know the syntax yet...

Oh yah,do you have machinary sound such as motor,robot,laser,metal,etc?
Also some pic of futuristic machinary building or room?
Want them sooo much...well,i think i need to topic this.
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Finding a random point on a circle

Postby Kalladdolf » Mon Apr 20, 2009 1:50 pm

Bee-Ant wrote:Huh?course not...

Oh, right, yeah, it sounded to me like I defeated the purpose completely. Glad I didn't. :)
User avatar
Kalladdolf
 
Posts: 2427
Joined: Sat Sep 08, 2007 8:22 am
Location: Germany
Score: 120 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest