HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Circle coordinate's question

12-27-2007, 02:31 PM#1
Castlemaster
I have a mathematical question.

If I want to generate a random coordinate that is 600 distance from the caster (i.e. a circle) without using locations, how exactly do I do that. There is what I have so far.
Collapse JASS:
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local real ylimit
    local real xnew
    local real ynew
    set xnew = GetRandomReal(-600.00,600.00) + x
    set ylimit = SquareRoot(360000-((xnew-x)*(xnew-x)))
    set ynew = GetRandomReal(-1*ylimit,ylimit) + y
First I make an X coordinate that is from -600 to 600. From here, I will just make the Y so that the xnew and ynew will not be more than 600 from x and y (using the distance formula of course)
12-27-2007, 02:45 PM#2
Skater
Collapse JASS:
    local real x=GetUnitX(caster)
    local real y=GetUnitY(caster)
    local real angle=GetRandomReal(0, 2*bj_PI)
    local real dist=GetRandomReal(0, 600)
    local real newx=x+dist*Cos(angle)
    local real newy=y+dist*Sin(angle)

This should work.
If not, some pros will tell it :D .
12-27-2007, 05:57 PM#3
Castlemaster
Ah thanks, I was overcomplicating it.
12-27-2007, 07:02 PM#4
Here-b-Trollz
I know you won't care, but polar projection is actually not extremely random. It is biased toward the centre of the circle (think about it this way. With shorter distances, the points on each angle line become closer together). If you want something that is uniform, use:

Collapse JASS:
function RandomPointCircle takes real x, real y, real d returns location
    local real a=GetRandomReal(0,2)*bj_PI
    set d=d*SquareRoot(GetRandomReal(0,1))
    return Location(x+d*Cos(a), y+d*Sin(a))
endfunction

or

Collapse JASS:
local real cx=GetUnitX(caster)
local real cy=GetUnitY(caster)
local real a=GetRandomReal(0,2)*bj_PI
local real d=600*SquareRoot(GetRandomReal(0,1) //600 is your size.
local real x=cx+d*Cos(a)
local real y=cy+d*Sin(a)
12-27-2007, 10:20 PM#5
Strilanc
Quote:
Originally Posted by Here-b-Trollz
I know you won't care, but polar projection is actually not extremely random. It is biased toward the centre of the circle .

Luckily he wanted a random point a fixed distance from the center, so this is not an issue.