GetAngleBetweenLocations(location, location)

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

float GetAngleBetweenLocations(
    location lOne,
    location lTwo
);

Parameters

lOne

Location One

lTwo

Location Two


Description

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.

Calls
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)



Remarks

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.


Requirements

#include "x0_i0_position"

Version

1.61

See Also

functions: abs | acos | FloatToInt | GetDistanceBetweenLocations | GetPositionFromLocation | IntToFloat
categories: Area Functions | Miscellaneous Functions | Movement Functions


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