## C# Geodesy Library for GPS – Vincenty’s Formulae

BitCoin tips graciously accepted at **1FB63FYQMy7hpC2ANVhZ5mSgAZEtY1aVLf**

Looking for the Java version of the Geodesy library? Click here.

**Read the related blog entry here.**

This will be handy for anyone, particularly Geocachers, interested in developing software for use with a GPS receiver. The library provides two important functions:

- Calculate a destination given a starting point, direction, and distance traveled on Earth
- Calculate the distance between two points on Earth

The fancy schmancy names for these functions are the “direct geodetic problem” and the “the inverse geodetic problem”.

For a deeper discussion of the source code, I recommend reading my blog entry: C#, GPS Receivers, and Geocaching: Vincenty’s Formula.

This is the C# source code for implementations of Thaddeus Vincenty’s algorithms to solve the direct and inverse geodetic problems.

The inputs for the direct solution are the latitude and longitude of a starting point, a starting bearing, a distance to travel, and a reference model of Earth (several are provided). The outputs are the latitude and longitude of the destination and, optionally, the final bearing at the destination.

The inputs for the inverse solution are the latitude and longitude of two points and a reference model of Earth (several are provided). The outputs are 1) the distance between the points along the curve of Earth, and 2) the direction from the starting point to the ending point.

The library has no dependencies on any other libraries.

The primary classes in the library are:

**Gavaghan.Geodesy (2-D calculations)
**

__ Angle__ – encapsulates latitude and longitude measurements in degrees while providing easy conversion to radians.

__ Ellipsoid__ – an immutable property class representing a model of Earth used for geodetic calculations. Several static instances are included that describe scientifically measured models. WGS84 (the 1984 World Geodetic System) and GRS80 (the 1980 Geodetic Reference System) are the most widely used.

__ GlobalCoordinates__ – encapsulates a location on Earth as described by two

`Angle`

s: latitude and longitude.__ GeodeticCurve__ – the outcome of an inverse geodetic calculation. It represents the path and ellipsoidal distance between two

`GlobalCoordinate`

s for a specified reference `Ellipsoid`

.__ GeodeticCalculator__ – this is a behavior class that contains the actual implementations of Vincenty’s Formulae.

**Gavaghan.Geodesy (3-D calculations)**

__ GlobalPosition__ – this is similar to

`GlobalCoordinates`

, but it also includes a measurement of elevation, in meters, above or below the reference `Ellipsoid`

.__ GeodeticMeasurement__ – this is similar to

`GeodeticCurve`

, but it also adds a point-to-point measurement which accounts for a change in elevation between two points in addition to the ellipsoidal distance.__ GeodeticCalculator__ – this is the same behavior class described above. It contains methods for both 2-D and 3-D calculations.

**Gavaghan.Geodesy.Example**

This is a console application project that sets up and computes a direct calculation and a 2-D and 3-D inverse calculation. This is a good starting point for figuring out how to use the library.

**Gavaghan.Geodesy.Test**

This is an NUnit project. Currently, there are not many tests. It is mostly geared toward ensuring that the canonicalization of `GlobalCoordinates`

behaves properly.

**Version History**

1.1.1 | Apr 15, 2008 | Fixed pole-crossing defect. Many thanks to Matt Feemster for finding this. |

1.1.0 | Jan 6, 2008 | Incorporated Vincenty’s direct solution. |