Skip to content

Wetitpig/geodesic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geodesic

Programs for calculating distance between coordinates.

Formula

Compilation

make
make clean

A binary will be located in ./bin directory (bin/geodesic).

Usage

geodesic [-i file] [-o file] [-k precision] [-p problem] [-f projection] [-s] [-a] [-h]

Computation Options

-p [direct|inverse|polygon] Solve direct problem or inverse problem.

  • Direct problem: Given a coordinate and a vector of distance and initial bearing, evaluate the destination coordinate and the final bearing.
  • Inverse problem: Given 2 coordinates, evaluate the distance, the initial bearing and the final bearing.
  • Polygon problem: Given a set of coordinates, evaluate the perimeter and area.

-f [sphere|ellipsoid|block] Select projection for evaluating the azimuths and distances.

  • Sphere projection employs the haversine algorithm and spherical triangle formula. Error is higher (error ~0.5%).
  • Ellipsoid projection employs the Vincenty's algorithm with modifications by Charles Karney. It is more resource-intensive (2x sphere projection).
  • Block projection means following parallels of latitude and meridians of longitude, assuming the Earth is an ellipsoid. For meridian arcs Bessel's series is implemented. All inputted coordinates should follow meridians of longitude and parallels of latitude.

-s Different computations for different problems.

  • Distance between coordinates for inverse problems.
  • The destination coordinate for direct problems.
  • The perimeter for polygon problems.

-a Different computations for different problems.

  • Initial and final bearings from one coordinate to the next for inverse problems.
  • The final bearing for direct problems.
  • The area for polygon problems.

IO Options

-i [FILE|-] Input file. - signifies standard in (stdin). Defaults to stdin without the option.

-o [FILE|-] Output file. - signifies standard out (stdout). Defaults to stdout without the option.

-k [integer] Set the number of decimal places in output. Default is 6.

Inverse problem

Arguments

Coordinates are given in the form of:

[coordinates1] [coordinates2] ... [coordinatesN], where each coordinate is in the form of latitude,longitude in decimals.

Output

[
  {
    "distance": xxx,
    "start_azimuth": xxx,
    "end_azimuth": xxx
  },
  {
    "distance": xxx,
    "start_azimuth": xxx,
    "end_azimuth": xxx
  },
  ...
  {
    "distance": xxx,
    "start_azimuth": xxx,
    "end_azimuth": xxx
  },
  {
    "total_distance": xxx
  }
]

Where each set of pairs in array specifies the following:

  • distance as the distance between the nth coordinate and the (n+1)th coordinate.
  • start_azimuth as the bearing at the nth coordinate, on the line from the nth coordinate to the (n+1)th coordinate.
  • end_azimuth as the bearing at the (n+1)th coordinate, on the line from the nth coordinate to the (n+1)th coordinate.

"total_distance" specifies the total distance of the line joining all coordinates.

Direct problem

Arguments

Vectors are given in the form of:

[start coordinate] [vector1] [vector2] ... [vectorN], where each vector is in the form of distance:bearing, in decimals and degrees respectively.

Output

[
  {
    "coordinate": [xxx,xxx],
    "azimuth": xxx
  },
  {
    "coordinate": [xxx,xxx],
    "azimuth": xxx
  },
  ...
  {
    "coordinate": [xxx,xxx],
    "azimuth": xxx
  }
]

Where each set of pairs in array specifies the following:

  • coordinate as the destination coordinate at the distance and bearing from the (n-1)th coordinate.
  • azimuth as the bearing at coordinate (nth coordinate), on the line from (n-1)th coordinate to nth coordinate.

Polygon problem

Arguments

Coordinates are given in the form of:

[coordinates1] [coordinates2] ... [coordinatesN] [coordinates1], where each coordinate is in the form of latitude,longitude in decimals.

Coordinates of a polygon should be specified in the counter-clockwise direction.

For polygons that include the poles, coordinates should be specified in the eastward direction for the North Pole, and the westward direction for the South Pole.

Note that coordinate1 must be placed at the end to close the polygon.

Output

{
  "perimeter": xxx,
  "area": xxx
}

Where

  • perimeter denotes the perimeter of the polygon.
  • area denotes the area of the polygon.

Units

  • All distances are provided in kilometres.
  • All areas are provided in square kilometres.
  • All angles are provided in degrees.
  • For latitudes, positive is assumed for north.
  • For longitudes, positive is assumed for east.
  • For bearings, full bearing must be used.

Notes

  • allow_nan should be set to true for parsing JSON, because azimuths may return a NaN value for zero vectors depending on the algorithm.

References

  1. Movable Type Scripts
  2. Vincenty's formulae @ Wikipedia
  3. Geodetic Inverse Solution between Antinodal Points
  4. Determination of areas on the plane, sphere and ellipsoid
  5. Geodesics on an ellipsoid of revolution
  6. Meridian arc @ Wikipedia
  7. Longitude @ Wikipedia

About

Program for calculating distance between coordinates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published