GeographicLib  1.43
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Friends | List of all members
GeographicLib::Rhumb Class Reference

Solve of the direct and inverse rhumb problems. More...

#include <GeographicLib/Rhumb.hpp>

Public Types

enum  mask {
  NONE, LATITUDE, LONGITUDE, AZIMUTH,
  DISTANCE, AREA, LONG_UNROLL, ALL
}
 

Public Member Functions

 Rhumb (real a, real f, bool exact=true)
 
void Direct (real lat1, real lon1, real azi12, real s12, real &lat2, real &lon2, real &S12) const
 
void Direct (real lat1, real lon1, real azi12, real s12, real &lat2, real &lon2) const
 
void GenDirect (real lat1, real lon1, real azi12, real s12, unsigned outmask, real &lat2, real &lon2, real &S12) const
 
void Inverse (real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12, real &S12) const
 
void Inverse (real lat1, real lon1, real lat2, real lon2, real &s12, real &azi12) const
 
void GenInverse (real lat1, real lon1, real lat2, real lon2, unsigned outmask, real &s12, real &azi12, real &S12) const
 
RhumbLine Line (real lat1, real lon1, real azi12) const
 

Friends

class RhumbLine
 
template<class T >
class PolygonAreaT
 

Inspector functions.

Math::real MajorRadius () const
 
Math::real Flattening () const
 
Math::real EllipsoidArea () const
 
static const RhumbWGS84 ()
 

Detailed Description

Solve of the direct and inverse rhumb problems.

The path of constant azimuth between two points on a ellipsoid at (lat1, lon1) and (lat2, lon2) is called the rhumb line (also called the loxodrome). Its length is s12 and its azimuth is azi12. (The azimuth is the heading measured clockwise from north.)

Given lat1, lon1, azi12, and s12, we can determine lat2, and lon2. This is the direct rhumb problem and its solution is given by the function Rhumb::Direct.

Given lat1, lon1, lat2, and lon2, we can determine azi12 and s12. This is the inverse rhumb problem, whose solution is given by Rhumb::Inverse. This finds the shortest such rhumb line, i.e., the one that wraps no more than half way around the earth. If the end points are on opposite meridians, there are two shortest rhumb lines and the east-going one is chosen.

These routines also optionally calculate the area under the rhumb line, S12. This is the area, measured counter-clockwise, of the rhumb line quadrilateral with corners (lat1,lon1), (0,lon1), (0,lon2), and (lat2,lon2).

Note that rhumb lines may be appreciably longer (up to 50%) than the corresponding Geodesic. For example the distance between London Heathrow and Tokyo Narita via the rhumb line is 11400 km which is 18% longer than the geodesic distance 9600 km.

For more information on rhumb lines see Rhumb lines.

Example of use:

