File: example-Intersect.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 (33 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (2)
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
30
31
32
33
// Example of using the GeographicLib::Intersect class

#include <iostream>
#include <exception>
#include <GeographicLib/Intersect.hpp>
#include <GeographicLib/Constants.hpp>

using namespace std;
using namespace GeographicLib;

int main() {
  try {
    Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f());
    Intersect intersect(geod);
    // Define the two geodesics
    GeodesicLine lineX(geod, 0, 0, 45, Intersect::LineCaps);
    GeodesicLine lineY(geod, 45, 10, 135, Intersect::LineCaps);
    // Find displacement to closest intersection
    Intersect::Point point = intersect.Closest(lineX, lineY);
    // Check position at intersection
    double latx, lonx, laty, lony;
    lineX.Position(point.first, latx, lonx);
    lineY.Position(point.second, laty, lony);
    cout << "X intersection displacement + position "
         << point.first << " " << latx << " " << lonx << "\n";
    cout << "Y intersection displacement + position "
         << point.second << " " << laty << " " << lony << "\n";
  }
  catch (const exception& e) {
    cerr << "Caught exception: " << e.what() << "\n";
    return 1;
  }
}