API for the geodesic routines in C. More...
Go to the source code of this file.
Classes | |
struct | geod_geodesic |
struct | geod_geodesicline |
struct | geod_polygon |
Macros | |
#define | GEODESIC_VERSION |
#define | GEODESIC_VERSION_MAJOR 1 |
#define | GEODESIC_VERSION_MINOR 49 |
#define | GEODESIC_VERSION_NUM(a, b, c) ((((a) * 10000 + (b)) * 100) + (c)) |
#define | GEODESIC_VERSION_PATCH 0 |
Enumerations | |
enum | geod_flags { GEOD_NOFLAGS = 0U, GEOD_ARCMODE = 1U<<0, GEOD_LONG_UNROLL = 1U<<15 } |
enum | geod_mask { GEOD_NONE = 0U, GEOD_LATITUDE = 1U<<7 | 0U, GEOD_LONGITUDE = 1U<<8 | 1U<<3, GEOD_AZIMUTH = 1U<<9 | 0U, GEOD_DISTANCE = 1U<<10 | 1U<<0, GEOD_DISTANCE_IN = 1U<<11 | 1U<<0 | 1U<<1, GEOD_REDUCEDLENGTH = 1U<<12 | 1U<<0 | 1U<<2, GEOD_GEODESICSCALE = 1U<<13 | 1U<<0 | 1U<<2, GEOD_AREA = 1U<<14 | 1U<<4, GEOD_ALL = 0x7F80U| 0x1FU } |
Functions | |
void | geod_direct (const struct geod_geodesic *g, double lat1, double lon1, double azi1, double s12, double *plat2, double *plon2, double *pazi2) |
void | geod_directline (struct geod_geodesicline *l, const struct geod_geodesic *g, double lat1, double lon1, double azi1, double s12, unsigned caps) |
double | geod_gendirect (const struct geod_geodesic *g, double lat1, double lon1, double azi1, unsigned flags, double s12_a12, double *plat2, double *plon2, double *pazi2, double *ps12, double *pm12, double *pM12, double *pM21, double *pS12) |
void | geod_gendirectline (struct geod_geodesicline *l, const struct geod_geodesic *g, double lat1, double lon1, double azi1, unsigned flags, double s12_a12, unsigned caps) |
double | geod_geninverse (const struct geod_geodesic *g, double lat1, double lon1, double lat2, double lon2, double *ps12, double *pazi1, double *pazi2, double *pm12, double *pM12, double *pM21, double *pS12) |
double | geod_genposition (const struct geod_geodesicline *l, unsigned flags, double s12_a12, double *plat2, double *plon2, double *pazi2, double *ps12, double *pm12, double *pM12, double *pM21, double *pS12) |
void | geod_gensetdistance (struct geod_geodesicline *l, unsigned flags, double s13_a13) |
void | geod_init (struct geod_geodesic *g, double a, double f) |
void | geod_inverse (const struct geod_geodesic *g, double lat1, double lon1, double lat2, double lon2, double *ps12, double *pazi1, double *pazi2) |
void | geod_inverseline (struct geod_geodesicline *l, const struct geod_geodesic *g, double lat1, double lon1, double lat2, double lon2, unsigned caps) |
void | geod_lineinit (struct geod_geodesicline *l, const struct geod_geodesic *g, double lat1, double lon1, double azi1, unsigned caps) |
void | geod_polygon_addedge (const struct geod_geodesic *g, struct geod_polygon *p, double azi, double s) |
void | geod_polygon_addpoint (const struct geod_geodesic *g, struct geod_polygon *p, double lat, double lon) |
void | geod_polygon_clear (struct geod_polygon *p) |
unsigned | geod_polygon_compute (const struct geod_geodesic *g, const struct geod_polygon *p, int reverse, int sign, double *pA, double *pP) |
void | geod_polygon_init (struct geod_polygon *p, int polylinep) |
unsigned | geod_polygon_testedge (const struct geod_geodesic *g, const struct geod_polygon *p, double azi, double s, int reverse, int sign, double *pA, double *pP) |
unsigned | geod_polygon_testpoint (const struct geod_geodesic *g, const struct geod_polygon *p, double lat, double lon, int reverse, int sign, double *pA, double *pP) |
void | geod_polygonarea (const struct geod_geodesic *g, double lats[], double lons[], int n, double *pA, double *pP) |
void | geod_position (const struct geod_geodesicline *l, double s12, double *plat2, double *plon2, double *pazi2) |
void | geod_setdistance (struct geod_geodesicline *l, double s13) |
API for the geodesic routines in C.
This an implementation in C of the geodesic algorithms described in
The principal advantages of these algorithms over previous ones (e.g., Vincenty, 1975) are
The shortest path between two points on the ellipsoid at (lat1, lon1) and (lat2, lon2) is called the geodesic. Its length is s12 and the geodesic from point 1 to point 2 has forward azimuths azi1 and azi2 at the two end points.
Traditionally two geodesic problems are considered:
The ellipsoid is specified by its equatorial radius a (typically in meters) and flattening f. The routines are accurate to round off with double precision arithmetic provided that |f| < 1/50; for the WGS84 ellipsoid, the errors are less than 15 nanometers. (Reasonably accurate results are obtained for |f| < 1/5.) For a prolate ellipsoid, specify f < 0.
The routines also calculate several other quantities of interest
If points 1, 2, and 3 lie on a single geodesic, then the following addition rules hold:
The shortest distance returned by the solution of the inverse problem is (obviously) uniquely defined. However, in a few special cases there are multiple azimuths which yield the same shortest distance. Here is a catalog of those cases:
These routines are a simple transcription of the corresponding C++ classes in GeographicLib. The "class data" is represented by the structs geod_geodesic, geod_geodesicline, geod_polygon and pointers to these objects are passed as initial arguments to the member functions. Most of the internal comments have been retained. However, in the process of transcription some documentation has been lost and the documentation for the C++ classes, GeographicLib::Geodesic, GeographicLib::GeodesicLine, and GeographicLib::PolygonAreaT, should be consulted. The C++ code remains the "reference implementation". Think twice about restructuring the internals of the C code since this may make porting fixes from the C++ code more difficult.
Copyright (c) Charles Karney (2012-2017) charl and licensed under the MIT/X11 License. For more information, see es@k arney .comhttps://geographiclib.sourceforge.io/
This library was distributed with GeographicLib 1.49.
Definition in file geodesic.h.
#define GEODESIC_VERSION |
The version of the geodesic library as a single integer, packed as MMmmmmpp where MM is the major version, mmmm is the minor version, and pp is the patch level. Users should not rely on this particular packing of the components of the version number. Instead they should use a test such as
Definition at line 155 of file geodesic.h.
#define GEODESIC_VERSION_MAJOR 1 |
The major version of the geodesic library. (This tracks the version of GeographicLib.)
Definition at line 125 of file geodesic.h.
#define GEODESIC_VERSION_MINOR 49 |
The minor version of the geodesic library. (This tracks the version of GeographicLib.)
Definition at line 130 of file geodesic.h.
Pack the version components into a single integer. Users should not rely on this particular packing of the components of the version number; see the documentation for GEODESIC_VERSION, below.
Definition at line 142 of file geodesic.h.
#define GEODESIC_VERSION_PATCH 0 |
The patch level of the geodesic library. (This tracks the version of GeographicLib.)
Definition at line 135 of file geodesic.h.
enum geod_flags |
flag values for the flags argument to geod_gendirect() and geod_genposition()
Enumerator | |
---|---|
GEOD_NOFLAGS | No flags |
GEOD_ARCMODE | Position given in terms of arc distance |
GEOD_LONG_UNROLL | Unroll the longitude |
Definition at line 900 of file geodesic.h.
enum geod_mask |
mask values for the caps argument to geod_lineinit().
Definition at line 883 of file geodesic.h.
void geod_direct | ( | const struct geod_geodesic * | g, |
double | lat1, | ||
double | lon1, | ||
double | azi1, | ||
double | s12, | ||
double * | plat2, | ||
double * | plon2, | ||
double * | pazi2 | ||
) |
Solve the direct geodesic problem.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | azi1 | azimuth at point 1 (degrees). |
[in] | s12 | distance from point 1 to point 2 (meters); it can be negative. |
[out] | plat2 | pointer to the latitude of point 2 (degrees). |
[out] | plon2 | pointer to the longitude of point 2 (degrees). |
[out] | pazi2 | pointer to the (forward) azimuth at point 2 (degrees). |
g must have been initialized with a call to geod_init(). lat1 should be in the range [−90°, 90°]. The values of lon2 and azi2 returned are in the range [−180°, 180°]. Any of the "return" arguments plat2, etc., may be replaced by 0, if you do not need some quantities computed.
If either point is at a pole, the azimuth is defined by keeping the longitude fixed, writing lat = ±(90° − ε), and taking the limit ε → 0+. An arc length greater that 180° signifies a geodesic which is not a shortest path. (For a prolate ellipsoid, an additional condition is necessary for a shortest path: the longitudinal extent must not exceed of 180°.)
Example, determine the point 10000 km NE of JFK:
void geod_directline | ( | struct geod_geodesicline * | l, |
const struct geod_geodesic * | g, | ||
double | lat1, | ||
double | lon1, | ||
double | azi1, | ||
double | s12, | ||
unsigned | caps | ||
) |
Initialize a geod_geodesicline object in terms of the direct geodesic problem.
[out] | l | a pointer to the object to be initialized. |
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | azi1 | azimuth at point 1 (degrees). |
[in] | s12 | distance from point 1 to point 2 (meters); it can be negative. |
[in] | caps | bitor'ed combination of geod_mask() values specifying the capabilities the geod_geodesicline object should possess, i.e., which quantities can be returned in calls to geod_position() and geod_genposition(). |
This function sets point 3 of the geod_geodesicline to correspond to point 2 of the direct geodesic problem. See geod_lineinit() for more information.
double geod_gendirect | ( | const struct geod_geodesic * | g, |
double | lat1, | ||
double | lon1, | ||
double | azi1, | ||
unsigned | flags, | ||
double | s12_a12, | ||
double * | plat2, | ||
double * | plon2, | ||
double * | pazi2, | ||
double * | ps12, | ||
double * | pm12, | ||
double * | pM12, | ||
double * | pM21, | ||
double * | pS12 | ||
) |
The general direct geodesic problem.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | azi1 | azimuth at point 1 (degrees). |
[in] | flags | bitor'ed combination of geod_flags(); flags & GEOD_ARCMODE determines the meaning of s12_a12 and flags & GEOD_LONG_UNROLL "unrolls" lon2. |
[in] | s12_a12 | if flags & GEOD_ARCMODE is 0, this is the distance from point 1 to point 2 (meters); otherwise it is the arc length from point 1 to point 2 (degrees); it can be negative. |
[out] | plat2 | pointer to the latitude of point 2 (degrees). |
[out] | plon2 | pointer to the longitude of point 2 (degrees). |
[out] | pazi2 | pointer to the (forward) azimuth at point 2 (degrees). |
[out] | ps12 | pointer to the distance from point 1 to point 2 (meters). |
[out] | pm12 | pointer to the reduced length of geodesic (meters). |
[out] | pM12 | pointer to the geodesic scale of point 2 relative to point 1 (dimensionless). |
[out] | pM21 | pointer to the geodesic scale of point 1 relative to point 2 (dimensionless). |
[out] | pS12 | pointer to the area under the geodesic (meters2). |
g must have been initialized with a call to geod_init(). lat1 should be in the range [−90°, 90°]. The function value a12 equals s12_a12 if flags & GEOD_ARCMODE. Any of the "return" arguments, plat2, etc., may be replaced by 0, if you do not need some quantities computed.
With flags & GEOD_LONG_UNROLL bit set, the longitude is "unrolled" so that the quantity lon2 − lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.
void geod_gendirectline | ( | struct geod_geodesicline * | l, |
const struct geod_geodesic * | g, | ||
double | lat1, | ||
double | lon1, | ||
double | azi1, | ||
unsigned | flags, | ||
double | s12_a12, | ||
unsigned | caps | ||
) |
Initialize a geod_geodesicline object in terms of the direct geodesic problem spacified in terms of either distance or arc length.
[out] | l | a pointer to the object to be initialized. |
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | azi1 | azimuth at point 1 (degrees). |
[in] | flags | either GEOD_NOFLAGS or GEOD_ARCMODE to determining the meaning of the s12_a12. |
[in] | s12_a12 | if flags = GEOD_NOFLAGS, this is the distance from point 1 to point 2 (meters); if flags = GEOD_ARCMODE, it is the arc length from point 1 to point 2 (degrees); it can be negative. |
[in] | caps | bitor'ed combination of geod_mask() values specifying the capabilities the geod_geodesicline object should possess, i.e., which quantities can be returned in calls to geod_position() and geod_genposition(). |
This function sets point 3 of the geod_geodesicline to correspond to point 2 of the direct geodesic problem. See geod_lineinit() for more information.
double geod_geninverse | ( | const struct geod_geodesic * | g, |
double | lat1, | ||
double | lon1, | ||
double | lat2, | ||
double | lon2, | ||
double * | ps12, | ||
double * | pazi1, | ||
double * | pazi2, | ||
double * | pm12, | ||
double * | pM12, | ||
double * | pM21, | ||
double * | pS12 | ||
) |
The general inverse geodesic calculation.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | lat2 | latitude of point 2 (degrees). |
[in] | lon2 | longitude of point 2 (degrees). |
[out] | ps12 | pointer to the distance from point 1 to point 2 (meters). |
[out] | pazi1 | pointer to the azimuth at point 1 (degrees). |
[out] | pazi2 | pointer to the (forward) azimuth at point 2 (degrees). |
[out] | pm12 | pointer to the reduced length of geodesic (meters). |
[out] | pM12 | pointer to the geodesic scale of point 2 relative to point 1 (dimensionless). |
[out] | pM21 | pointer to the geodesic scale of point 1 relative to point 2 (dimensionless). |
[out] | pS12 | pointer to the area under the geodesic (meters2). |
g must have been initialized with a call to geod_init(). lat1 and lat2 should be in the range [−90°, 90°]. Any of the "return" arguments ps12, etc., may be replaced by 0, if you do not need some quantities computed.
double geod_genposition | ( | const struct geod_geodesicline * | l, |
unsigned | flags, | ||
double | s12_a12, | ||
double * | plat2, | ||
double * | plon2, | ||
double * | pazi2, | ||
double * | ps12, | ||
double * | pm12, | ||
double * | pM12, | ||
double * | pM21, | ||
double * | pS12 | ||
) |
The general position function.
[in] | l | a pointer to the geod_geodesicline object specifying the geodesic line. |
[in] | flags | bitor'ed combination of geod_flags(); flags & GEOD_ARCMODE determines the meaning of s12_a12 and flags & GEOD_LONG_UNROLL "unrolls" lon2; if flags & GEOD_ARCMODE is 0, then l must have been initialized with caps |= GEOD_DISTANCE_IN. |
[in] | s12_a12 | if flags & GEOD_ARCMODE is 0, this is the distance from point 1 to point 2 (meters); otherwise it is the arc length from point 1 to point 2 (degrees); it can be negative. |
[out] | plat2 | pointer to the latitude of point 2 (degrees). |
[out] | plon2 | pointer to the longitude of point 2 (degrees); requires that l was initialized with caps |= GEOD_LONGITUDE. |
[out] | pazi2 | pointer to the (forward) azimuth at point 2 (degrees). |
[out] | ps12 | pointer to the distance from point 1 to point 2 (meters); requires that l was initialized with caps |= GEOD_DISTANCE. |
[out] | pm12 | pointer to the reduced length of geodesic (meters); requires that l was initialized with caps |= GEOD_REDUCEDLENGTH. |
[out] | pM12 | pointer to the geodesic scale of point 2 relative to point 1 (dimensionless); requires that l was initialized with caps |= GEOD_GEODESICSCALE. |
[out] | pM21 | pointer to the geodesic scale of point 1 relative to point 2 (dimensionless); requires that l was initialized with caps |= GEOD_GEODESICSCALE. |
[out] | pS12 | pointer to the area under the geodesic (meters2); requires that l was initialized with caps |= GEOD_AREA. |
l must have been initialized with a call to geod_lineinit() with caps |= GEOD_DISTANCE_IN. The value azi2 returned is in the range [−180°, 180°]. Any of the "return" arguments plat2, etc., may be replaced by 0, if you do not need some quantities computed. Requesting a value which l is not capable of computing is not an error; the corresponding argument will not be altered.
With flags & GEOD_LONG_UNROLL bit set, the longitude is "unrolled" so that the quantity lon2 − lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.
Example, compute way points between JFK and Singapore Changi Airport using geod_genposition(). In this example, the points are evenly space in arc length (and so only approximately equally spaced in distance). This is faster than using geod_position() and would be appropriate if drawing the path on a map.
void geod_gensetdistance | ( | struct geod_geodesicline * | l, |
unsigned | flags, | ||
double | s13_a13 | ||
) |
Specify position of point 3 in terms of either distance or arc length.
[in,out] | l | a pointer to the geod_geodesicline object. |
[in] | flags | either GEOD_NOFLAGS or GEOD_ARCMODE to determining the meaning of the s13_a13. |
[in] | s13_a13 | if flags = GEOD_NOFLAGS, this is the distance from point 1 to point 3 (meters); if flags = GEOD_ARCMODE, it is the arc length from point 1 to point 3 (degrees); it can be negative. |
If flags = GEOD_NOFLAGS, this calls geod_setdistance(). If flags = GEOD_ARCMODE, the s13 is only set if the geod_geodesicline object has been constructed with caps |= GEOD_DISTANCE.
void geod_init | ( | struct geod_geodesic * | g, |
double | a, | ||
double | f | ||
) |
Initialize a geod_geodesic object.
[out] | g | a pointer to the object to be initialized. |
[in] | a | the equatorial radius (meters). |
[in] | f | the flattening. |
void geod_inverse | ( | const struct geod_geodesic * | g, |
double | lat1, | ||
double | lon1, | ||
double | lat2, | ||
double | lon2, | ||
double * | ps12, | ||
double * | pazi1, | ||
double * | pazi2 | ||
) |
Solve the inverse geodesic problem.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | lat2 | latitude of point 2 (degrees). |
[in] | lon2 | longitude of point 2 (degrees). |
[out] | ps12 | pointer to the distance from point 1 to point 2 (meters). |
[out] | pazi1 | pointer to the azimuth at point 1 (degrees). |
[out] | pazi2 | pointer to the (forward) azimuth at point 2 (degrees). |
g must have been initialized with a call to geod_init(). lat1 and lat2 should be in the range [−90°, 90°]. The values of azi1 and azi2 returned are in the range [−180°, 180°]. Any of the "return" arguments, ps12, etc., may be replaced by 0, if you do not need some quantities computed.
If either point is at a pole, the azimuth is defined by keeping the longitude fixed, writing lat = ±(90° − ε), and taking the limit ε → 0+.
The solution to the inverse problem is found using Newton's method. If this fails to converge (this is very unlikely in geodetic applications but does occur for very eccentric ellipsoids), then the bisection method is used to refine the solution.
Example, determine the distance between JFK and Singapore Changi Airport:
void geod_inverseline | ( | struct geod_geodesicline * | l, |
const struct geod_geodesic * | g, | ||
double | lat1, | ||
double | lon1, | ||
double | lat2, | ||
double | lon2, | ||
unsigned | caps | ||
) |
Initialize a geod_geodesicline object in terms of the inverse geodesic problem.
[out] | l | a pointer to the object to be initialized. |
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | lat2 | latitude of point 2 (degrees). |
[in] | lon2 | longitude of point 2 (degrees). |
[in] | caps | bitor'ed combination of geod_mask() values specifying the capabilities the geod_geodesicline object should possess, i.e., which quantities can be returned in calls to geod_position() and geod_genposition(). |
This function sets point 3 of the geod_geodesicline to correspond to point 2 of the inverse geodesic problem. See geod_lineinit() for more information.
void geod_lineinit | ( | struct geod_geodesicline * | l, |
const struct geod_geodesic * | g, | ||
double | lat1, | ||
double | lon1, | ||
double | azi1, | ||
unsigned | caps | ||
) |
Initialize a geod_geodesicline object.
[out] | l | a pointer to the object to be initialized. |
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lat1 | latitude of point 1 (degrees). |
[in] | lon1 | longitude of point 1 (degrees). |
[in] | azi1 | azimuth at point 1 (degrees). |
[in] | caps | bitor'ed combination of geod_mask() values specifying the capabilities the geod_geodesicline object should possess, i.e., which quantities can be returned in calls to geod_position() and geod_genposition(). |
g must have been initialized with a call to geod_init(). lat1 should be in the range [−90°, 90°].
The geod_mask values are [see geod_mask()]:
A value of caps = 0 is treated as GEOD_LATITUDE | GEOD_LONGITUDE | GEOD_AZIMUTH | GEOD_DISTANCE_IN (to support the solution of the "standard" direct problem).
When initialized by this function, point 3 is undefined (l->s13 = l->a13 = NaN).
void geod_polygon_addedge | ( | const struct geod_geodesic * | g, |
struct geod_polygon * | p, | ||
double | azi, | ||
double | s | ||
) |
Add an edge to the polygon or polyline.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in,out] | p | a pointer to the geod_polygon object specifying the polygon. |
[in] | azi | azimuth at current point (degrees). |
[in] | s | distance from current point to next point (meters). |
g and p must have been initialized with calls to geod_init() and geod_polygon_init(), respectively. The same g must be used for all the points and edges in a polygon. This does nothing if no points have been added yet. The lat and lon fields of p give the location of the new vertex.
void geod_polygon_addpoint | ( | const struct geod_geodesic * | g, |
struct geod_polygon * | p, | ||
double | lat, | ||
double | lon | ||
) |
Add a point to the polygon or polyline.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in,out] | p | a pointer to the geod_polygon object specifying the polygon. |
[in] | lat | the latitude of the point (degrees). |
[in] | lon | the longitude of the point (degrees). |
g and p must have been initialized with calls to geod_init() and geod_polygon_init(), respectively. The same g must be used for all the points and edges in a polygon. lat should be in the range [−90°, 90°].
An example of the use of this function is given in the documentation for geod_polygon_compute().
void geod_polygon_clear | ( | struct geod_polygon * | p | ) |
Clear the polygon, allowing a new polygon to be started.
[in,out] | p | a pointer to the object to be cleared. |
unsigned geod_polygon_compute | ( | const struct geod_geodesic * | g, |
const struct geod_polygon * | p, | ||
int | reverse, | ||
int | sign, | ||
double * | pA, | ||
double * | pP | ||
) |
Return the results for a polygon.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | p | a pointer to the geod_polygon object specifying the polygon. |
[in] | reverse | if non-zero then clockwise (instead of counter-clockwise) traversal counts as a positive area. |
[in] | sign | if non-zero then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. |
[out] | pA | pointer to the area of the polygon (meters2); only set if polyline is non-zero in the call to geod_polygon_init(). |
[out] | pP | pointer to the perimeter of the polygon or length of the polyline (meters). |
The area and perimeter are accumulated at two times the standard floating point precision to guard against the loss of accuracy with many-sided polygons. Only simple polygons (which are not self-intersecting) are allowed. There's no need to "close" the polygon by repeating the first vertex. Set pA or pP to zero, if you do not want the corresponding quantity returned.
More points can be added to the polygon after this call.
Example, compute the perimeter and area of the geodesic triangle with vertices (0°N,0°E), (0°N,90°E), (90°N,0°E).
void geod_polygon_init | ( | struct geod_polygon * | p, |
int | polylinep | ||
) |
Initialize a geod_polygon object.
[out] | p | a pointer to the object to be initialized. |
[in] | polylinep | non-zero if a polyline instead of a polygon. |
If polylinep is zero, then the sequence of vertices and edges added by geod_polygon_addpoint() and geod_polygon_addedge() define a polygon and the perimeter and area are returned by geod_polygon_compute(). If polylinep is non-zero, then the vertices and edges define a polyline and only the perimeter is returned by geod_polygon_compute().
The area and perimeter are accumulated at two times the standard floating point precision to guard against the loss of accuracy with many-sided polygons. At any point you can ask for the perimeter and area so far.
An example of the use of this function is given in the documentation for geod_polygon_compute().
unsigned geod_polygon_testedge | ( | const struct geod_geodesic * | g, |
const struct geod_polygon * | p, | ||
double | azi, | ||
double | s, | ||
int | reverse, | ||
int | sign, | ||
double * | pA, | ||
double * | pP | ||
) |
Return the results assuming a tentative final test point is added via an azimuth and distance; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if geod_polygon_addedge() and geod_polygon_compute() are used.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | p | a pointer to the geod_polygon object specifying the polygon. |
[in] | azi | azimuth at current point (degrees). |
[in] | s | distance from current point to final test point (meters). |
[in] | reverse | if non-zero then clockwise (instead of counter-clockwise) traversal counts as a positive area. |
[in] | sign | if non-zero then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. |
[out] | pA | pointer to the area of the polygon (meters2); only set if polyline is non-zero in the call to geod_polygon_init(). |
[out] | pP | pointer to the perimeter of the polygon or length of the polyline (meters). |
unsigned geod_polygon_testpoint | ( | const struct geod_geodesic * | g, |
const struct geod_polygon * | p, | ||
double | lat, | ||
double | lon, | ||
int | reverse, | ||
int | sign, | ||
double * | pA, | ||
double * | pP | ||
) |
Return the results assuming a tentative final test point is added; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if geod_polygon_addpoint() and geod_polygon_compute() are used.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | p | a pointer to the geod_polygon object specifying the polygon. |
[in] | lat | the latitude of the test point (degrees). |
[in] | lon | the longitude of the test point (degrees). |
[in] | reverse | if non-zero then clockwise (instead of counter-clockwise) traversal counts as a positive area. |
[in] | sign | if non-zero then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. |
[out] | pA | pointer to the area of the polygon (meters2); only set if polyline is non-zero in the call to geod_polygon_init(). |
[out] | pP | pointer to the perimeter of the polygon or length of the polyline (meters). |
lat should be in the range [−90°, 90°].
void geod_polygonarea | ( | const struct geod_geodesic * | g, |
double | lats[], | ||
double | lons[], | ||
int | n, | ||
double * | pA, | ||
double * | pP | ||
) |
A simple interface for computing the area of a geodesic polygon.
[in] | g | a pointer to the geod_geodesic object specifying the ellipsoid. |
[in] | lats | an array of latitudes of the polygon vertices (degrees). |
[in] | lons | an array of longitudes of the polygon vertices (degrees). |
[in] | n | the number of vertices. |
[out] | pA | pointer to the area of the polygon (meters2). |
[out] | pP | pointer to the perimeter of the polygon (meters). |
lats should be in the range [−90°, 90°].
Only simple polygons (which are not self-intersecting) are allowed. There's no need to "close" the polygon by repeating the first vertex. The area returned is signed with counter-clockwise traversal being treated as positive.
Example, compute the area of Antarctica:
void geod_position | ( | const struct geod_geodesicline * | l, |
double | s12, | ||
double * | plat2, | ||
double * | plon2, | ||
double * | pazi2 | ||
) |
Compute the position along a geod_geodesicline.
[in] | l | a pointer to the geod_geodesicline object specifying the geodesic line. |
[in] | s12 | distance from point 1 to point 2 (meters); it can be negative. |
[out] | plat2 | pointer to the latitude of point 2 (degrees). |
[out] | plon2 | pointer to the longitude of point 2 (degrees); requires that l was initialized with caps |= GEOD_LONGITUDE. |
[out] | pazi2 | pointer to the (forward) azimuth at point 2 (degrees). |
l must have been initialized with a call, e.g., to geod_lineinit(), with caps |= GEOD_DISTANCE_IN. The values of lon2 and azi2 returned are in the range [−180°, 180°]. Any of the "return" arguments plat2, etc., may be replaced by 0, if you do not need some quantities computed.
Example, compute way points between JFK and Singapore Changi Airport the "obvious" way using geod_direct():
A faster way using geod_position():
void geod_setdistance | ( | struct geod_geodesicline * | l, |
double | s13 | ||
) |
Specify position of point 3 in terms of distance.
[in,out] | l | a pointer to the geod_geodesicline object. |
[in] | s13 | the distance from point 1 to point 3 (meters); it can be negative. |
This is only useful if the geod_geodesicline object has been constructed with caps |= GEOD_DISTANCE_IN.