• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

PolarProjection

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
How can I convert these actions;
  • Actions
    • Set TempLoc = (Target point of issued order)
    • Set TempLoc2 = (TempLoc offset by 300.00 towards (Random angle) degrees)
To this;
PolarProjection()

My intention is to remove location creation and replace it with reals.
Can someone teach me how to use PolarProjection (without BJs) ?

I know "PolarProjection" is not even a function, but is there any method to it ? Calculation perhaps ?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I don't get what is the question actually, do you want to use coordinates?

JASS:
// I don't remember exact name of these two natives
local real x = GetOrderPointX() 
local real y = GetOrderPointY()
local real angle = GetRandomReal(0, bj_PI * 2) // Radian, not degree
local real xx = x + 300 * angle
local real yy = y + 300 * angle
 
Level 16
Joined
May 1, 2008
Messages
1,605
JASS:
function name takes nothing returns nothing
    local real x = SorceX + distance * Cos(Facing * bj_DEGTORAD)
    local real y = SorceY + distance * Sin(Facing * bj_DEGTORAD)
    
    call SetUnitX(Unit,x)
    call SetUnitY(Unit,y)
endfunction
Stop wasting locals, just calculate them at once.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I need to know the (Random angle) function is calculated.
Can I use GetRandomDirectionDeg to randomize my degree from 1 to 360 ?

Okay, now I see the red color, I know it should be avoided.

Some of you said;
JASS:
local real angle = GetRandomReal(0, bj_PI * 2)

Some of you said;
JASS:
local real facing = GetRandomInt(0,630)/100

Which one is it ?

@HappyTauren
Lol, Random Angle is in Real but why do you call function GetRandomInt ?
 
Don't mind me, just too used to random ints, changed it up there :D

Well if you even wanna use this then it's that one:

JASS:
 GetRandomReal(0.01,360.) / 100
Inefficient, because Sin and Cos take radians, so you have to use bj_DEGTORAD conversion. Also, you shouldn't divide by 100, in my previous post there was a reason for it, because I thought GetRandomInt(lb,hb) was faster.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
My unit goes to left-top corner.

I mean, how to set a Coordinates of X/Y at GetOrderPointX/Y offset by 300 towards random angle (1 ~ 360)

I fail to get the "towards random angle" calculation, because my unit simply goes to top-left corner (no matter how many times the Event occur).

Current Calculation;
  • Then - Actions
    • Custom script: set r = GetRandomReal(1.00, 360.00)
    • Custom script: set i = GetRandomInt(udg_SF_MinPerimeterAOE, udg_SF_MaxPerimeterAOE)
    • Custom script: call IssuePointOrder(u, "smart", (GetOrderPointX() + i) * r, (GetOrderPointY() + i) * r)
Don't mind the GetRandomInt.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
File > Preferences > Test > Uncheck "Use Fixed Random Seed"
No, I mean not having problem with "randomizing" the angle, hmmm hard to explain.

Okay, can you guys give me a full script to set both x and y (Reals) to this situation;
GetOrderPointX/Y offset by 300 towards (Random angle)

The script would return x/y as final value for me to easily input in function parameter.

How would you guys do it ?

Btw, Ceday, your trigger ordered my unit to top-left corner, forever, whereas it should be offset by 300 around the GetOrderPointX/Y, it seems like it goes to 10,000 offset.
 
Level 16
Joined
May 1, 2008
Messages
1,605
File > Preferences > Test > Uncheck "Use Fixed Random Seed"

Not really, I have this option marked too but this still works for me:
JASS:
function action takes nothing returns nothing
    local real x = GetUnitX(gg_unit_hfoo_0000) + 50. * Cos(GetRandomReal(0.01,360.) * bj_DEGTORAD)
    local real y = GetUnitY(gg_unit_hfoo_0000) + 50. * Sin(GetRandomReal(0.01,360.) * bj_DEGTORAD)
    
    call SetUnitX(gg_unit_hfoo_0000,x)
    call SetUnitY(gg_unit_hfoo_0000,y)
endfunction

function InitTrig_Trigger takes nothing returns nothing
    local trigger t = CreateTrigger()
    
    call TriggerRegisterTimerEvent(t,2.,true)
    call TriggerAddAction(t,function action)
    
    set t = null
endfunction

Also about your value "6.28318530718", first of all the max numbers behind the comma are 8 (someone told me at least) and if I take the cos of your max value I never get to 1. When you take the cos of mine max value (360), I get 1 and this should be the plan.

Edit: Well Cos(0) = 1 too but when I would take Cos(359.99), my value is still above your max value, so your facing value ends to early.
 
