Is it possible to get a random point in region A, which isn't in region B, if the regions overlap?
I tried to make a function, that gets random points until the point fulfil these conditions, but there is a problem: Region B can contain the complete region A. If region A is complete in region B, the function should return no point.
How can I do this?
If you're using editor-placed regions, add negative shapes to them if you only have region A and region B (more regions than that won't work for the trigger), add the negative shape to fit the other region (same center, shape and size)
Also, the random integer function can sometimes fail with regions with negative shapes.
There are more than two regions. I used A and B to explain my problem. I wanted to create a function for any regions, i.e. you can choose region A and B whenever you run the function.
I would suggest making it pick a random point in A. Then it checks if the point is also in B, and if it is, picks it again. This could be accomplished with the 'while' loop.
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
I would suggest making it pick a random point in A. Then it checks if the point is also in B, and if it is, picks it again. This could be accomplished with the 'while' loop.
I can think of two ways to make something that could do, they can be combined ofc...
Check like 20 or maybe 50 times and if all of them fail, return no point. Add 1 to an integer in the end of the while and do an integer compare condition...
Check the corners + center point + middle of each side, total of 9 points. If none of these points is only in A and not B, then one can assume that no point is. Something that should cover all the extremes so to speak...
It's not perfect, it can fail, but it's pretty good i think...
Region B can contain the complete region A. If region A is complete in region B, the function should return no point. How can I do this?
Try and make a function that compares two regions to see if they cover the same space, for rectangular regions that would mean checking all four corners, for circular ones you would check the center and the radius, functions for doing this should already be in the editor.
Is it possible to get a random point in region A, which isn't in region B, if the regions overlap? I tried to make a function, that gets random points until the point fulfil these conditions, but there is a problem: Region B can contain the complete region A. If region A is complete in region B, the function should return no point. How can I do this?
Ive been over this kinda quite a bit and the "random point" function doesnt work very well.... if has an internal fail check that if it takes to long to find a valid point it will return a point that doesnt hold to what you want..
Now you could just keep looping till a random point matches additional conditions you check it against..... but the random point function isnt very random IMO so you have to loop through "ALOT" which in a case where you randoming alot of points for alot of players it may actually cause a battle net game to de-sync.
S3rius proposed a way to me to do things a bit differently ... heres a topic we talked about it on..
so you have to loop through "ALOT" which in a case where you randoming alot of points for alot of players it may actually cause a battle net game to de-sync.
Is it possible to get a random point in region A, which isn't in region B, if the regions overlap? I tried to make a function, that gets random points until the point fulfil these conditions, but there is a problem: Region B can contain the complete region A. If region A is complete in region B, the function should return no point. How can I do this?
If you're using editor-placed regions, add negative shapes to them if you only have region A and region B (more regions than that won't work for the trigger), add the negative shape to fit the other region (same center, shape and size)
Also, the random integer function can sometimes fail with regions with negative shapes.
Let's hope someone else has a better solution.
There are more than two regions. I used A and B to explain my problem. I wanted to create a function for any regions, i.e. you can choose region A and B whenever you run the function.
I would suggest making it pick a random point in A. Then it checks if the point is also in B, and if it is, picks it again. This could be accomplished with the 'while' loop.
@zeldarules28: Go
That's what I have done. But it won't work, if A is completely in B. Any idea how to detect this case?
@WiiKing: Go
I can think of two ways to make something that could do, they can be combined ofc...
Try and make a function that compares two regions to see if they cover the same space, for rectangular regions that would mean checking all four corners, for circular ones you would check the center and the radius, functions for doing this should already be in the editor.
Ive been over this kinda quite a bit and the "random point" function doesnt work very well.... if has an internal fail check that if it takes to long to find a valid point it will return a point that doesnt hold to what you want..
Now you could just keep looping till a random point matches additional conditions you check it against..... but the random point function isnt very random IMO so you have to loop through "ALOT" which in a case where you randoming alot of points for alot of players it may actually cause a battle net game to de-sync.
S3rius proposed a way to me to do things a bit differently ... heres a topic we talked about it on..
http://forums.sc2mapster.com/development/triggers/15555-trigger-gui-random-point-failure/
What are you basing this on?
@s3rius: Go
I was having players complain to me about de-sync errors..... that occurred during my radoming / semi-infinite looping while generating points.....
not entirely sure if thats true or not...