Haversine Closest Point Is In Angles-as-euclidian-coordinates?

by ADMIN 63 views

Introduction

In the realm of geodesy, the Haversine formula is a widely used method for calculating distances between two points on a sphere, such as the Earth. However, when it comes to finding the closest point on a geodesic line to a given point, the results may not always be as expected. In this article, we will delve into the world of spherical geometry and explore the concept of treating angles as Cartesian coordinates with wraparound.

The Haversine Formula

The Haversine formula is a formula used to calculate the distance between two points on a sphere. It is given by:

a = sin²(Δlat/2) + cos(lat1) * cos(lat2) * sin²(Δlong/2)

where a is the distance between the two points, Δlat is the difference in latitude, Δlong is the difference in longitude, and lat1 and lat2 are the latitudes of the two points.

The Geodesic Line

A geodesic line is a curve on a sphere that is the shortest path between two points. In the context of the Haversine formula, a geodesic line is a great circle, which is a circle on a sphere that passes through the center of the sphere.

The Haversine Closest Point

The Haversine closest point is a method for finding the closest point on a geodesic line to a given point. It is implemented in the geo crate in Rust, which provides a set of functions for working with geodesic lines and points.

The Test Case

The test case provided in the code snippet above is designed to test the Haversine closest point method. It creates two points, pt_a and pt_b, which are located at high latitudes. It then creates a geodesic line between these two points and calculates the midpoint of the line. The Haversine closest point method is then used to find the closest point on the geodesic line to the midpoint.

The Results

The results of the test case are surprising. The closest point returned by the Haversine closest point method is neither the input point nor on the geodesic line. This suggests that the method is not working as expected.

Treating Angles as Cartesian Coordinates

Upon further investigation, it appears that many of the "spherical" methods, including the Haversine closest point method, are actually treating angles as Cartesian coordinates with wraparound. This means that the angles are being treated as if they were coordinates on a plane, rather than as angles on a sphere.

Conclusion

In conclusion, the Haversine closest point method is not working as expected. The results suggest that the method is treating angles as Cartesian coordinates with wraparound, rather than as angles on a sphere. This has significant implications for any application that relies on this method.

Correcting the Assumptions

The assumptions made in the test case are correct. The Haversine closest point method is not working as expected, and the results suggest that the method is treating angles as Cartesian coordinates with wraparound.

Correcting the Test

To correct the test, we need to modify the Haversine closest point method to treat angles as angles on a sphere, rather than as Cartesian coordinates with wraparound. This can be done by using a different method for calculating the closest point, such as the closest_point method provided by the geo crate.

Code Modifications

The code modifications required to correct the test are as follows:

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.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);
}

Conclusion

Q: What is the Haversine closest point method?

A: The Haversine closest point method is a method for finding the closest point on a geodesic line to a given point. It is implemented in the geo crate in Rust, which provides a set of functions for working with geodesic lines and points.

Q: Why is the Haversine closest point method not working as expected?

A: The Haversine closest point method is not working as expected because it is treating angles as Cartesian coordinates with wraparound, rather than as angles on a sphere. This means that the method is not taking into account the curvature of the Earth and is instead treating the angles as if they were coordinates on a plane.

Q: What is the difference between treating angles as Cartesian coordinates and treating them as angles on a sphere?

A: Treating angles as Cartesian coordinates means that the angles are being treated as if they were coordinates on a plane, rather than as angles on a sphere. This can lead to incorrect results when working with geodesic lines and points.

Q: How can I correct the Haversine closest point method to treat angles as angles on a sphere?

A: To correct the Haversine closest point method, you can use a different method for calculating the closest point, such as the closest_point method provided by the geo crate. This method takes into account the curvature of the Earth and treats the angles as angles on a sphere.

Q: What are the implications of treating angles as Cartesian coordinates with wraparound?

A: Treating angles as Cartesian coordinates with wraparound can lead to incorrect results when working with geodesic lines and points. This can have significant implications for any application that relies on these methods.

Q: How can I avoid treating angles as Cartesian coordinates with wraparound?

A: To avoid treating angles as Cartesian coordinates with wraparound, you can use methods that take into account the curvature of the Earth, such as the closest_point method provided by the geo crate.

Q: What are some common use cases for the Haversine closest point method?

A: The Haversine closest point method is commonly used in applications such as:

  • Geolocation: Finding the closest point on a geodesic line to a given location.
  • Route planning: Finding the closest point on a geodesic line to a given destination.
  • Geospatial analysis: Analyzing geospatial data and finding the closest point on a geodesic line to a given point.

Q: How can I implement the Haversine closest point method in my own code?

A: To implement the Haversine closest point method in your own code, you can use the geo crate in Rust, which provides a set of functions for working with geodesic lines and points. You can also use other libraries and frameworks that provide similar functionality.

Q: What are some best practices for working with geodesic lines and points?

A: Some best practices for working with geodesic lines and points include:

  • Using methods that take into account the curvature of the Earth: Avoid using methods that treat angles as Cartesian coordinates with wraparound.
  • Using libraries and frameworks that provide accurate geospatial functionality: Use libraries and frameworks that provide accurate geospatial functionality, such as the geo crate in Rust.
  • Testing and validating your code: Test and validate your code to ensure that it is working correctly and producing accurate results.