## Working with Angles

When working on directional geospatial data it is often useful to use a bearing (direction of travel). Although using the bearing is very helpful, it does pose a problem: what to do with North. I recently worked on a large project where I needed to determine average bearing of a vehicle at a specific location (the location would be repeated weekly).

If the vehicle repeatedly travels due North then the bearing reading that is taken will variously be just over 0 degrees or just under 360 degrees (either side of due North). The average of this would actually be due South, which is the polar opposite of the direction actually being travelled. This issue doesn’t only apply to premises that are exactly due North, but by any premises where the bearing of the truck occasionally crosses due North. For example, 350 degrees direction might occasionally has a value of 0-5 degrees.

I’ve come up with a way to resolve this by using “Angular Distance”. That is, instead of using bearing which comes back on itself, I’ve used the number of degrees away from North. This way NW would be 45 degrees, as would also be NE, meaning that a truck travelling due North would have an average Angular Distance from north of zero. Similar to a normal compass, South would also be 180 degrees. By doing this, we lose any ability to identify East/West travel, so a second angular distance is required, and I’ve chosen the distance from due East, where 0 is due east and 180 is due West.

Therefore, due north has a Northern Angular Distance Using these two angular distances the original bearing can be easily determined. For instance, an Angular Distance of 45 from North and 45 from East means the truck must be travelling NE. This type of information becomes essential to determining which side of the road a truck is collecting bins. Calculating the total change in bearing can be unintuitive. A change from NE (45 Degrees) to NW (315 Degrees) is a total angular distance of zero from North (as this is the angular distance, not angle). However, over this same change in bearing the angular distance from east is 90 Degrees (45 to 135). Therefore the actual net angular distance of to bearings is calculated by using the Bearing, not the angular distances.

Compass_Direction – Turns a standard bearing (such as 223) into a bearing (SW). The divisions are N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW

North_Distance – Provides the Northern Angular Distance from a bearing.

East_Distiance – Provides the Eastern Angular Distance from a bearing.

Angular_Distance - Given the North_Distance and East_Distance it returns the smallest angle between the two vectors.

I will post each of these functions seperately to aid finding them.

## Comments