GeodesicLine.hpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /**
  2. * \file GeodesicLine.hpp
  3. * \brief Header for GeographicLib::GeodesicLine class
  4. *
  5. * Copyright (c) Charles Karney (2009-2020) <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_GEODESICLINE_HPP)
  10. #define GEOGRAPHICLIB_GEODESICLINE_HPP 1
  11. #include <GeographicLib/Constants.hpp>
  12. #include <GeographicLib/Geodesic.hpp>
  13. namespace GeographicLib {
  14. /**
  15. * \brief A geodesic line
  16. *
  17. * GeodesicLine facilitates the determination of a series of points on a
  18. * single geodesic. The starting point (\e lat1, \e lon1) and the azimuth \e
  19. * azi1 are specified in the constructor; alternatively, the Geodesic::Line
  20. * method can be used to create a GeodesicLine. GeodesicLine.Position
  21. * returns the location of point 2 a distance \e s12 along the geodesic. In
  22. * addition, GeodesicLine.ArcPosition gives the position of point 2 an arc
  23. * length \e a12 along the geodesic.
  24. *
  25. * You can register the position of a reference point 3 a distance (arc
  26. * length), \e s13 (\e a13) along the geodesic with the
  27. * GeodesicLine.SetDistance (GeodesicLine.SetArc) functions. Points a
  28. * fractional distance along the line can be found by providing, for example,
  29. * 0.5 * Distance() as an argument to GeodesicLine.Position. The
  30. * Geodesic::InverseLine or Geodesic::DirectLine methods return GeodesicLine
  31. * objects with point 3 set to the point 2 of the corresponding geodesic
  32. * problem. GeodesicLine objects created with the public constructor or with
  33. * Geodesic::Line have \e s13 and \e a13 set to NaNs.
  34. *
  35. * The default copy constructor and assignment operators work with this
  36. * class. Similarly, a vector can be used to hold GeodesicLine objects.
  37. *
  38. * The calculations are accurate to better than 15 nm (15 nanometers). See
  39. * Sec. 9 of
  40. * <a href="https://arxiv.org/abs/1102.1215v1">arXiv:1102.1215v1</a> for
  41. * details. The algorithms used by this class are based on series expansions
  42. * using the flattening \e f as a small parameter. These are only accurate
  43. * for |<i>f</i>| &lt; 0.02; however reasonably accurate results will be
  44. * obtained for |<i>f</i>| &lt; 0.2. For very eccentric ellipsoids, use
  45. * GeodesicLineExact instead.
  46. *
  47. * The algorithms are described in
  48. * - C. F. F. Karney,
  49. * <a href="https://doi.org/10.1007/s00190-012-0578-z">
  50. * Algorithms for geodesics</a>,
  51. * J. Geodesy <b>87</b>, 43--55 (2013);
  52. * DOI: <a href="https://doi.org/10.1007/s00190-012-0578-z">
  53. * 10.1007/s00190-012-0578-z</a>;
  54. * addenda:
  55. * <a href="https://geographiclib.sourceforge.io/geod-addenda.html">
  56. * geod-addenda.html</a>.
  57. * .
  58. * For more information on geodesics see \ref geodesic.
  59. *
  60. * Example of use:
  61. * \include example-GeodesicLine.cpp
  62. *
  63. * <a href="GeodSolve.1.html">GeodSolve</a> is a command-line utility
  64. * providing access to the functionality of Geodesic and GeodesicLine.
  65. **********************************************************************/
  66. class GEOGRAPHICLIB_EXPORT GeodesicLine {
  67. private:
  68. typedef Math::real real;
  69. friend class Geodesic;
  70. static const int nC1_ = Geodesic::nC1_;
  71. static const int nC1p_ = Geodesic::nC1p_;
  72. static const int nC2_ = Geodesic::nC2_;
  73. static const int nC3_ = Geodesic::nC3_;
  74. static const int nC4_ = Geodesic::nC4_;
  75. real tiny_;
  76. real _lat1, _lon1, _azi1;
  77. real _a, _f, _b, _c2, _f1, _salp0, _calp0, _k2,
  78. _salp1, _calp1, _ssig1, _csig1, _dn1, _stau1, _ctau1, _somg1, _comg1,
  79. _A1m1, _A2m1, _A3c, _B11, _B21, _B31, _A4, _B41;
  80. real _a13, _s13;
  81. // index zero elements of _C1a, _C1pa, _C2a, _C3a are unused
  82. real _C1a[nC1_ + 1], _C1pa[nC1p_ + 1], _C2a[nC2_ + 1], _C3a[nC3_],
  83. _C4a[nC4_]; // all the elements of _C4a are used
  84. unsigned _caps;
  85. void LineInit(const Geodesic& g,
  86. real lat1, real lon1,
  87. real azi1, real salp1, real calp1,
  88. unsigned caps);
  89. GeodesicLine(const Geodesic& g,
  90. real lat1, real lon1,
  91. real azi1, real salp1, real calp1,
  92. unsigned caps, bool arcmode, real s13_a13);
  93. enum captype {
  94. CAP_NONE = Geodesic::CAP_NONE,
  95. CAP_C1 = Geodesic::CAP_C1,
  96. CAP_C1p = Geodesic::CAP_C1p,
  97. CAP_C2 = Geodesic::CAP_C2,
  98. CAP_C3 = Geodesic::CAP_C3,
  99. CAP_C4 = Geodesic::CAP_C4,
  100. CAP_ALL = Geodesic::CAP_ALL,
  101. CAP_MASK = Geodesic::CAP_MASK,
  102. OUT_ALL = Geodesic::OUT_ALL,
  103. OUT_MASK = Geodesic::OUT_MASK,
  104. };
  105. public:
  106. /**
  107. * Bit masks for what calculations to do. They signify to the
  108. * GeodesicLine::GeodesicLine constructor and to Geodesic::Line what
  109. * capabilities should be included in the GeodesicLine object. This is
  110. * merely a duplication of Geodesic::mask.
  111. **********************************************************************/
  112. enum mask {
  113. /**
  114. * No capabilities, no output.
  115. * @hideinitializer
  116. **********************************************************************/
  117. NONE = Geodesic::NONE,
  118. /**
  119. * Calculate latitude \e lat2. (It's not necessary to include this as a
  120. * capability to GeodesicLine because this is included by default.)
  121. * @hideinitializer
  122. **********************************************************************/
  123. LATITUDE = Geodesic::LATITUDE,
  124. /**
  125. * Calculate longitude \e lon2.
  126. * @hideinitializer
  127. **********************************************************************/
  128. LONGITUDE = Geodesic::LONGITUDE,
  129. /**
  130. * Calculate azimuths \e azi1 and \e azi2. (It's not necessary to
  131. * include this as a capability to GeodesicLine because this is included
  132. * by default.)
  133. * @hideinitializer
  134. **********************************************************************/
  135. AZIMUTH = Geodesic::AZIMUTH,
  136. /**
  137. * Calculate distance \e s12.
  138. * @hideinitializer
  139. **********************************************************************/
  140. DISTANCE = Geodesic::DISTANCE,
  141. /**
  142. * Allow distance \e s12 to be used as input in the direct geodesic
  143. * problem.
  144. * @hideinitializer
  145. **********************************************************************/
  146. DISTANCE_IN = Geodesic::DISTANCE_IN,
  147. /**
  148. * Calculate reduced length \e m12.
  149. * @hideinitializer
  150. **********************************************************************/
  151. REDUCEDLENGTH = Geodesic::REDUCEDLENGTH,
  152. /**
  153. * Calculate geodesic scales \e M12 and \e M21.
  154. * @hideinitializer
  155. **********************************************************************/
  156. GEODESICSCALE = Geodesic::GEODESICSCALE,
  157. /**
  158. * Calculate area \e S12.
  159. * @hideinitializer
  160. **********************************************************************/
  161. AREA = Geodesic::AREA,
  162. /**
  163. * Unroll \e lon2 in the direct calculation.
  164. * @hideinitializer
  165. **********************************************************************/
  166. LONG_UNROLL = Geodesic::LONG_UNROLL,
  167. /**
  168. * All capabilities, calculate everything. (LONG_UNROLL is not
  169. * included in this mask.)
  170. * @hideinitializer
  171. **********************************************************************/
  172. ALL = Geodesic::ALL,
  173. };
  174. /** \name Constructors
  175. **********************************************************************/
  176. ///@{
  177. /**
  178. * Constructor for a geodesic line staring at latitude \e lat1, longitude
  179. * \e lon1, and azimuth \e azi1 (all in degrees).
  180. *
  181. * @param[in] g A Geodesic object used to compute the necessary information
  182. * about the GeodesicLine.
  183. * @param[in] lat1 latitude of point 1 (degrees).
  184. * @param[in] lon1 longitude of point 1 (degrees).
  185. * @param[in] azi1 azimuth at point 1 (degrees).
  186. * @param[in] caps bitor'ed combination of GeodesicLine::mask values
  187. * specifying the capabilities the GeodesicLine object should possess,
  188. * i.e., which quantities can be returned in calls to
  189. * GeodesicLine::Position.
  190. *
  191. * \e lat1 should be in the range [&minus;90&deg;, 90&deg;].
  192. *
  193. * The GeodesicLine::mask values are
  194. * - \e caps |= GeodesicLine::LATITUDE for the latitude \e lat2; this is
  195. * added automatically;
  196. * - \e caps |= GeodesicLine::LONGITUDE for the latitude \e lon2;
  197. * - \e caps |= GeodesicLine::AZIMUTH for the latitude \e azi2; this is
  198. * added automatically;
  199. * - \e caps |= GeodesicLine::DISTANCE for the distance \e s12;
  200. * - \e caps |= GeodesicLine::REDUCEDLENGTH for the reduced length \e m12;
  201. * - \e caps |= GeodesicLine::GEODESICSCALE for the geodesic scales \e M12
  202. * and \e M21;
  203. * - \e caps |= GeodesicLine::AREA for the area \e S12;
  204. * - \e caps |= GeodesicLine::DISTANCE_IN permits the length of the
  205. * geodesic to be given in terms of \e s12; without this capability the
  206. * length can only be specified in terms of arc length;
  207. * - \e caps |= GeodesicLine::ALL for all of the above.
  208. * .
  209. * The default value of \e caps is GeodesicLine::ALL.
  210. *
  211. * If the point is at a pole, the azimuth is defined by keeping \e lon1
  212. * fixed, writing \e lat1 = &plusmn;(90&deg; &minus; &epsilon;), and taking
  213. * the limit &epsilon; &rarr; 0+.
  214. **********************************************************************/
  215. GeodesicLine(const Geodesic& g, real lat1, real lon1, real azi1,
  216. unsigned caps = ALL);
  217. /**
  218. * A default constructor. If GeodesicLine::Position is called on the
  219. * resulting object, it returns immediately (without doing any
  220. * calculations). The object can be set with a call to Geodesic::Line.
  221. * Use Init() to test whether object is still in this uninitialized state.
  222. **********************************************************************/
  223. GeodesicLine() : _caps(0U) {}
  224. ///@}
  225. /** \name Position in terms of distance
  226. **********************************************************************/
  227. ///@{
  228. /**
  229. * Compute the position of point 2 which is a distance \e s12 (meters) from
  230. * point 1.
  231. *
  232. * @param[in] s12 distance from point 1 to point 2 (meters); it can be
  233. * negative.
  234. * @param[out] lat2 latitude of point 2 (degrees).
  235. * @param[out] lon2 longitude of point 2 (degrees); requires that the
  236. * GeodesicLine object was constructed with \e caps |=
  237. * GeodesicLine::LONGITUDE.
  238. * @param[out] azi2 (forward) azimuth at point 2 (degrees).
  239. * @param[out] m12 reduced length of geodesic (meters); requires that the
  240. * GeodesicLine object was constructed with \e caps |=
  241. * GeodesicLine::REDUCEDLENGTH.
  242. * @param[out] M12 geodesic scale of point 2 relative to point 1
  243. * (dimensionless); requires that the GeodesicLine object was constructed
  244. * with \e caps |= GeodesicLine::GEODESICSCALE.
  245. * @param[out] M21 geodesic scale of point 1 relative to point 2
  246. * (dimensionless); requires that the GeodesicLine object was constructed
  247. * with \e caps |= GeodesicLine::GEODESICSCALE.
  248. * @param[out] S12 area under the geodesic (meters<sup>2</sup>); requires
  249. * that the GeodesicLine object was constructed with \e caps |=
  250. * GeodesicLine::AREA.
  251. * @return \e a12 arc length from point 1 to point 2 (degrees).
  252. *
  253. * The values of \e lon2 and \e azi2 returned are in the range
  254. * [&minus;180&deg;, 180&deg;].
  255. *
  256. * The GeodesicLine object \e must have been constructed with \e caps |=
  257. * GeodesicLine::DISTANCE_IN; otherwise Math::NaN() is returned and no
  258. * parameters are set. Requesting a value which the GeodesicLine object is
  259. * not capable of computing is not an error; the corresponding argument
  260. * will not be altered.
  261. *
  262. * The following functions are overloaded versions of
  263. * GeodesicLine::Position which omit some of the output parameters. Note,
  264. * however, that the arc length is always computed and returned as the
  265. * function value.
  266. **********************************************************************/
  267. Math::real Position(real s12,
  268. real& lat2, real& lon2, real& azi2,
  269. real& m12, real& M12, real& M21,
  270. real& S12) const {
  271. real t;
  272. return GenPosition(false, s12,
  273. LATITUDE | LONGITUDE | AZIMUTH |
  274. REDUCEDLENGTH | GEODESICSCALE | AREA,
  275. lat2, lon2, azi2, t, m12, M12, M21, S12);
  276. }
  277. /**
  278. * See the documentation for GeodesicLine::Position.
  279. **********************************************************************/
  280. Math::real Position(real s12, real& lat2, real& lon2) const {
  281. real t;
  282. return GenPosition(false, s12,
  283. LATITUDE | LONGITUDE,
  284. lat2, lon2, t, t, t, t, t, t);
  285. }
  286. /**
  287. * See the documentation for GeodesicLine::Position.
  288. **********************************************************************/
  289. Math::real Position(real s12, real& lat2, real& lon2,
  290. real& azi2) const {
  291. real t;
  292. return GenPosition(false, s12,
  293. LATITUDE | LONGITUDE | AZIMUTH,
  294. lat2, lon2, azi2, t, t, t, t, t);
  295. }
  296. /**
  297. * See the documentation for GeodesicLine::Position.
  298. **********************************************************************/
  299. Math::real Position(real s12, real& lat2, real& lon2,
  300. real& azi2, real& m12) const {
  301. real t;
  302. return GenPosition(false, s12,
  303. LATITUDE | LONGITUDE |
  304. AZIMUTH | REDUCEDLENGTH,
  305. lat2, lon2, azi2, t, m12, t, t, t);
  306. }
  307. /**
  308. * See the documentation for GeodesicLine::Position.
  309. **********************************************************************/
  310. Math::real Position(real s12, real& lat2, real& lon2,
  311. real& azi2, real& M12, real& M21)
  312. const {
  313. real t;
  314. return GenPosition(false, s12,
  315. LATITUDE | LONGITUDE |
  316. AZIMUTH | GEODESICSCALE,
  317. lat2, lon2, azi2, t, t, M12, M21, t);
  318. }
  319. /**
  320. * See the documentation for GeodesicLine::Position.
  321. **********************************************************************/
  322. Math::real Position(real s12,
  323. real& lat2, real& lon2, real& azi2,
  324. real& m12, real& M12, real& M21)
  325. const {
  326. real t;
  327. return GenPosition(false, s12,
  328. LATITUDE | LONGITUDE | AZIMUTH |
  329. REDUCEDLENGTH | GEODESICSCALE,
  330. lat2, lon2, azi2, t, m12, M12, M21, t);
  331. }
  332. ///@}
  333. /** \name Position in terms of arc length
  334. **********************************************************************/
  335. ///@{
  336. /**
  337. * Compute the position of point 2 which is an arc length \e a12 (degrees)
  338. * from point 1.
  339. *
  340. * @param[in] a12 arc length from point 1 to point 2 (degrees); it can
  341. * be negative.
  342. * @param[out] lat2 latitude of point 2 (degrees).
  343. * @param[out] lon2 longitude of point 2 (degrees); requires that the
  344. * GeodesicLine object was constructed with \e caps |=
  345. * GeodesicLine::LONGITUDE.
  346. * @param[out] azi2 (forward) azimuth at point 2 (degrees).
  347. * @param[out] s12 distance from point 1 to point 2 (meters); requires
  348. * that the GeodesicLine object was constructed with \e caps |=
  349. * GeodesicLine::DISTANCE.
  350. * @param[out] m12 reduced length of geodesic (meters); requires that the
  351. * GeodesicLine object was constructed with \e caps |=
  352. * GeodesicLine::REDUCEDLENGTH.
  353. * @param[out] M12 geodesic scale of point 2 relative to point 1
  354. * (dimensionless); requires that the GeodesicLine object was constructed
  355. * with \e caps |= GeodesicLine::GEODESICSCALE.
  356. * @param[out] M21 geodesic scale of point 1 relative to point 2
  357. * (dimensionless); requires that the GeodesicLine object was constructed
  358. * with \e caps |= GeodesicLine::GEODESICSCALE.
  359. * @param[out] S12 area under the geodesic (meters<sup>2</sup>); requires
  360. * that the GeodesicLine object was constructed with \e caps |=
  361. * GeodesicLine::AREA.
  362. *
  363. * The values of \e lon2 and \e azi2 returned are in the range
  364. * [&minus;180&deg;, 180&deg;].
  365. *
  366. * Requesting a value which the GeodesicLine object is not capable of
  367. * computing is not an error; the corresponding argument will not be
  368. * altered.
  369. *
  370. * The following functions are overloaded versions of
  371. * GeodesicLine::ArcPosition which omit some of the output parameters.
  372. **********************************************************************/
  373. void ArcPosition(real a12, real& lat2, real& lon2, real& azi2,
  374. real& s12, real& m12, real& M12, real& M21,
  375. real& S12) const {
  376. GenPosition(true, a12,
  377. LATITUDE | LONGITUDE | AZIMUTH | DISTANCE |
  378. REDUCEDLENGTH | GEODESICSCALE | AREA,
  379. lat2, lon2, azi2, s12, m12, M12, M21, S12);
  380. }
  381. /**
  382. * See the documentation for GeodesicLine::ArcPosition.
  383. **********************************************************************/
  384. void ArcPosition(real a12, real& lat2, real& lon2)
  385. const {
  386. real t;
  387. GenPosition(true, a12,
  388. LATITUDE | LONGITUDE,
  389. lat2, lon2, t, t, t, t, t, t);
  390. }
  391. /**
  392. * See the documentation for GeodesicLine::ArcPosition.
  393. **********************************************************************/
  394. void ArcPosition(real a12,
  395. real& lat2, real& lon2, real& azi2)
  396. const {
  397. real t;
  398. GenPosition(true, a12,
  399. LATITUDE | LONGITUDE | AZIMUTH,
  400. lat2, lon2, azi2, t, t, t, t, t);
  401. }
  402. /**
  403. * See the documentation for GeodesicLine::ArcPosition.
  404. **********************************************************************/
  405. void ArcPosition(real a12, real& lat2, real& lon2, real& azi2,
  406. real& s12) const {
  407. real t;
  408. GenPosition(true, a12,
  409. LATITUDE | LONGITUDE | AZIMUTH | DISTANCE,
  410. lat2, lon2, azi2, s12, t, t, t, t);
  411. }
  412. /**
  413. * See the documentation for GeodesicLine::ArcPosition.
  414. **********************************************************************/
  415. void ArcPosition(real a12, real& lat2, real& lon2, real& azi2,
  416. real& s12, real& m12) const {
  417. real t;
  418. GenPosition(true, a12,
  419. LATITUDE | LONGITUDE | AZIMUTH |
  420. DISTANCE | REDUCEDLENGTH,
  421. lat2, lon2, azi2, s12, m12, t, t, t);
  422. }
  423. /**
  424. * See the documentation for GeodesicLine::ArcPosition.
  425. **********************************************************************/
  426. void ArcPosition(real a12, real& lat2, real& lon2, real& azi2,
  427. real& s12, real& M12, real& M21)
  428. const {
  429. real t;
  430. GenPosition(true, a12,
  431. LATITUDE | LONGITUDE | AZIMUTH |
  432. DISTANCE | GEODESICSCALE,
  433. lat2, lon2, azi2, s12, t, M12, M21, t);
  434. }
  435. /**
  436. * See the documentation for GeodesicLine::ArcPosition.
  437. **********************************************************************/
  438. void ArcPosition(real a12, real& lat2, real& lon2, real& azi2,
  439. real& s12, real& m12, real& M12, real& M21)
  440. const {
  441. real t;
  442. GenPosition(true, a12,
  443. LATITUDE | LONGITUDE | AZIMUTH |
  444. DISTANCE | REDUCEDLENGTH | GEODESICSCALE,
  445. lat2, lon2, azi2, s12, m12, M12, M21, t);
  446. }
  447. ///@}
  448. /** \name The general position function.
  449. **********************************************************************/
  450. ///@{
  451. /**
  452. * The general position function. GeodesicLine::Position and
  453. * GeodesicLine::ArcPosition are defined in terms of this function.
  454. *
  455. * @param[in] arcmode boolean flag determining the meaning of the second
  456. * parameter; if \e arcmode is false, then the GeodesicLine object must
  457. * have been constructed with \e caps |= GeodesicLine::DISTANCE_IN.
  458. * @param[in] s12_a12 if \e arcmode is false, this is the distance between
  459. * point 1 and point 2 (meters); otherwise it is the arc length between
  460. * point 1 and point 2 (degrees); it can be negative.
  461. * @param[in] outmask a bitor'ed combination of GeodesicLine::mask values
  462. * specifying which of the following parameters should be set.
  463. * @param[out] lat2 latitude of point 2 (degrees).
  464. * @param[out] lon2 longitude of point 2 (degrees); requires that the
  465. * GeodesicLine object was constructed with \e caps |=
  466. * GeodesicLine::LONGITUDE.
  467. * @param[out] azi2 (forward) azimuth at point 2 (degrees).
  468. * @param[out] s12 distance from point 1 to point 2 (meters); requires
  469. * that the GeodesicLine object was constructed with \e caps |=
  470. * GeodesicLine::DISTANCE.
  471. * @param[out] m12 reduced length of geodesic (meters); requires that the
  472. * GeodesicLine object was constructed with \e caps |=
  473. * GeodesicLine::REDUCEDLENGTH.
  474. * @param[out] M12 geodesic scale of point 2 relative to point 1
  475. * (dimensionless); requires that the GeodesicLine object was constructed
  476. * with \e caps |= GeodesicLine::GEODESICSCALE.
  477. * @param[out] M21 geodesic scale of point 1 relative to point 2
  478. * (dimensionless); requires that the GeodesicLine object was constructed
  479. * with \e caps |= GeodesicLine::GEODESICSCALE.
  480. * @param[out] S12 area under the geodesic (meters<sup>2</sup>); requires
  481. * that the GeodesicLine object was constructed with \e caps |=
  482. * GeodesicLine::AREA.
  483. * @return \e a12 arc length from point 1 to point 2 (degrees).
  484. *
  485. * The GeodesicLine::mask values possible for \e outmask are
  486. * - \e outmask |= GeodesicLine::LATITUDE for the latitude \e lat2;
  487. * - \e outmask |= GeodesicLine::LONGITUDE for the latitude \e lon2;
  488. * - \e outmask |= GeodesicLine::AZIMUTH for the latitude \e azi2;
  489. * - \e outmask |= GeodesicLine::DISTANCE for the distance \e s12;
  490. * - \e outmask |= GeodesicLine::REDUCEDLENGTH for the reduced length \e
  491. * m12;
  492. * - \e outmask |= GeodesicLine::GEODESICSCALE for the geodesic scales \e
  493. * M12 and \e M21;
  494. * - \e outmask |= GeodesicLine::AREA for the area \e S12;
  495. * - \e outmask |= GeodesicLine::ALL for all of the above;
  496. * - \e outmask |= GeodesicLine::LONG_UNROLL to unroll \e lon2 instead of
  497. * reducing it into the range [&minus;180&deg;, 180&deg;].
  498. * .
  499. * Requesting a value which the GeodesicLine object is not capable of
  500. * computing is not an error; the corresponding argument will not be
  501. * altered. Note, however, that the arc length is always computed and
  502. * returned as the function value.
  503. *
  504. * With the GeodesicLine::LONG_UNROLL bit set, the quantity \e lon2 &minus;
  505. * \e lon1 indicates how many times and in what sense the geodesic
  506. * encircles the ellipsoid.
  507. **********************************************************************/
  508. Math::real GenPosition(bool arcmode, real s12_a12, unsigned outmask,
  509. real& lat2, real& lon2, real& azi2,
  510. real& s12, real& m12, real& M12, real& M21,
  511. real& S12) const;
  512. ///@}
  513. /** \name Setting point 3
  514. **********************************************************************/
  515. ///@{
  516. /**
  517. * Specify position of point 3 in terms of distance.
  518. *
  519. * @param[in] s13 the distance from point 1 to point 3 (meters); it
  520. * can be negative.
  521. *
  522. * This is only useful if the GeodesicLine object has been constructed
  523. * with \e caps |= GeodesicLine::DISTANCE_IN.
  524. **********************************************************************/
  525. void SetDistance(real s13);
  526. /**
  527. * Specify position of point 3 in terms of arc length.
  528. *
  529. * @param[in] a13 the arc length from point 1 to point 3 (degrees); it
  530. * can be negative.
  531. *
  532. * The distance \e s13 is only set if the GeodesicLine object has been
  533. * constructed with \e caps |= GeodesicLine::DISTANCE.
  534. **********************************************************************/
  535. void SetArc(real a13);
  536. /**
  537. * Specify position of point 3 in terms of either distance or arc length.
  538. *
  539. * @param[in] arcmode boolean flag determining the meaning of the second
  540. * parameter; if \e arcmode is false, then the GeodesicLine object must
  541. * have been constructed with \e caps |= GeodesicLine::DISTANCE_IN.
  542. * @param[in] s13_a13 if \e arcmode is false, this is the distance from
  543. * point 1 to point 3 (meters); otherwise it is the arc length from
  544. * point 1 to point 3 (degrees); it can be negative.
  545. **********************************************************************/
  546. void GenSetDistance(bool arcmode, real s13_a13);
  547. ///@}
  548. /** \name Inspector functions
  549. **********************************************************************/
  550. ///@{
  551. /**
  552. * @return true if the object has been initialized.
  553. **********************************************************************/
  554. bool Init() const { return _caps != 0U; }
  555. /**
  556. * @return \e lat1 the latitude of point 1 (degrees).
  557. **********************************************************************/
  558. Math::real Latitude() const
  559. { return Init() ? _lat1 : Math::NaN(); }
  560. /**
  561. * @return \e lon1 the longitude of point 1 (degrees).
  562. **********************************************************************/
  563. Math::real Longitude() const
  564. { return Init() ? _lon1 : Math::NaN(); }
  565. /**
  566. * @return \e azi1 the azimuth (degrees) of the geodesic line at point 1.
  567. **********************************************************************/
  568. Math::real Azimuth() const
  569. { return Init() ? _azi1 : Math::NaN(); }
  570. /**
  571. * The sine and cosine of \e azi1.
  572. *
  573. * @param[out] sazi1 the sine of \e azi1.
  574. * @param[out] cazi1 the cosine of \e azi1.
  575. **********************************************************************/
  576. void Azimuth(real& sazi1, real& cazi1) const
  577. { if (Init()) { sazi1 = _salp1; cazi1 = _calp1; } }
  578. /**
  579. * @return \e azi0 the azimuth (degrees) of the geodesic line as it crosses
  580. * the equator in a northward direction.
  581. *
  582. * The result lies in [&minus;90&deg;, 90&deg;].
  583. **********************************************************************/
  584. Math::real EquatorialAzimuth() const
  585. { return Init() ? Math::atan2d(_salp0, _calp0) : Math::NaN(); }
  586. /**
  587. * The sine and cosine of \e azi0.
  588. *
  589. * @param[out] sazi0 the sine of \e azi0.
  590. * @param[out] cazi0 the cosine of \e azi0.
  591. **********************************************************************/
  592. void EquatorialAzimuth(real& sazi0, real& cazi0) const
  593. { if (Init()) { sazi0 = _salp0; cazi0 = _calp0; } }
  594. /**
  595. * @return \e a1 the arc length (degrees) between the northward equatorial
  596. * crossing and point 1.
  597. *
  598. * The result lies in (&minus;180&deg;, 180&deg;].
  599. **********************************************************************/
  600. Math::real EquatorialArc() const {
  601. return Init() ? Math::atan2d(_ssig1, _csig1) : Math::NaN();
  602. }
  603. /**
  604. * @return \e a the equatorial radius of the ellipsoid (meters). This is
  605. * the value inherited from the Geodesic object used in the constructor.
  606. **********************************************************************/
  607. Math::real EquatorialRadius() const
  608. { return Init() ? _a : Math::NaN(); }
  609. /**
  610. * @return \e f the flattening of the ellipsoid. This is the value
  611. * inherited from the Geodesic object used in the constructor.
  612. **********************************************************************/
  613. Math::real Flattening() const
  614. { return Init() ? _f : Math::NaN(); }
  615. /**
  616. * @return \e caps the computational capabilities that this object was
  617. * constructed with. LATITUDE and AZIMUTH are always included.
  618. **********************************************************************/
  619. unsigned Capabilities() const { return _caps; }
  620. /**
  621. * Test what capabilities are available.
  622. *
  623. * @param[in] testcaps a set of bitor'ed GeodesicLine::mask values.
  624. * @return true if the GeodesicLine object has all these capabilities.
  625. **********************************************************************/
  626. bool Capabilities(unsigned testcaps) const {
  627. testcaps &= OUT_ALL;
  628. return (_caps & testcaps) == testcaps;
  629. }
  630. /**
  631. * The distance or arc length to point 3.
  632. *
  633. * @param[in] arcmode boolean flag determining the meaning of returned
  634. * value.
  635. * @return \e s13 if \e arcmode is false; \e a13 if \e arcmode is true.
  636. **********************************************************************/
  637. Math::real GenDistance(bool arcmode) const
  638. { return Init() ? (arcmode ? _a13 : _s13) : Math::NaN(); }
  639. /**
  640. * @return \e s13, the distance to point 3 (meters).
  641. **********************************************************************/
  642. Math::real Distance() const { return GenDistance(false); }
  643. /**
  644. * @return \e a13, the arc length to point 3 (degrees).
  645. **********************************************************************/
  646. Math::real Arc() const { return GenDistance(true); }
  647. /**
  648. * \deprecated An old name for EquatorialRadius().
  649. **********************************************************************/
  650. GEOGRAPHICLIB_DEPRECATED("Use EquatorialRadius()")
  651. Math::real MajorRadius() const { return EquatorialRadius(); }
  652. ///@}
  653. };
  654. } // namespace GeographicLib
  655. #endif // GEOGRAPHICLIB_GEODESICLINE_HPP