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

Getting bearing between two points? #185

Closed
pavelmachek opened this issue Feb 27, 2018 · 6 comments
Closed

Getting bearing between two points? #185

pavelmachek opened this issue Feb 27, 2018 · 6 comments

Comments

@pavelmachek
Copy link

I can use haversine_destination to convert point, bearing and distance to second point. Is there reverse operation available? I can use haversine_distance() to get distance of two points, but I can't get bearing...

@urschrei
Copy link
Member

Hmm I don't do much with Haversine, @mkulke, got any ideas?

@pavelmachek
Copy link
Author

For now I worked around the problem with:

fn get_bearing(origin : & geo::Point<f64>, destination : & geo::Point<f64>) -> f64 {
// https://gist.github.com/geografa/1366401
        let (lon1, lat1) = ( origin.x().to_radians(), origin.y().to_radians() );
        let (lon2, lat2) = ( destination.x().to_radians(), destination.y().to_radians() );
        let dlon = lon2-lon1;

        let bearing = f64::atan2(f64::sin(dlon)*f64::cos(lat2),f64::cos(lat1)*f64::sin(lat2)-f64::sin(lat1)*f64::cos(lat2)*f64::cos(dlon));

        bearing.to_degrees()
}

@mkulke
Copy link
Contributor

mkulke commented Mar 2, 2018

@pavelmachek

actually i think your implementation is canonical. maybe worth adding?

S = cos φB sin ∆L
C = cos φA sin φB − sin φA cos φB cos ∆L
beta = atan2(S, C);

source: https://dtcenter.org/met/users/docs/write_ups/gc_simple.pdf

@pavelmachek
Copy link
Author

Yes, the code should be ok. But I guess I do not know enough about rust templates and cargo to generate proper patch. I'd like rust-geo to gain that functionality.

@mkulke
Copy link
Contributor

mkulke commented Mar 2, 2018

alrighty, i quickly added the trait in #186. it's useful for me as well.

@urschrei
Copy link
Member

urschrei commented Mar 2, 2018 via email

bors bot added a commit that referenced this issue Mar 4, 2018
186: Added bearing trait. r=frewsxcv a=mkulke

adresses #185
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

4 participants