Files
qt6-migration-pipeline/external/GeographicLib/share/doc/GeographicLib-dev/example-Trigfun.cpp
T
torsten 77c67c12ca Execute the same instructions but now for tools in folders you are getti
Entire-Metadata: .entire/metadata/fb87247f-2a75-407e-b336-cbc8c20ba5a6
Entire-Session: fb87247f-2a75-407e-b336-cbc8c20ba5a6
Entire-Strategy: manual-commit
2026-09-24 16:24:51 +00:00

30 lines
842 B
C++

// 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;
}
}