calculate_intersection_point

Function calculate_intersection_point 

Source
pub fn calculate_intersection_point(arc1: &Arc, arc2: &Arc) -> Option<Vector3d>
Expand description

Calculate whether a pair of Arcs intersect and (if so) where.

  • arc1, arc2 the Arcs.

returns the distance along the first Arc to the second Arc or None if they don’t intersect.

§Examples

use unit_sphere::{Arc, Degrees, LatLong, calculate_intersection_point};
use angle_sc::is_within_tolerance;

let istanbul = LatLong::new(Degrees(42.0), Degrees(29.0));
let washington = LatLong::new(Degrees(39.0), Degrees(-77.0));
let reyjavik = LatLong::new(Degrees(64.0), Degrees(-22.0));
let accra = LatLong::new(Degrees(6.0), Degrees(0.0));

let arc1 = Arc::try_from((&istanbul, &washington)).unwrap();
let arc2 = Arc::try_from((&reyjavik, &accra)).unwrap();

// Calculate the intersection point position
let intersection_point = calculate_intersection_point(&arc1, &arc2).unwrap();
let lat_long = LatLong::from(&intersection_point);

// The expected latitude and longitude are from:
// <https://sourceforge.net/p/geographiclib/discussion/1026621/thread/21aaff9f/#fe0a>

// Geodesic intersection latitude is 54.7170296089477
assert!(is_within_tolerance(54.72, lat_long.lat().0, 0.05));
// Geodesic intersection longitude is -14.56385574430775
assert!(is_within_tolerance(-14.56, lat_long.lon().0, 0.02));