Snippet GetPointInclination

Dirac

22710180
Reaction score
147
I don't know if this exists yet, but it's very useful and self explanatory
JASS:
library GetPointInclination /* v1.1.0

*/uses/*
*/  GetPointZ /* thehelper.net/forums/showthread.php/168825-GetPointZ

***********************************************************************
*
*   function GetPointInclinationX takes real x,real y returns real
*   function GetPointInclinationY takes real x,real y returns real
*       -   returns (in radians) angle between 0 and 90
*       -   If 0 then its flat, if 90 its a wall
*
*   function GetPointcGravityAngle takes real x, real y returns real
*       -   Returns (in radians) angle between 0 and 360.
*       -   The angle points towards lower terrain level from the
*       -   desired location
*
*   function IsPointInclined takes real x,real y returns boolean
*
**********************************************************************/

    globals
        private constant real TENDENCY=10
    endglobals
    
    function GetPointInclinationX takes real x,real y returns real
        return Atan((GetPointZ(x+TENDENCY,y)-GetPointZ(x-TENDENCY,y))/(TENDENCY*2))
    endfunction
    
    function GetPointInclinationY takes real x,real y returns real
        return Atan((GetPointZ(x,y+TENDENCY)-GetPointZ(x,y-TENDENCY))/(TENDENCY*2))
    endfunction
    
    function IsPointInclined takes real x,real y returns boolean
        return not(0==GetPointInclinationX(x,y)) or not(0==GetPointInclinationY(x,y))
    endfunction
    
    function GetPointGravityAngle takes real x, real y returns real
        return Atan2(-Sin(GetPointInclinationY(x,y)),-Sin(GetPointInclinationX(x,y)))
    endfunction
endlibrary

How does the system work, and what's that TENDENCY var inside it?:
This system evaluates 2 close points between the point you're evaluating, the distance of this points to your point is the TENDENCY, then the system compares the Z of these 2 points, and creates an angle between them, this angle it's the point's inclination.
If you're not familiar with trigonometry i suggest you to use GetPointGravityAngle because it's very user friendly.
 

luorax

Invasion in Duskwood
Reaction score
67
Actually you're leaking two location handle in both GetLocInclinationX and GetLocInclinationY functions.

Use a global location and [ljass]MoveLocation()[/ljass].
 

Dirac

22710180
Reaction score
147
Ty luorax, i never ever use locations, but in order to use getlocZ i must. Code updated
 

Dirac

22710180
Reaction score
147
In order to explain how does TENDENCY affects the code i must explain you how does the system works. But ok.

IMO TENDENCY should never be changed
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Code:
GetLocInclinationX(real x,real y)
    // returns (in radians) angle between 0 and 90
    // -If 0 then its flat, if 90 its a wall

If you plug for r (the height of the first point, say 3) and for l (the height of the second point, say 8) then
the atan(3 - 8) / 20 is not an angle between (0 and 90) because it's negative.

Shouldn't you calculate the angle between the two heights with abs(atan2(r - l, 10)) to get an angle between 0 and 90 in radians?

