| 12-27-2007, 02:31 PM | #1 |
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. 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 |
| 12-27-2007, 02:45 PM | #2 |
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 |
Ah thanks, I was overcomplicating it. |
| 12-27-2007, 07:02 PM | #4 |
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: 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 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 | |
Quote:
Luckily he wanted a random point a fixed distance from the center, so this is not an issue. |
