wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 07-25-2009, 06:37 PM   #16
chobibo
100% Genuine Retard!
 
chobibo's Avatar
 
Join Date: Jan 2007
Posts: 797

chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)

Send a message via Yahoo to chobibo
Default

Quote:
Or can't you have a long incredibly complicated functions that put all (or some) of the coordinates that exist in a circle in a array. After that it will randomize an index and take those coordinates. Get my idea? Or maybe it's just stupid. I just feel unsafe with the possibility of so many runs in a loop for just a random point...

That would be inefficient, it would take a lot of memory and a lot of processing power.
__________________
Where's mah sig?

Last edited by chobibo : 07-25-2009 at 07:47 PM.
chobibo is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 07-25-2009, 06:51 PM   #17
ploks
User
 
Join Date: Jun 2007
Posts: 99

ploks has little to show at this moment (6)

Default

Doesn't that function still give an uneven distribution. The distance between the imagined lines (one per degree) is longer the farther out you come from the middle. (like a sun)

I believe that a loop is the only way. (create a square with the side 2r, randomize a point in square, check if distance between point and centre is <=r, if not repeat with new point)
ploks is offline   Reply With Quote
Old 07-25-2009, 07:02 PM   #18
Cheezeman
User
 
Cheezeman's Avatar
 
Join Date: Apr 2009
Posts: 179

Cheezeman has little to show at this moment (1)

Default

Flame_Phoenix once showed me this function made by Vexorian:
Collapse JASS:
    //Function made by Vexorian, it selects a random region in a disk.
    //All regions have the same chance of beeing choosen
    function GetRandomPointInDisk takes real centerx, real centery, real minradius, real maxradius returns location
        local real d = SquareRoot(GetRandomReal(minradius * minradius, maxradius * maxradius))
        local real a = GetRandomReal(0, 2 * bj_PI)
        return Location(centerx + d * Cos(a), centery + d * Sin(a))
    endfunction
Maybe it helps?
__________________
I have no signature yet
Cheezeman is offline   Reply With Quote
Old 07-25-2009, 07:06 PM   #19
chobibo
100% Genuine Retard!
 
chobibo's Avatar
 
Join Date: Jan 2007
Posts: 797

chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)

Send a message via Yahoo to chobibo
Default

I think you're right.
__________________
Where's mah sig?
chobibo is offline   Reply With Quote
Old 07-25-2009, 07:47 PM   #20
ploks
User
 
Join Date: Jun 2007
Posts: 99

ploks has little to show at this moment (6)

Default

Thanks for the answers. Guess I'll go with Vexorians function (even though I don't understand it). The reward Rep rep!
ploks is offline   Reply With Quote
Old 07-25-2009, 08:30 PM   #21
chobibo
100% Genuine Retard!
 
chobibo's Avatar
 
Join Date: Jan 2007
Posts: 797

chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)chobibo has a spectacular aura about (101)

Send a message via Yahoo to chobibo
Default

I also don't know,maybe the formula for the ara of the circle has something to do with this, since it used this formula: valid_r = √random(min_r^2, max_r^2)
__________________
Where's mah sig?
chobibo is offline   Reply With Quote
Old 07-25-2009, 10:13 PM   #22
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Quote:
I believe that a loop is the only way. (create a square with the side 2r, randomize a point in square
square root + sin/cos does work.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 07-25-2009, 10:31 PM   #23
uberfoop
User
 
uberfoop's Avatar
 
Join Date: Jul 2005
Posts: 207

Submissions (1)

uberfoop will become famous soon enough (29)

AI tournament - 2nd place

Default

Quote:
Originally Posted by Vexorian
square root + sin/cos does work.
Indeed. The math works, and a quick distribution chart agrees as well:
__________________
Quote:
Originally Posted by darkwulfv
.03 is one 300th of a second.

Last edited by uberfoop : 07-25-2009 at 10:33 PM.
uberfoop is offline   Reply With Quote
Old 07-25-2009, 10:40 PM   #24
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

That function is the only sensible thing to use, also it is quite short so you can just inline the code so you don't have to deal with locations.
__________________
Anitarf is offline   Reply With Quote
Old 07-25-2009, 10:58 PM   #25
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Anyway, the probability a random point in the square will be inside the circle is 0.785398164 (3 / pi).

Therefore, the Expected number of tries is:

E = 1 + E*(1 - 0.785398164 )
0.785398164 E = 1
E = 1.273239544

So on average the function needs slightly more than one try to get a point in the circle. So it is not as slow as it might look like, this is interesting, because for more complicated cases, like getting a random point inside two circles which have an intersection, it is probably the only way to do it without going crazy in the process...
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 07-25-2009, 11:10 PM   #26
ploks
User
 
Join Date: Jun 2007
Posts: 99

ploks has little to show at this moment (6)

Default

Quote:
Originally Posted by Vexorian
square root + sin/cos does work.

I don't doubt that. It just that the math is beyond me since I haven't started with trigonometric functions yet in school. Will do that after the summer break. Thanks for the function anyways :)
ploks is offline   Reply With Quote
Old 07-25-2009, 11:12 PM   #27
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

That's true, although with complicated cases, the smallest rectangle that encompasses your shape might still have a large percentage of it's area outside the shape, which makes it less effecient; that might be a moot point though if there's no other sane way to do it with that kind of shape.

Quote:
Originally Posted by ploks
I don't doubt that. It just that the math is beyond me since I haven't started with trigonometric functions yet in school. Will do that after the summer break. Thanks for the function anyways :)
You can always read up on them ahead of time.
__________________

Last edited by Anitarf : 07-25-2009 at 11:14 PM.
Anitarf is offline   Reply With Quote
Old 07-25-2009, 11:23 PM   #28
ploks
User
 
Join Date: Jun 2007
Posts: 99

ploks has little to show at this moment (6)

Default

Quote:
Originally Posted by Anitarf
You can always read up on them ahead of time.

Doin it already. However I guess a real math teacher combined with the fear of a bad grade will make me learn faster ;)
ploks is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 09:20 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services