Level 16
Joined
May 1, 2008
Messages
1,605
Well I would do it like this:
JASS:
    local real x = GetOrderPointX() + 300 * Cos(GetRandomReal(0.01,360.) * bj_DEGTORAD)
    local real y = GetOrderPointY() + 300 * Sin(GetRandomReal(0.01,360.) * bj_DEGTORAD)

and then you refer to it:
JASS:
call SetUnitX(UNIT,x)
call SetUnitY(UNIT,y)

..at least I! always did it like this and no one said something against it so far :eek:
 
Check this out.

The bug could occur because of the max 8 digits thing.

JASS:
function Move takes nothing returns nothing
    local real facing = GetRandomReal(0,6.2831853)
    call SetUnitX(Unit,GetOrderPointX() + 300 * Cos(facing))
    call SetUnitY(Unit,GetOrderPointY() + 300 * Sin(facing))
endfunction

Try this again. First it gets the random facing angle in radians, from 0 to 2 PI, then it uses that value with cos and sin functions. If it doesn't work as intended, you're doing something wrong.

Also, Dr. Boom, your script favors some angles over others, because you're using degrees. You also do not need to call the GetRandomReal function two times, not to mention your bj_DEGTORAD is outside the Sin and Cos functions, so it doesn't serve its purpose.
 
Level 16
Joined
May 1, 2008
Messages
1,605
I just make a fast-writing mistake so I edited it .. and since your editing your posts all the time, you should be careful if some other person do it too (so check it out now -..-)

I know the real value has more then 8 digits, but someone told me Warcraft 3 just handle up to 8
 
Last edited:
Level 16
Joined
May 1, 2008
Messages
1,605
Well I don't know math very well, but I thought like this:

1) The facing value (how ever we calculate them now) is one full circle (360°)
2) When I use your max possible value like: Cos(6.2831853) I only get 0.99399311 (rounded)
3) When I use my max possible value like: Cos(360.) I get 1.

4) Since Cos(0) = 1 too, I used this: Cos(359,99) and I get: 0,99999999 (rounded)

Since I'm not sure, how many digits after comma Warcraft 3 use for facing , I thought mine would be better =S

Edit 1: I just owned myself as I see .. what is the use of bj_DEGTORAD then? As more I think about it, as more I get confused, so I better stay out of this and HappyTauren just won it =S

Edit 2: Actually I'm not in mood to discuss now how much I waste (whatever), when I have 1 more local variable as you, but as I said, I always used this way, it always worked for me and no one said something so far.
But I'll remember your way for the future, because 1 local more is 1 local more!
 
Well I don't know math very well, but I thought like this:

1) The facing value (how ever we calculate them now) is one full circle (360°)
It is correct. However, the facing angle in wc3 is in degrees, EVERYTHING ELSE is in radians (yeah, great engine design, Blizzard).
2) When I use your max possible value like: Cos(6.2831853) I only get 0.99399311 (rounded)
3) When I use my max possible value like: Cos(360.) I get 1.
360 is 360 in radians, not degress. Look at this. Also, 0.99 is, when displayed on the trigonometric cirlcle, not much different than 1.00.
However, 360*bj_DEGTORAD turns those 360 into radians, into a number between 0 and 6.28blah blah, which is what wc3 uses for trigonometric functions.

4) Since Cos(0) = 1 too, I used this: Cos(359,99) and I get: 0,99999999 (rounded)
Already sort of answered this.
Since I'm not sure, how many digits after comma Warcraft 3 use for facing , I thought mine would be better =S

Yes, it is good you've pointed out the 8 digit problem.
Edit 1: I just owned myself as I see .. what is the use of bj_DEGTORAD then? As more I think about it, as more I get confused, so I better stay out of this and HappyTauren just won it =S
As I said, it converts degrees to radians, so you can use 180 * bj_DEGTORAD to convert 180 into 3.14 (which is PI).

Edit 2: Actually I'm not in mood to discuss now how much I waste (whatever), when I have 1 more local variable as you, but as I said, I always used this way, it always worked for me and no one said something so far.
Even if it works in some cases, in some it won't and you will beat your head why it is so, that's why I suggest you learn a bit of trigonometry to understand this easier :)
But I'll remember your way for the future, because 1 local more is 1 local more!
Yeah, since they are dynamically allocated in wc3, they are actually slower than globals.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Get a vector with 0Y and nX where n is the distance you want it offset.

Multiply this by a rotation matrix for the angle you want it rotated.

You then perform a translation on that to centre it where you want.
Sounds like it requires more operation than the current ones.
Perhaps your calculations gives exact coordinates, I think I'll stick to the current method.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
It optimizes to the same... Vector with only 1 cordinate means half the rotation matrix can be discarded. The translation matrix simplifies to vector addition.

It is just to show how simple it is to derive these things from matricies. You could add cool things like skew if you wanted with just an extra step.
 
Status
Not open for further replies.
Top