Why is the angle between the two heights calcualted with TENDENCY * 2? (atan(r - l, TENDENCY * 2)?

And what do you mean by "algorithmic concepts" in the "In order to understand GetLocGravityAngle you must know some algorithmic concepts"? Can you describe them?
 

Dirac

22710180
Reaction score
147
If you plug for r (the height of the first point, say 3) and for l (the height of the second point, say 8) then
the atan(3 - 8) / 20 is not an angle between (0 and 90) because it's negative.

Shouldn't you calculate the angle between the two heights with abs(atan2(r - l, 10)) to get an angle between 0 and 90 in radians?
this is correct, it returns an angle between -90 and 90, i just fixed that in the tooltip
Why is the angle between the two heights calcualted with TENDENCY * 2? (atan(r - l, TENDENCY * 2)?
I don't see why i should explain this, the system works fine, but ok
TENDENCY*2 is equal to the distance between the two points (left and right) or (up and down) from each other.
And what do you mean by "algorithmic concepts" in the "In order to understand GetLocGravityAngle you must know some algorithmic concepts"? Can you describe them?
Again i don't see a reason of why i should explain this, i already explained how TENDENCY works and how you should manipulate, anything else works fine according to your values
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
@Dirac: "TENDENCY*2 is equal to the distance between the two points (left and right) or (up and down) from each other."
A: haha yeah well it took me some time to heat up =)

@Dirac: "i don't see a reason of why i should explain this (algorithmic concepts), i already explained how TENDENCY works and how you should manipulate, anything else works fine according to your values "
A: Why wouldn't you explain how your own script works (given that you upload them for other users to use). Describing them with vague terms like "algorithmic concepts" doesn't really help (I'm sure you would agree). Deducting from the function's name GetLocGravityAngle,
I far as I know the acceleration due to gravity is always towards the center of the earth (so always 90 degrees/down [or 270 degrees depending how you look at it]), so does that mean that the angle this function returns is always 90 deg? (I think not.)

@Dirac: " -The angle points towards lower terrain *
* level from the desired location"
A: I really don't know what you mean with that. Can you give an example?

I am not saying that your script doesn't work, I just don't know how to use it (even after reading your description).
So that's why I'm "annoying" you to describe it in more familiar terms (give some examples etc.) / layman's terms.

Edit: wait does the GetLocationGravityAngle == GetLocInclination? (It seams like it). If so then why name it "GravityAngle"?
 

Dirac

22710180
Reaction score
147
wait does the GetLocationGravityAngle == GetLocInclination? (It seams like it). If so then why name it "GravityAngle"?
No.
Gravity Angle is a tool i added to return an angle that always points towards the lowest area of a terrain, suppose you'r unit is on a ramp, the angle returned would point towards the ramp's start at the lower terrain.

GetLocInclination works in a total different manner, it points an angle in a Z parameter, this angle points the difference between a flat floor (0 degrees) and the current inclination level, if your ramp has low elevation it should return something between 20 and 30 degrees, depending on the inclination of the ramp, if it's very steep then the angle would be around 50 and 70 degrees, remember always according the the ramp's inclination

EDIT: the explanations written above are not "how my system works" but most likely "what my system does". Explaining how it works is almost futile unless it aims for efficiency issues, and beyond luorax's correction i don't think there should be any
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
That's a very good idea, but who will use it?

You have to know some advanced physics :D
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
I asked you to explain what you meant by "algorithmic concepts" that's all.

So if "Gravity Angle is an angle that always points towards the lowest area of a terrain, suppose you'r unit is on a ramp, the angle returned would point towards the ramp's start at the lower terrain." doesn't hat mean that the "Gravity Angle" = Elevation Angle + 180? 180 deg = PI of course.
 

Dirac

22710180
Reaction score
147
doesn't hat mean that the "Gravity Angle" = Elevation Angle + 180? 180 deg = PI of course.
No. the gravity angle doesn't point to the ground, it points towards lowest place nearby. And i totally didn't get what you were trying to say

(side note) i didn't mean algorithmic, but trigonometric, sorry for the confusion

EDIT: didn't see your reply there.
That's a very good idea, but who will use it?

You have to know some advanced physics :D
actually no, maybe the inclination angles are complicated to use, but the Gravity angle is actually very user friendly, if you want a unit to move faster when walking downcliff, then move it periodically towards the GravityAngle.
 

tooltiperror

Super Moderator
Reaction score
231
Very nice. Periodically people need things like these, it's kind of like wanting a XOR or a Logarithm.

Approved.
 

Dirac

22710180
Reaction score
147
Updated to v1.1.0
-Change the API
-Uses GetPointZ now
-No locals.

I would like to change the title to GetPointInclination
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top