From NWN Lexicon
Revision as of 00:24, 26 August 2012 by Dood (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

GetAngleBetweenLocations(location, location)

Returns a float representing the angle between Location One and Location Two

float GetAngleBetweenLocations(
    location lOne,
    location lTwo



Location One


Location Two


This is a convenience function that returns a float representing the angle between lOne and lTwo. This is done by extracting the positions from lOne and lTwo, then getting the distance between the two locations. Then the absolute change in the x axis is calculated and the result is applied to acos(deltaX / distance). The result is a number who’s value represents the absolute bearing (where North=0) between the two locations.

int abs(int iNum)
float acos(float fNum)
int FloatToInt(float fNum)
float IntToFloat(int iNum)
vector GetPositionFromLocation(location loc)
float GetDistanceBetweenLocations(location lone, location lTwo)


This method may suffer from round-off error, in the line:
IntToFloat(abs(FloatToInt(vPos1.x - vPos2.x)))
When vPos2.x is subtracted from vPos1.x and there is no guarantee that (vPos1.x > vPos2.x) is true. This author has to wonder about the absence of a fAbs function that returns the absolute value of a float, baring that why not simply write the following check:
float fChangeX = vPos1.x – vPos2.x;
if (fChangeX < 0)
fChangeX = -fChangeX;
as was done in GetChangedPosition. But this is merely this writer’s opinion; the precision error however can be real.

Also remember, this requires the include file x0_i0_position.


#include " x0_i0_position "



See Also



 author: Michael Nork, editor: Jasperre, additional contributor(s): James E. King