HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

uniform random point inside circle

12-11-2007, 10:08 AM#1
MaD[Lion]
i have 2 methods to do this tat i found on the net. which one is faster?

The first one is said to be fastest on computer:
Get random point in square tat holds the circle and check if tat point is inside circle, else find new one. Photon mapping used this.

2nd method i like more cus its more mathematical:
Alpha = GetRandomReal(0,360)
r = SquareRoot(GetRandomReal(0,1))
x = r*radius*cos(Alpha)
y = r*radius*Sin(Alpha)
12-11-2007, 10:19 AM#2
cohadar
Actually your second method is bugged, you should do:
Collapse JASS:
angle = GetRandomReal(0,2*bj_PI)
r = SquareRoot(GetRandomReal(0,1))
x = r*radius*Cos(angle)
y = r*radius*Sin(angle)
12-11-2007, 10:37 AM#3
MaD[Lion]
my is not if sin cos takes degree ^^ this is just generic, not really jass related
12-11-2007, 10:43 AM#4
cohadar
Genetic kills people.
12-11-2007, 11:07 AM#5
PandaMine
Read this, it helped me a lot (gives everything in relation to geometry for computing in graphics). Its a pdf document BTW (just had to rar it cos Wc3 doesnt accept attachments)
12-11-2007, 11:53 AM#6
Tide-Arc Ephemera
Quote:
Originally Posted by cohadar
Genetic kills people.
Genetics obviously made you illiterate, he said generic.
___

From the very little yet useful experience that I've been told, using one formula us SUPPOSED to be faster than two shapes. Basically just trying to find a random distance from a point in a random direction SHOULD be faster than drawing up a square, choosing something inside it, then filtering it out if it's not there and trying again.

At least that's what I heard.

So I think your mathematical (2nd?) method is faster.
12-11-2007, 12:09 PM#7
cohadar
Quote:
Originally Posted by Tide-Arc Ephemera
Genetics obviously made you illiterate, he said generic.

Nope, genetics made you not see the joke.
It probably has something to do with insufficient number of gray brain cells for lower primates.
12-11-2007, 12:34 PM#8
Malf
There was no joke.
12-11-2007, 12:48 PM#9
cohadar
Quote:
Originally Posted by Malf
There was no joke.

Define joke please.
(or not, because this is going waaay of topic)
12-11-2007, 01:13 PM#10
Anitarf
1st method:
Two random numbers, then three multiplications, a sum and a comparison to see if the chosen point is correct. Has an 1-(pi/4) = 0.215 chance of not being in the circle, in which case the procedure is repeated, which gives you approximately 0.275 repeats per query.

2nd method:
Two random numbers, square root, cos, sin and four multiplications. This one is most likely slower.

Quote:
Originally Posted by cohadar
Define joke please.
Something funny; so, nothing that you ever said. :P
12-11-2007, 01:17 PM#11
cohadar
Quote:
Originally Posted by Anitarf
Something funny; so, nothing that you ever said. :P

Define funny? Funny to who?


Btw 2 method is indeed slower in c++,
but in jass it is not.
12-11-2007, 01:33 PM#12
Vexorian
http://mathworld.wolfram.com/DiskPointPicking.html


Imho I like this one:

Collapse JASS:
function RandomPointInDisk takes real x, real y, real d returns location
 local real cx = GetRandomReal(-d,d)
    local real ty = SquareRoot(d*d-cx*cx)
    return Location(x+cx, y+ GetRandomReal(-ty,ty) )
endfunction

It is not uniform, but the bias towards the extremes is very small and I would say acceptable for war3, but it is faster than the second method...