[JASS]Getting Correct real Rotation

Status
Not open for further replies.

Furry Nova

Level 4
I've decided to start making my own spells in JASS. So far I'm creating spawn target points with Polar Offset based from the cast click point. I've followed this guide but it's a little difficult since I'm not very knowledgeable with geometry Math. So I'm taking it one step at a time.

This is my based understanding with the circle example so far that works.

JASS:
``````// PolarProjectionBJ(<location> Target, <real> Offset, <real> Direction) returns <location> Polar Offset Location
// I2R(<integer> Number) returns <real> Integer to Real
// CreateNUnitsAtLocFacingLocBJ(<integer> Create Number, <integer> Unit Type ID, <player> Owner, <location> Target, <location> Facing Target) returns <nothing>
set illusionLoc = PolarProjectionBJ(targetLoc, distance, (I2R(i) * (360.00 / l)))
call CreateNUnitsAtLocFacingLocBJ(1, uType, owner, illusionLoc, targetLoc)``````

I know 0 starts at East and there are 360 degrees in a circle. I want to find the value if I rotate by half. Say if value starts at 190 and I rotate by 180. This will result 370 but it's an overflow of the maximum possible result and should result in 10. Maybe if I reverse the direction by 180 from 170, it could result in 350 instead. Is there a easy function of way to safely get the correct rotation even if an overflow?

Example

JASS:
``````function getRotation takes real rotation returns real
// return correct rotation
endfunction``````

JASS:
``````local real start = 100.00
local real modify = start + 300.00
local real result = getRotation(modify) returns 40.00``````

WaterKnight

Level 26
`ModuloReal(val, 360)`

Not sure why you would need this though because all angle functions are periodic, so CosBJ(10) and CosBJ(370) yield the same. The native functions work in radians btw. 360° equals 2*pi

Furry Nova

Level 4
The spell I'm doing will spawn illusion in 2 certain points were the caster is facing. So the if I go under or over the degrees it will auto correct the value?

Dr Super Good

Spell Reviewer
Level 64
I know 0 starts at East and there are 360 degrees in a circle. I want to find the value if I rotate by half. Say if value starts at 190 and I rotate by 180. This will result 370 but it's an overflow of the maximum possible result and should result in 10. Maybe if I reverse the direction by 180 from 170, it could result in 350 instead. Is there a easy function of way to safely get the correct rotation even if an overflow?
The function is well defined for every angle. The cyclic nature of angles means that polar projection of 370 degrees produces approximately equal results to 10 degrees. Deviations in results would be due to rounding error, and should only really start being considerable if very large numbers are involved.

Status
Not open for further replies.

Replies
45
Views
2K
Replies
33
Views
2K
Replies
2
Views
516
Replies
3
Views
575
Replies
0
Views
695