File: example-Trigfun.cpp

package info (click to toggle)
geographiclib 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,572 kB
  • sloc: cpp: 27,765; sh: 5,463; makefile: 695; python: 12; ansic: 10
file content (29 lines) | stat: -rw-r--r-- 842 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Example of using the GeographicLib::Trigfun class.

#include <iostream>
#include <iomanip>
#include <exception>
#include <GeographicLib/Trigfun.hpp>

using namespace std;
using namespace GeographicLib;

int main(int argc, const char* const argv[]) {
  try {
    // Approximate 1/sqrt(1 - k2*sin(x)^2) by a Fourier series
    double k2 = Math::sq(0.8);
    auto f = [k2] (double x) -> double
    { return 1/sqrt(1 - k2 * Math::sq(sin(x))); };
    Trigfun tf(f, false, false, Math::pi()/2);
    cout << "Number of coefficients: " << tf.NCoeffs() << "\n";
    cout << "x tf(x) tf(x)-f(x)\n";
    for (int i = 0; i <= 20; ++i) {
      double x = i/10.0;
      cout << x << " " << tf(x) << " " << tf(x) - f(x) << "\n";
    }
  }
  catch (const std::exception& e) {
    std::cerr << "Caught exception: " << e.what() << "\n";
    return 1;
  }
}