Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haversine closest point is incorrect, at least at high lattitudes? #1325

Open
jodavaho opened this issue Mar 11, 2025 · 0 comments
Open

Haversine closest point is incorrect, at least at high lattitudes? #1325

jodavaho opened this issue Mar 11, 2025 · 0 comments

Comments

@jodavaho
Copy link

jodavaho commented Mar 11, 2025

Please correct me if my assumptions or test is incorrect.

use geo::prelude::*;
use geo::point;
use approx::assert_abs_diff_eq;
fn main() {
    // Make sure midpoint returned when at high latitudes
    use geo::Geodesic;
    let pt_a = point!(x: 0.0, y: 80.0);
    let pt_b = point!(x: 179.99, y: 80.0);
    let ln = geo::Line::new(pt_a, pt_b);
    let d = Geodesic::distance(pt_a, pt_b);
    let midpoint = Geodesic::point_at_ratio_between(pt_a, pt_b, 0.5);
    eprintln!("the midpoint is {:?}", midpoint);
    let closest_point = {
        let closest_res = ln.haversine_closest_point(&midpoint);
        use geo::Closest::*;
        match closest_res {
            Intersection(p) => p,
            SinglePoint(p) => p,
            Indeterminate => {
                panic!("Indeterminate");
            }
        }
    };
    assert_abs_diff_eq!(closest_point.y(), midpoint.y(), epsilon = 1e-6);
    assert_abs_diff_eq!(closest_point.x(), midpoint.x(), epsilon = 1e-6);
}

Image

The returned closest point is neither the input point or on the geodesic line.

again, please correct me if I've done something incorrect here.

@jodavaho jodavaho changed the title Haversine closest point is in angles-as-euclidian-coordinates? Haversine closest point is incorrect, at least at high lattitudes? Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant