1 // Example of using the GeographicLib::CircularEngine class
2 
3 #include <iostream>
4 #include <exception>
5 #include <vector>
6 #include <GeographicLib/CircularEngine.hpp>
7 #include <GeographicLib/SphericalHarmonic.hpp>
8 
9 using namespace std;
10 using namespace GeographicLib;
11 
main()12 int main() {
13   // This computes the same value as example-SphericalHarmonic.cpp using a
14   // CircularEngine (which will be faster if many values on a circle of
15   // latitude are to be found).
16   try {
17     using std::hypot;
18     int N = 3;                  // The maxium degree
19     double ca[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // cosine coefficients
20     vector<double> C(ca, ca + (N + 1) * (N + 2) / 2);
21     double sa[] = {6, 5, 4, 3, 2, 1}; // sine coefficients
22     vector<double> S(sa, sa + N * (N + 1) / 2);
23     double a = 1;
24     SphericalHarmonic h(C, S, N, a);
25     double x = 2, y = 3, z = 1, p = hypot(x, y);
26     CircularEngine circ = h.Circle(p, z, true);
27     double v, vx, vy, vz;
28     v = circ(x/p, y/p, vx, vy, vz);
29     cout << v << " " << vx << " " << vy << " " << vz << "\n";
30   }
31   catch (const exception& e) {
32     cerr << "Caught exception: " << e.what() << "\n";
33     return 1;
34   }
35 }
36