Trait geo::algorithm::cross_track_distance::CrossTrackDistance
source · pub trait CrossTrackDistance<T, Rhs = Self> {
// Required method
fn cross_track_distance(&self, line_point_a: &Rhs, line_point_b: &Rhs) -> T;
}
Expand description
Determine the cross track distance (also known as the cross track error) which is the shortest distance between a point and a continuous line.
Required Methods§
sourcefn cross_track_distance(&self, line_point_a: &Rhs, line_point_b: &Rhs) -> T
fn cross_track_distance(&self, line_point_a: &Rhs, line_point_b: &Rhs) -> T
Determine the cross track distance between this point and a line which passes through line_point_a and line_point_b
§Units
- return value: meters
§Example
use geo::prelude::*;
use geo::point;
// New York City
let p1 = point!(x: -74.006f64, y: 40.7128f64);
// Miami
let line_point_a = point!(x: -80.1918f64, y: 25.7617f64);
// Washington
let line_point_b = point!(x: -120.7401, y: 47.7511f64);
let distance = p1.cross_track_distance(&line_point_a, &line_point_b);
assert_eq!(
1_547_104., // meters
distance.round()
);