[GRASSLIST:1507] RE: bearing/angle

David Finlayson dfinlays at u.washington.edu
Thu Oct 16 13:53:18 EDT 2003


F.Y.I.

Keep in mind that most computer languages have a special function called 
atan2(y, x) that was designed for this problem.  It takes care of the 
angle ambiguity when (y/x) == (-y/-x) or (-y/x) == (y/-x) and gets the 
quadrant right.

David Finlayson

Dan Gelinas wrote:

> Not sure if a COGO (coordinate Geometry) module is available for grass. It probably wouldn't be hard to add this to grass using c.
> The manual way to calculate bearing/angle is the following:
> Known information: Eastings/Northing x/y coordinates of your two points, for example, based on the first quadrant:
> a = 1.5, 1.4
> b = 4.1, 3.4
> 
> Distance ab is calculated:
> dx = xb - xa = 4.1 - 1.5 = 2.6
> dy = yb - ya = 3.4 - 1.4 = 2.0
> ab = sqrt(sqr2.6 + sqr2.0) = 3.28
> 
> Azimuth (@) is calculated as such:
> @AB = arc tg 2.6/2.0 = 52o26'
> 
> All other quadrants:
> First Quad:   dx:+  dy:+
> Second Quad:  dx:+  dy:-
> third Quad:   dx:-  dy:-
> Forth Quad:   dx:-  dy:+ 
> 
> -Daniel
> --------------------------------------------------------------------------
> Safe Software Q.A.         Safe Software Inc.               dg at safe.com
> Daniel Gelinas, P.Eng.     Surrey, BC, CANADA        phone: (604) 501-9985
> B. Appl. Sc. (Geomatics)  http://www.safe.com          fax: (604) 501-9965
>                       Solutions for Spatial Data
>                  Translation, Distribution and Access
> --------------------------------------------------------------------------
> 
> -----Original Message-----
> From: Christian G. Tveen [mailto:cgt at navicon.dk]
> Sent: Wednesday, October 15, 2003 3:41 AM
> To: GRASSLIST at baylor.edu
> Subject: [GRASSLIST:1496] bearing/angle
> 
> 
> Hello,
> 
> 
> 
> I need a way to calculate the bearing / angle between two points. To be 
> more precise, I need to know in what direction and how long to go from 
> one point to get to the other. I use the distance functionality to 
> calculate 'how long to go' but need the direction. Is there any 
> functions to do so ?  If this is not sufficient information, pls. don't 
> hesitate asking me.
> 
> 
> Regards
> 
> Christian G. Tveen
> 




More information about the grass-user mailing list