// Example of using the GeographicLib::Rhumb class
#include <iostream>
#include <exception>
using namespace std;
using namespace GeographicLib;
int main() {
try {
// Alternatively: const Rhumb& rhumb = Rhumb::WGS84();
{
// Sample direct calculation, travelling about NE from JFK
double lat1 = 40.6, lon1 = -73.8, s12 = 5.5e6, azi12 = 51;
double lat2, lon2;
rhumb.Direct(lat1, lon1, azi12, s12, lat2, lon2);
cout << lat2 << " " << lon2 << "\n";
}
{
// Sample inverse calculation, JFK to LHR
double
lat1 = 40.6, lon1 = -73.8, // JFK Airport
lat2 = 51.6, lon2 = -0.5; // LHR Airport
double s12, azi12;
rhumb.Inverse(lat1, lon1, lat2, lon2, s12, azi12);
cout << s12 << " " << azi12 << "\n";
}
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
return 0;
}

Definition at line 66 of file Rhumb.hpp.

Member Enumeration Documentation

Bit masks for what calculations to do. They specify which results to return in the general routines Rhumb::GenDirect and Rhumb::GenInverse routines. RhumbLine::mask is a duplication of this enum.

Enumerator
NONE 

No output.

LATITUDE 

Calculate latitude lat2.

LONGITUDE 

Calculate longitude lon2.

AZIMUTH 

Calculate azimuth azi12.

DISTANCE 

Calculate distance s12.

AREA 

Calculate area S12.

LONG_UNROLL 

Unroll lon2 in the direct calculation. (This flag used to be called LONG_NOWRAP.)

ALL 

Calculate everything. (LONG_UNROLL is not included in this mask.)

Definition at line 189 of file Rhumb.hpp.

Constructor & Destructor Documentation

GeographicLib::Rhumb::Rhumb ( real  a,
real  f,
bool  exact = true 
)

Constructor for a ellipsoid with

Parameters
[in]aequatorial radius (meters).
[in]fflattening of ellipsoid. Setting f = 0 gives a sphere. Negative f gives a prolate ellipsoid. If f > 1, set flattening to 1/f.
[in]exactif true (the default) use an addition theorem for elliptic integrals to compute divided differences; otherwise use series expansion (accurate for |f| < 0.01).
Exceptions
GeographicErrif a or (1 − f) a is not positive.

See Rhumb lines, for a detailed description of the exact parameter.

Definition at line 18 of file Rhumb.cpp.

References GeographicLib::Math::polyval().

Member Function Documentation

void GeographicLib::Rhumb::Direct ( real  lat1,
real  lon1,
real  azi12,
real  s12,
real &  lat2,
real &  lon2,
real &  S12 
) const
inline

Solve the direct rhumb problem returning also the area.

Parameters
[in]lat1latitude of point 1 (degrees).
[in]lon1longitude of point 1 (degrees).
[in]azi12azimuth of the rhumb line (degrees).
[in]s12distance between point 1 and point 2 (meters); it can be negative.
[out]lat2latitude of point 2 (degrees).
[out]lon2longitude of point 2 (degrees).
[out]S12area under the rhumb line (meters2).

lat1 should be in the range [−90°, 90°]; lon1 and azi12 should be in the range [−540°, 540°). The value of lon2 returned is in the range [−180°, 180°).

If point 1 is a pole, the cosine of its latitude is taken to be 1/ε2 (where ε is 2-52). This position, which is extremely close to the actual pole, allows the calculation to be carried out in finite terms. If s12 is large enough that the rhumb line crosses a pole, the longitude of point 2 is indeterminate (a NaN is returned for lon2 and S12).

Definition at line 276 of file Rhumb.hpp.

Referenced by main().

void GeographicLib::Rhumb::Direct ( real  lat1,
real  lon1,
real  azi12,
real  s12,
real &  lat2,
real &  lon2 
) const
inline

Solve the direct rhumb problem without the area.

Definition at line 285 of file Rhumb.hpp.

void GeographicLib::Rhumb::GenDirect ( real  lat1,
real  lon1,
real  azi12,
real  s12,
unsigned  outmask,
real &  lat2,
real &  lon2,
real &  S12 
) const

The general direct rhumb problem. Rhumb::Direct is defined in terms of this function.

Parameters
[in]lat1latitude of point 1 (degrees).
[in]lon1longitude of point 1 (degrees).
[in]azi12azimuth of the rhumb line (degrees).
[in]s12distance between point 1 and point 2 (meters); it can be negative.
[in]outmaska bitor'ed combination of Rhumb::mask values specifying which of the following parameters should be set.
[out]lat2latitude of point 2 (degrees).
[out]lon2longitude of point 2 (degrees).
[out]S12area under the rhumb line (meters2).

The Rhumb::mask values possible for outmask are

With the Rhumb::LONG_UNROLL bit set, the quantity lon2lon1 indicates how many times and in what sense the rhumb line encircles the ellipsoid. Because lon2 might be outside the normal allowed range for longitudes, [−540°, 540°), be sure to normalize it with Math::AngNormalize2 before using it in other GeographicLib calls.

Definition at line 170 of file Rhumb.cpp.

References GeographicLib::RhumbLine::GenPosition(), and Line().

void GeographicLib::Rhumb::Inverse ( real  lat1,
real  lon1,
real  lat2,
real  lon2,
real &  s12,
real &  azi12,
real &  S12 
) const
inline

Solve the inverse rhumb problem returning also the area.

Parameters
[in]lat1latitude of point 1 (degrees).
[in]lon1longitude of point 1 (degrees).
[in]lat2latitude of point 2 (degrees).
[in]lon2longitude of point 2 (degrees).
[out]s12rhumb distance between point 1 and point 2 (meters).
[out]azi12azimuth of the rhumb line (degrees).
[out]S12area under the rhumb line (meters2).

The shortest rhumb line is found. If the end points are on opposite meridians, there are two shortest rhumb lines and the east-going one is chosen. lat1 and lat2 should be in the range [−90°, 90°]; lon1 and lon2 should be in the range [−540°, 540°). The value of azi12 returned is in the range [−180°, 180°).

If either point is a pole, the cosine of its latitude is taken to be 1/ε2 (where ε is 2-52). This position, which is extremely close to the actual pole, allows the calculation to be carried out in finite terms.

Definition at line 347 of file Rhumb.hpp.

Referenced by main().

void GeographicLib::Rhumb::Inverse ( real  lat1,
real  lon1,
real  lat2,
real  lon2,
real &  s12,
real &  azi12 
) const
inline

Solve the inverse rhumb problem without the area.

Definition at line 356 of file Rhumb.hpp.

void GeographicLib::Rhumb::GenInverse ( real  lat1,
real  lon1,
real  lat2,
real  lon2,
unsigned  outmask,
real &  s12,
real &  azi12,
real &  S12 
) const

The general inverse rhumb problem. Rhumb::Inverse is defined in terms of this function.

Parameters
[in]lat1latitude of point 1 (degrees).
[in]lon1longitude of point 1 (degrees).
[in]lat2latitude of point 2 (degrees).
[in]lon2longitude of point 2 (degrees).
[in]outmaska bitor'ed combination of Rhumb::mask values specifying which of the following parameters should be set.
[out]s12rhumb distance between point 1 and point 2 (meters).
[out]azi12azimuth of the rhumb line (degrees).
[out]S12area under the rhumb line (meters2).

The Rhumb::mask values possible for outmask are

Definition at line 147 of file Rhumb.cpp.

References GeographicLib::Math::AngDiff(), GeographicLib::Math::AngNormalize(), AREA, GeographicLib::Math::atan2d(), AZIMUTH, GeographicLib::Math::degree(), DISTANCE, GeographicLib::Math::hypot(), GeographicLib::Ellipsoid::IsometricLatitude(), and GeographicLib::Ellipsoid::QuarterMeridian().

RhumbLine GeographicLib::Rhumb::Line ( real  lat1,
real  lon1,
real  azi12 
) const

Set up to compute several points on a single rhumb line.

Parameters
[in]lat1latitude of point 1 (degrees).
[in]lon1longitude of point 1 (degrees).
[in]azi12azimuth of the rhumb line (degrees).
Returns
a RhumbLine object.

lat1 should be in the range [−90°, 90°]; lon1 and azi12 should be in the range [−540°, 540°).

If point 1 is a pole, the cosine of its latitude is taken to be 1/ε2 (where ε is 2-52). This position, which is extremely close to the actual pole, allows the calculation to be carried out in finite terms.

Definition at line 167 of file Rhumb.cpp.

References RhumbLine.

Referenced by GenDirect(), and main().

Math::real GeographicLib::Rhumb::MajorRadius ( ) const
inline
Returns
a the equatorial radius of the ellipsoid (meters). This is the value used in the constructor.

Definition at line 412 of file Rhumb.hpp.

Math::real GeographicLib::Rhumb::Flattening ( ) const
inline
Returns
f the flattening of the ellipsoid. This is the value used in the constructor.

Definition at line 418 of file Rhumb.hpp.

Math::real GeographicLib::Rhumb::EllipsoidArea ( ) const
inline

Definition at line 420 of file Rhumb.hpp.

const Rhumb & GeographicLib::Rhumb::WGS84 ( )
static

A global instantiation of Rhumb with the parameters for the WGS84 ellipsoid.

Definition at line 142 of file Rhumb.cpp.

References GeographicLib::Constants::WGS84_a(), and GeographicLib::Constants::WGS84_f().

Friends And Related Function Documentation

friend class RhumbLine
friend

Definition at line 69 of file Rhumb.hpp.

Referenced by Line().

template<class T >
friend class PolygonAreaT
friend

Definition at line 70 of file Rhumb.hpp.


The documentation for this class was generated from the following files: