Rhumb.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /**
  2. * \file Rhumb.hpp
  3. * \brief Header for GeographicLib::Rhumb and GeographicLib::RhumbLine classes
  4. *
  5. * Copyright (c) Charles Karney (2014-2021) <charles@karney.com> and licensed
  6. * under the MIT/X11 License. For more information, see
  7. * https://geographiclib.sourceforge.io/
  8. **********************************************************************/
  9. #if !defined(GEOGRAPHICLIB_RHUMB_HPP)
  10. #define GEOGRAPHICLIB_RHUMB_HPP 1
  11. #include <GeographicLib/Constants.hpp>
  12. #include <GeographicLib/Ellipsoid.hpp>
  13. #if !defined(GEOGRAPHICLIB_RHUMBAREA_ORDER)
  14. /**
  15. * The order of the series approximation used in rhumb area calculations.
  16. * GEOGRAPHICLIB_RHUMBAREA_ORDER can be set to any integer in [4, 8].
  17. **********************************************************************/
  18. # define GEOGRAPHICLIB_RHUMBAREA_ORDER \
  19. (GEOGRAPHICLIB_PRECISION == 2 ? 6 : \
  20. (GEOGRAPHICLIB_PRECISION == 1 ? 4 : 8))
  21. #endif
  22. namespace GeographicLib {
  23. class RhumbLine;
  24. template <class T> class PolygonAreaT;
  25. /**
  26. * \brief Solve of the direct and inverse rhumb problems.
  27. *
  28. * The path of constant azimuth between two points on a ellipsoid at (\e
  29. * lat1, \e lon1) and (\e lat2, \e lon2) is called the rhumb line (also
  30. * called the loxodrome). Its length is \e s12 and its azimuth is \e azi12.
  31. * (The azimuth is the heading measured clockwise from north.)
  32. *
  33. * Given \e lat1, \e lon1, \e azi12, and \e s12, we can determine \e lat2,
  34. * and \e lon2. This is the \e direct rhumb problem and its solution is
  35. * given by the function Rhumb::Direct.
  36. *
  37. * Given \e lat1, \e lon1, \e lat2, and \e lon2, we can determine \e azi12
  38. * and \e s12. This is the \e inverse rhumb problem, whose solution is given
  39. * by Rhumb::Inverse. This finds the shortest such rhumb line, i.e., the one
  40. * that wraps no more than half way around the earth. If the end points are
  41. * on opposite meridians, there are two shortest rhumb lines and the
  42. * east-going one is chosen.
  43. *
  44. * These routines also optionally calculate the area under the rhumb line, \e
  45. * S12. This is the area, measured counter-clockwise, of the rhumb line
  46. * quadrilateral with corners (<i>lat1</i>,<i>lon1</i>), (0,<i>lon1</i>),
  47. * (0,<i>lon2</i>), and (<i>lat2</i>,<i>lon2</i>).
  48. *
  49. * Note that rhumb lines may be appreciably longer (up to 50%) than the
  50. * corresponding Geodesic. For example the distance between London Heathrow
  51. * and Tokyo Narita via the rhumb line is 11400 km which is 18% longer than
  52. * the geodesic distance 9600 km.
  53. *
  54. * For more information on rhumb lines see \ref rhumb.
  55. *
  56. * Example of use:
  57. * \include example-Rhumb.cpp
  58. **********************************************************************/
  59. class GEOGRAPHICLIB_EXPORT Rhumb {
  60. private:
  61. typedef Math::real real;
  62. friend class RhumbLine;
  63. template <class T> friend class PolygonAreaT;
  64. Ellipsoid _ell;
  65. bool _exact;
  66. real _c2;
  67. static const int tm_maxord = GEOGRAPHICLIB_TRANSVERSEMERCATOR_ORDER;
  68. static const int maxpow_ = GEOGRAPHICLIB_RHUMBAREA_ORDER;
  69. // _R[0] unused
  70. real _R[maxpow_ + 1];
  71. static real gd(real x)
  72. { using std::atan; using std::sinh; return atan(sinh(x)); }
  73. // Use divided differences to determine (mu2 - mu1) / (psi2 - psi1)
  74. // accurately
  75. //
  76. // Definition: Df(x,y,d) = (f(x) - f(y)) / (x - y)
  77. // See:
  78. // W. M. Kahan and R. J. Fateman,
  79. // Symbolic computation of divided differences,
  80. // SIGSAM Bull. 33(3), 7-28 (1999)
  81. // https://doi.org/10.1145/334714.334716
  82. // http://www.cs.berkeley.edu/~fateman/papers/divdiff.pdf
  83. static real Dlog(real x, real y) {
  84. using std::sqrt; using std::asinh;
  85. real t = x - y;
  86. // Change
  87. //
  88. // atanh(t / (x + y))
  89. //
  90. // to
  91. //
  92. // asinh(t / (2 * sqrt(x*y)))
  93. //
  94. // to avoid taking atanh(1) when x is large and y is 1. N.B., this
  95. // routine is invoked with positive x and y, so no need to guard against
  96. // taking the sqrt of a negative quantity. This fixes bogus results for
  97. // the area being returning when an endpoint is at a pole.
  98. return t != 0 ? 2 * asinh(t / (2 * sqrt(x*y))) / t : 1 / x;
  99. }
  100. // N.B., x and y are in degrees
  101. static real Dtan(real x, real y) {
  102. real d = x - y, tx = Math::tand(x), ty = Math::tand(y), txy = tx * ty;
  103. return d != 0 ?
  104. (2 * txy > -1 ? (1 + txy) * Math::tand(d) : tx - ty) /
  105. (d * Math::degree()) :
  106. 1 + txy;
  107. }
  108. static real Datan(real x, real y) {
  109. using std::atan;
  110. real d = x - y, xy = x * y;
  111. return d != 0 ?
  112. (2 * xy > -1 ? atan( d / (1 + xy) ) : atan(x) - atan(y)) / d :
  113. 1 / (1 + xy);
  114. }
  115. static real Dsin(real x, real y) {
  116. using std::sin; using std::cos;
  117. real d = (x - y) / 2;
  118. return cos((x + y)/2) * (d != 0 ? sin(d) / d : 1);
  119. }
  120. static real Dsinh(real x, real y) {
  121. using std::sinh; using std::cosh;
  122. real d = (x - y) / 2;
  123. return cosh((x + y) / 2) * (d != 0 ? sinh(d) / d : 1);
  124. }
  125. static real Dcosh(real x, real y) {
  126. using std::sinh;
  127. real d = (x - y) / 2;
  128. return sinh((x + y) / 2) * (d != 0 ? sinh(d) / d : 1);
  129. }
  130. static real Dasinh(real x, real y) {
  131. using std::asinh; using std::hypot;
  132. real d = x - y,
  133. hx = hypot(real(1), x), hy = hypot(real(1), y);
  134. return d != 0 ?
  135. asinh(x*y > 0 ? d * (x + y) / (x*hy + y*hx) : x*hy - y*hx) / d :
  136. 1 / hx;
  137. }
  138. static real Dgd(real x, real y) {
  139. using std::sinh;
  140. return Datan(sinh(x), sinh(y)) * Dsinh(x, y);
  141. }
  142. // N.B., x and y are the tangents of the angles
  143. static real Dgdinv(real x, real y)
  144. { return Dasinh(x, y) / Datan(x, y); }
  145. // Copied from LambertConformalConic...
  146. // Deatanhe(x,y) = eatanhe((x-y)/(1-e^2*x*y))/(x-y)
  147. real Deatanhe(real x, real y) const {
  148. real t = x - y, d = 1 - _ell._e2 * x * y;
  149. return t != 0 ? Math::eatanhe(t / d, _ell._es) / t : _ell._e2 / d;
  150. }
  151. // (E(x) - E(y)) / (x - y) -- E = incomplete elliptic integral of 2nd kind
  152. real DE(real x, real y) const;
  153. // (mux - muy) / (phix - phiy) using elliptic integrals
  154. real DRectifying(real latx, real laty) const;
  155. // (psix - psiy) / (phix - phiy)
  156. real DIsometric(real latx, real laty) const;
  157. // (sum(c[j]*sin(2*j*x),j=1..n) - sum(c[j]*sin(2*j*x),j=1..n)) / (x - y)
  158. static real SinCosSeries(bool sinp,
  159. real x, real y, const real c[], int n);
  160. // (mux - muy) / (chix - chiy) using Krueger's series
  161. real DConformalToRectifying(real chix, real chiy) const;
  162. // (chix - chiy) / (mux - muy) using Krueger's series
  163. real DRectifyingToConformal(real mux, real muy) const;
  164. // (mux - muy) / (psix - psiy)
  165. // N.B., psix and psiy are in degrees
  166. real DIsometricToRectifying(real psix, real psiy) const;
  167. // (psix - psiy) / (mux - muy)
  168. real DRectifyingToIsometric(real mux, real muy) const;
  169. real MeanSinXi(real psi1, real psi2) const;
  170. // The following two functions (with lots of ignored arguments) mimic the
  171. // interface to the corresponding Geodesic function. These are needed by
  172. // PolygonAreaT.
  173. void GenDirect(real lat1, real lon1, real azi12,
  174. bool, real s12, unsigned outmask,
  175. real& lat2, real& lon2, real&, real&, real&, real&, real&,
  176. real& S12) const {
  177. GenDirect(lat1, lon1, azi12, s12, outmask, lat2, lon2, S12);
  178. }
  179. void GenInverse(real lat1, real lon1, real lat2, real lon2,
  180. unsigned outmask, real& s12, real& azi12,
  181. real&, real& , real& , real& , real& S12) const {
  182. GenInverse(lat1, lon1, lat2, lon2, outmask, s12, azi12, S12);
  183. }
  184. public:
  185. /**
  186. * Bit masks for what calculations to do. They specify which results to
  187. * return in the general routines Rhumb::GenDirect and Rhumb::GenInverse
  188. * routines. RhumbLine::mask is a duplication of this enum.
  189. **********************************************************************/
  190. enum mask {
  191. /**
  192. * No output.
  193. * @hideinitializer
  194. **********************************************************************/
  195. NONE = 0U,
  196. /**
  197. * Calculate latitude \e lat2.
  198. * @hideinitializer
  199. **********************************************************************/
  200. LATITUDE = 1U<<7,
  201. /**
  202. * Calculate longitude \e lon2.
  203. * @hideinitializer
  204. **********************************************************************/
  205. LONGITUDE = 1U<<8,
  206. /**
  207. * Calculate azimuth \e azi12.
  208. * @hideinitializer
  209. **********************************************************************/
  210. AZIMUTH = 1U<<9,
  211. /**
  212. * Calculate distance \e s12.
  213. * @hideinitializer
  214. **********************************************************************/
  215. DISTANCE = 1U<<10,
  216. /**
  217. * Calculate area \e S12.
  218. * @hideinitializer
  219. **********************************************************************/
  220. AREA = 1U<<14,
  221. /**
  222. * Unroll \e lon2 in the direct calculation.
  223. * @hideinitializer
  224. **********************************************************************/
  225. LONG_UNROLL = 1U<<15,
  226. /**
  227. * Calculate everything. (LONG_UNROLL is not included in this mask.)
  228. * @hideinitializer
  229. **********************************************************************/
  230. ALL = 0x7F80U,
  231. };
  232. /**
  233. * Constructor for a ellipsoid with
  234. *
  235. * @param[in] a equatorial radius (meters).
  236. * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
  237. * Negative \e f gives a prolate ellipsoid.
  238. * @param[in] exact if true (the default) use an addition theorem for
  239. * elliptic integrals to compute divided differences; otherwise use
  240. * series expansion (accurate for |<i>f</i>| < 0.01).
  241. * @exception GeographicErr if \e a or (1 &minus; \e f) \e a is not
  242. * positive.
  243. *
  244. * See \ref rhumb, for a detailed description of the \e exact parameter.
  245. **********************************************************************/
  246. Rhumb(real a, real f, bool exact = true);
  247. /**
  248. * Solve the direct rhumb problem returning also the area.
  249. *
  250. * @param[in] lat1 latitude of point 1 (degrees).
  251. * @param[in] lon1 longitude of point 1 (degrees).
  252. * @param[in] azi12 azimuth of the rhumb line (degrees).
  253. * @param[in] s12 distance between point 1 and point 2 (meters); it can be
  254. * negative.
  255. * @param[out] lat2 latitude of point 2 (degrees).
  256. * @param[out] lon2 longitude of point 2 (degrees).
  257. * @param[out] S12 area under the rhumb line (meters<sup>2</sup>).
  258. *
  259. * \e lat1 should be in the range [&minus;90&deg;, 90&deg;]. The value of
  260. * \e lon2 returned is in the range [&minus;180&deg;, 180&deg;].
  261. *
  262. * If point 1 is a pole, the cosine of its latitude is taken to be
  263. * 1/&epsilon;<sup>2</sup> (where &epsilon; is 2<sup>-52</sup>). This
  264. * position, which is extremely close to the actual pole, allows the
  265. * calculation to be carried out in finite terms. If \e s12 is large
  266. * enough that the rhumb line crosses a pole, the longitude of point 2
  267. * is indeterminate (a NaN is returned for \e lon2 and \e S12).
  268. **********************************************************************/
  269. void Direct(real lat1, real lon1, real azi12, real s12,
  270. real& lat2, real& lon2, real& S12) const {
  271. GenDirect(lat1, lon1, azi12, s12,
  272. LATITUDE | LONGITUDE | AREA, lat2, lon2, S12);
  273. }
  274. /**
  275. * Solve the direct rhumb problem without the area.
  276. **********************************************************************/
  277. void Direct(real lat1, real lon1, real azi12, real s12,
  278. real& lat2, real& lon2) const {
  279. real t;
  280. GenDirect(lat1, lon1, azi12, s12, LATITUDE | LONGITUDE, lat2, lon2, t);
  281. }
  282. /**
  283. * The general direct rhumb problem. Rhumb::Direct is defined in terms
  284. * of this function.
  285. *
  286. * @param[in] lat1 latitude of point 1 (degrees).
  287. * @param[in] lon1 longitude of point 1 (degrees).
  288. * @param[in] azi12 azimuth of the rhumb line (degrees).
  289. * @param[in] s12 distance between point 1 and point 2 (meters); it can be
  290. * negative.
  291. * @param[in] outmask a bitor'ed combination of Rhumb::mask values
  292. * specifying which of the following parameters should be set.
  293. * @param[out] lat2 latitude of point 2 (degrees).
  294. * @param[out] lon2 longitude of point 2 (degrees).
  295. * @param[out] S12 area under the rhumb line (meters<sup>2</sup>).
  296. *
  297. * The Rhumb::mask values possible for \e outmask are
  298. * - \e outmask |= Rhumb::LATITUDE for the latitude \e lat2;
  299. * - \e outmask |= Rhumb::LONGITUDE for the latitude \e lon2;
  300. * - \e outmask |= Rhumb::AREA for the area \e S12;
  301. * - \e outmask |= Rhumb::ALL for all of the above;
  302. * - \e outmask |= Rhumb::LONG_UNROLL to unroll \e lon2 instead of wrapping
  303. * it into the range [&minus;180&deg;, 180&deg;].
  304. * .
  305. * With the Rhumb::LONG_UNROLL bit set, the quantity \e lon2 &minus;
  306. * \e lon1 indicates how many times and in what sense the rhumb line
  307. * encircles the ellipsoid.
  308. **********************************************************************/
  309. void GenDirect(real lat1, real lon1, real azi12, real s12,
  310. unsigned outmask, real& lat2, real& lon2, real& S12) const;
  311. /**
  312. * Solve the inverse rhumb problem returning also the area.
  313. *
  314. * @param[in] lat1 latitude of point 1 (degrees).
  315. * @param[in] lon1 longitude of point 1 (degrees).
  316. * @param[in] lat2 latitude of point 2 (degrees).
  317. * @param[in] lon2 longitude of point 2 (degrees).
  318. * @param[out] s12 rhumb distance between point 1 and point 2 (meters).
  319. * @param[out] azi12 azimuth of the rhumb line (degrees).
  320. * @param[out] S12 area under the rhumb line (meters<sup>2</sup>).
  321. *
  322. * The shortest rhumb line is found. If the end points are on opposite
  323. * meridians, there are two shortest rhumb lines and the east-going one is
  324. * chosen. \e lat1 and \e lat2 should be in the range [&minus;90&deg;,
  325. * 90&deg;]. The value of \e azi12 returned is in the range
  326. * [&minus;180&deg;, 180&deg;].
  327. *
  328. * If either point is a pole, the cosine of its latitude is taken to be
  329. * 1/&epsilon;<sup>2</sup> (where &epsilon; is 2<sup>-52</sup>). This
  330. * position, which is extremely close to the actual pole, allows the
  331. * calculation to be carried out in finite terms.
  332. **********************************************************************/
  333. void Inverse(real lat1, real lon1, real lat2, real lon2,
  334. real& s12, real& azi12, real& S12) const {
  335. GenInverse(lat1, lon1, lat2, lon2,
  336. DISTANCE | AZIMUTH | AREA, s12, azi12, S12);
  337. }
  338. /**
  339. * Solve the inverse rhumb problem without the area.
  340. **********************************************************************/
  341. void Inverse(real lat1, real lon1, real lat2, real lon2,
  342. real& s12, real& azi12) const {
  343. real t;
  344. GenInverse(lat1, lon1, lat2, lon2, DISTANCE | AZIMUTH, s12, azi12, t);
  345. }
  346. /**
  347. * The general inverse rhumb problem. Rhumb::Inverse is defined in terms
  348. * of this function.
  349. *
  350. * @param[in] lat1 latitude of point 1 (degrees).
  351. * @param[in] lon1 longitude of point 1 (degrees).
  352. * @param[in] lat2 latitude of point 2 (degrees).
  353. * @param[in] lon2 longitude of point 2 (degrees).
  354. * @param[in] outmask a bitor'ed combination of Rhumb::mask values
  355. * specifying which of the following parameters should be set.
  356. * @param[out] s12 rhumb distance between point 1 and point 2 (meters).
  357. * @param[out] azi12 azimuth of the rhumb line (degrees).
  358. * @param[out] S12 area under the rhumb line (meters<sup>2</sup>).
  359. *
  360. * The Rhumb::mask values possible for \e outmask are
  361. * - \e outmask |= Rhumb::DISTANCE for the latitude \e s12;
  362. * - \e outmask |= Rhumb::AZIMUTH for the latitude \e azi12;
  363. * - \e outmask |= Rhumb::AREA for the area \e S12;
  364. * - \e outmask |= Rhumb::ALL for all of the above;
  365. **********************************************************************/
  366. void GenInverse(real lat1, real lon1, real lat2, real lon2,
  367. unsigned outmask,
  368. real& s12, real& azi12, real& S12) const;
  369. /**
  370. * Set up to compute several points on a single rhumb line.
  371. *
  372. * @param[in] lat1 latitude of point 1 (degrees).
  373. * @param[in] lon1 longitude of point 1 (degrees).
  374. * @param[in] azi12 azimuth of the rhumb line (degrees).
  375. * @return a RhumbLine object.
  376. *
  377. * \e lat1 should be in the range [&minus;90&deg;, 90&deg;].
  378. *
  379. * If point 1 is a pole, the cosine of its latitude is taken to be
  380. * 1/&epsilon;<sup>2</sup> (where &epsilon; is 2<sup>-52</sup>). This
  381. * position, which is extremely close to the actual pole, allows the
  382. * calculation to be carried out in finite terms.
  383. **********************************************************************/
  384. RhumbLine Line(real lat1, real lon1, real azi12) const;
  385. /** \name Inspector functions.
  386. **********************************************************************/
  387. ///@{
  388. /**
  389. * @return \e a the equatorial radius of the ellipsoid (meters). This is
  390. * the value used in the constructor.
  391. **********************************************************************/
  392. Math::real EquatorialRadius() const { return _ell.EquatorialRadius(); }
  393. /**
  394. * @return \e f the flattening of the ellipsoid. This is the
  395. * value used in the constructor.
  396. **********************************************************************/
  397. Math::real Flattening() const { return _ell.Flattening(); }
  398. /**
  399. * @return total area of ellipsoid in meters<sup>2</sup>. The area of a
  400. * polygon encircling a pole can be found by adding
  401. * Geodesic::EllipsoidArea()/2 to the sum of \e S12 for each side of the
  402. * polygon.
  403. **********************************************************************/
  404. Math::real EllipsoidArea() const { return _ell.Area(); }
  405. /**
  406. * \deprecated An old name for EquatorialRadius().
  407. **********************************************************************/
  408. GEOGRAPHICLIB_DEPRECATED("Use EquatorialRadius()")
  409. Math::real MajorRadius() const { return EquatorialRadius(); }
  410. ///@}
  411. /**
  412. * A global instantiation of Rhumb with the parameters for the WGS84
  413. * ellipsoid.
  414. **********************************************************************/
  415. static const Rhumb& WGS84();
  416. };
  417. /**
  418. * \brief Find a sequence of points on a single rhumb line.
  419. *
  420. * RhumbLine facilitates the determination of a series of points on a single
  421. * rhumb line. The starting point (\e lat1, \e lon1) and the azimuth \e
  422. * azi12 are specified in the call to Rhumb::Line which returns a RhumbLine
  423. * object. RhumbLine.Position returns the location of point 2 (and,
  424. * optionally, the corresponding area, \e S12) a distance \e s12 along the
  425. * rhumb line.
  426. *
  427. * There is no public constructor for this class. (Use Rhumb::Line to create
  428. * an instance.) The Rhumb object used to create a RhumbLine must stay in
  429. * scope as long as the RhumbLine.
  430. *
  431. * Example of use:
  432. * \include example-RhumbLine.cpp
  433. **********************************************************************/
  434. class GEOGRAPHICLIB_EXPORT RhumbLine {
  435. private:
  436. typedef Math::real real;
  437. friend class Rhumb;
  438. const Rhumb& _rh;
  439. bool _exact; // TODO: RhumbLine::_exact is unused; retire
  440. real _lat1, _lon1, _azi12, _salp, _calp, _mu1, _psi1, _r1;
  441. // copy assignment not allowed
  442. RhumbLine& operator=(const RhumbLine&) = delete;
  443. RhumbLine(const Rhumb& rh, real lat1, real lon1, real azi12,
  444. bool exact);
  445. public:
  446. /**
  447. * Construction is via default copy constructor.
  448. **********************************************************************/
  449. RhumbLine(const RhumbLine&) = default;
  450. /**
  451. * This is a duplication of Rhumb::mask.
  452. **********************************************************************/
  453. enum mask {
  454. /**
  455. * No output.
  456. * @hideinitializer
  457. **********************************************************************/
  458. NONE = Rhumb::NONE,
  459. /**
  460. * Calculate latitude \e lat2.
  461. * @hideinitializer
  462. **********************************************************************/
  463. LATITUDE = Rhumb::LATITUDE,
  464. /**
  465. * Calculate longitude \e lon2.
  466. * @hideinitializer
  467. **********************************************************************/
  468. LONGITUDE = Rhumb::LONGITUDE,
  469. /**
  470. * Calculate azimuth \e azi12.
  471. * @hideinitializer
  472. **********************************************************************/
  473. AZIMUTH = Rhumb::AZIMUTH,
  474. /**
  475. * Calculate distance \e s12.
  476. * @hideinitializer
  477. **********************************************************************/
  478. DISTANCE = Rhumb::DISTANCE,
  479. /**
  480. * Calculate area \e S12.
  481. * @hideinitializer
  482. **********************************************************************/
  483. AREA = Rhumb::AREA,
  484. /**
  485. * Unroll \e lon2 in the direct calculation.
  486. * @hideinitializer
  487. **********************************************************************/
  488. LONG_UNROLL = Rhumb::LONG_UNROLL,
  489. /**
  490. * Calculate everything. (LONG_UNROLL is not included in this mask.)
  491. * @hideinitializer
  492. **********************************************************************/
  493. ALL = Rhumb::ALL,
  494. };
  495. /**
  496. * Compute the position of point 2 which is a distance \e s12 (meters) from
  497. * point 1. The area is also computed.
  498. *
  499. * @param[in] s12 distance between point 1 and point 2 (meters); it can be
  500. * negative.
  501. * @param[out] lat2 latitude of point 2 (degrees).
  502. * @param[out] lon2 longitude of point 2 (degrees).
  503. * @param[out] S12 area under the rhumb line (meters<sup>2</sup>).
  504. *
  505. * The value of \e lon2 returned is in the range [&minus;180&deg;,
  506. * 180&deg;].
  507. *
  508. * If \e s12 is large enough that the rhumb line crosses a pole, the
  509. * longitude of point 2 is indeterminate (a NaN is returned for \e lon2 and
  510. * \e S12).
  511. **********************************************************************/
  512. void Position(real s12, real& lat2, real& lon2, real& S12) const {
  513. GenPosition(s12, LATITUDE | LONGITUDE | AREA, lat2, lon2, S12);
  514. }
  515. /**
  516. * Compute the position of point 2 which is a distance \e s12 (meters) from
  517. * point 1. The area is not computed.
  518. **********************************************************************/
  519. void Position(real s12, real& lat2, real& lon2) const {
  520. real t;
  521. GenPosition(s12, LATITUDE | LONGITUDE, lat2, lon2, t);
  522. }
  523. /**
  524. * The general position routine. RhumbLine::Position is defined in term so
  525. * this function.
  526. *
  527. * @param[in] s12 distance between point 1 and point 2 (meters); it can be
  528. * negative.
  529. * @param[in] outmask a bitor'ed combination of RhumbLine::mask values
  530. * specifying which of the following parameters should be set.
  531. * @param[out] lat2 latitude of point 2 (degrees).
  532. * @param[out] lon2 longitude of point 2 (degrees).
  533. * @param[out] S12 area under the rhumb line (meters<sup>2</sup>).
  534. *
  535. * The RhumbLine::mask values possible for \e outmask are
  536. * - \e outmask |= RhumbLine::LATITUDE for the latitude \e lat2;
  537. * - \e outmask |= RhumbLine::LONGITUDE for the latitude \e lon2;
  538. * - \e outmask |= RhumbLine::AREA for the area \e S12;
  539. * - \e outmask |= RhumbLine::ALL for all of the above;
  540. * - \e outmask |= RhumbLine::LONG_UNROLL to unroll \e lon2 instead of
  541. * wrapping it into the range [&minus;180&deg;, 180&deg;].
  542. * .
  543. * With the RhumbLine::LONG_UNROLL bit set, the quantity \e lon2 &minus; \e
  544. * lon1 indicates how many times and in what sense the rhumb line encircles
  545. * the ellipsoid.
  546. *
  547. * If \e s12 is large enough that the rhumb line crosses a pole, the
  548. * longitude of point 2 is indeterminate (a NaN is returned for \e lon2 and
  549. * \e S12).
  550. **********************************************************************/
  551. void GenPosition(real s12, unsigned outmask,
  552. real& lat2, real& lon2, real& S12) const;
  553. /** \name Inspector functions
  554. **********************************************************************/
  555. ///@{
  556. /**
  557. * @return \e lat1 the latitude of point 1 (degrees).
  558. **********************************************************************/
  559. Math::real Latitude() const { return _lat1; }
  560. /**
  561. * @return \e lon1 the longitude of point 1 (degrees).
  562. **********************************************************************/
  563. Math::real Longitude() const { return _lon1; }
  564. /**
  565. * @return \e azi12 the azimuth of the rhumb line (degrees).
  566. **********************************************************************/
  567. Math::real Azimuth() const { return _azi12; }
  568. /**
  569. * @return \e a the equatorial radius of the ellipsoid (meters). This is
  570. * the value inherited from the Rhumb object used in the constructor.
  571. **********************************************************************/
  572. Math::real EquatorialRadius() const { return _rh.EquatorialRadius(); }
  573. /**
  574. * @return \e f the flattening of the ellipsoid. This is the value
  575. * inherited from the Rhumb object used in the constructor.
  576. **********************************************************************/
  577. Math::real Flattening() const { return _rh.Flattening(); }
  578. };
  579. } // namespace GeographicLib
  580. #endif // GEOGRAPHICLIB_RHUMB_HPP