[GRASS5] Angle of Line Function?

David D Gray ddgray at armadce.demon.co.uk
Sat Mar 10 16:10:34 EST 2001


Jeshua Lacock wrote:
> 
> Greetings,
> 
> I would greatly appreciate any help with developing a simple function
> that returns the angle (in degrees) of a line when given two points
> (x1, y1 and x2, y2).
> 
> Embarrassingly I have spent days trying to figure this out (that's
> what I get for using the teachers edition of geometry in high
> school!!).  ;->
> 
> I have ran across a function on the web, but somehow it seems really off:
>      angle = (((Atan((northingDifference/eastingDifference)))*180)/PI)
> 

Jeshua

This might give an answer in the wrong quadrant - only reliable if
between N -> E.

The atan2 function is a standard function to determine the value of the
angle and assign it to the correct quadrant by taking account of the
sign of the easting and northing offsets from the first point:

in degrees

angle = atan2( y2 - y1, x2 - x1 ) * 180 / M_PI    /* if math.h def'd */

The angle will be in standard mathematical format:

East = 0 --> (anticlockwise) --> North = 90 etc.

but you may want to use a different convention.

> The points that I am using are UTM coordinates.
> 

Above should be OK. Some uses may require a very small correction based
on considerations of the projection, but that would depend on the exact
problem.

David

---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list