1 // Example of using the GeographicLib::GeodesicLine class
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <exception>
6 #include <cmath>
7 #include <GeographicLib/Geodesic.hpp>
8 #include <GeographicLib/GeodesicLine.hpp>
9 #include <GeographicLib/Constants.hpp>
10 
11 using namespace std;
12 using namespace GeographicLib;
13 
main()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     GeodesicLine line = geod.InverseLine(lat1, lon1, lat2, lon2);
23     double ds0 = 500e3;             // Nominal distance between points = 500 km
24     int num = int(ceil(line.Distance() / ds0)); // The number of intervals
25     cout << fixed << setprecision(3);
26     {
27       // Use intervals of equal length
28       double ds = line.Distance() / num;
29       for (int i = 0; i <= num; ++i) {
30         double lat, lon;
31        line.Position(i * ds, lat, lon);
32        cout << i << " " << lat << " " << lon << "\n";
33       }
34     }
35     {
36       // Slightly faster, use intervals of equal arc length
37       double da = line.Arc() / num;
38       for (int i = 0; i <= num; ++i) {
39         double lat, lon;
40        line.ArcPosition(i * da, lat, lon);
41        cout << i << " " << lat << " " << lon << "\n";
42       }
43     }
44   }
45   catch (const exception& e) {
46     cerr << "Caught exception: " << e.what() << "\n";
47     return 1;
48   }
49 }
50