examples/example-GeodesicLine.cpp
Go to the documentation of this file.
1 // Example of using the GeographicLib::GeodesicLine class
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <exception>
6 #include <cmath>
10 
11 using namespace std;
12 using namespace GeographicLib;
13 
14 int main() {
15  try {
16  // Print waypoints between JFK and SIN
17  Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f());
18  // Alternatively: const Geodesic& geod = Geodesic::WGS84();
19  double
20  lat1 = 40.640, lon1 = -73.779, // JFK
21  lat2 = 1.359, lon2 = 103.989; // SIN
22  const GeographicLib::GeodesicLine line =
23  geod.InverseLine(lat1, lon1, lat2, lon2);
24  double ds0 = 500e3; // Nominal distance between points = 500 km
25  int num = int(ceil(line.Distance() / ds0)); // The number of intervals
26  cout << fixed << setprecision(3);
27  {
28  // Use intervals of equal length
29  double ds = line.Distance() / num;
30  for (int i = 0; i <= num; ++i) {
31  double lat, lon;
32  line.Position(i * ds, lat, lon);
33  cout << i << " " << lat << " " << lon << "\n";
34  }
35  }
36  {
37  // Slightly faster, use intervals of equal arc length
38  double da = line.Arc() / num;
39  for (int i = 0; i <= num; ++i) {
40  double lat, lon;
41  line.ArcPosition(i * da, lat, lon);
42  cout << i << " " << lat << " " << lon << "\n";
43  }
44  }
45  }
46  catch (const exception& e) {
47  cerr << "Caught exception: " << e.what() << "\n";
48  return 1;
49  }
50 }
Header for GeographicLib::GeodesicLine class.
return int(ret)+1
static const double lat
Math::real Arc() const
Math::real Position(real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Half.h:150
Math::real Distance() const
EIGEN_DEVICE_FUNC const CeilReturnType ceil() const
Header for GeographicLib::Geodesic class.
Namespace for GeographicLib.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Header for GeographicLib::Constants class.
GeodesicLine InverseLine(real lat1, real lon1, real lat2, real lon2, unsigned caps=ALL) const
static const double lon
void ArcPosition(real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Geodesic calculations
Definition: Geodesic.hpp:172


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:02