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 }
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
main
int main()
Definition: examples/example-GeodesicLine.cpp:14
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
GeographicLib::GeodesicLine
A geodesic line.
Definition: GeodesicLine.hpp:71
GeographicLib::GeodesicLine::Arc
Math::real Arc() const
Definition: GeodesicLine.hpp:695
GeographicLib::GeodesicLine::Distance
Math::real Distance() const
Definition: GeodesicLine.hpp:690
GeographicLib::GeodesicLine::Position
Math::real Position(real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: GeodesicLine.hpp:281
GeodesicLine.hpp
Header for GeographicLib::GeodesicLine class.
GeographicLib::Geodesic::InverseLine
GeodesicLine InverseLine(real lat1, real lon1, real lat2, real lon2, unsigned caps=ALL) const
Definition: src/Geodesic.cpp:510
Constants.hpp
Header for GeographicLib::Constants class.
std
Definition: BFloat16.h:88
ceil
const EIGEN_DEVICE_FUNC CeilReturnType ceil() const
Definition: ArrayCwiseUnaryOps.h:495
lon
static const double lon
Definition: testGeographicLib.cpp:34
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
GeographicLib::Geodesic
Geodesic calculations
Definition: Geodesic.hpp:172
Geodesic.hpp
Header for GeographicLib::Geodesic class.
GeographicLib::GeodesicLine::ArcPosition
void ArcPosition(real a12, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Definition: GeodesicLine.hpp:394
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:31