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

Distance calculator - add altitude in formulas #37

Closed
Warxcell opened this issue Aug 13, 2018 · 8 comments
Closed

Distance calculator - add altitude in formulas #37

Warxcell opened this issue Aug 13, 2018 · 8 comments
Assignees
Milestone

Comments

@Warxcell
Copy link

Warxcell commented Aug 13, 2018

Hello, right now distance calculator does not add altitude difference between points to distance, and when it's calculating route with elevation gain or loss the results are slightly not correct.

I used pythagorean to include altitude to distance. I don't know if this is correct, but results looks more or less correct. :)

  public function distanceLatLngAlt(float $lat1, float $lng1, float $alt1, float $lat2, float $lng2, float $alt2)
    {
        $distance = $this->distanceLatLng($lat1, $lng1, $lat2, $lng2);

        $elevDiff = abs($alt1 - $alt2);

        return sqrt(pow($distance, 2) + pow($elevDiff, 2));
    }

This formula is tested against 141 km path. The difference between distance with 2 formulas is almost 1km.

What do you think if we integrate this or some other formulas to include altitude in distance calculations?

@Warxcell Warxcell changed the title Distance calculator Distance calculator - add altitude in formulas Aug 13, 2018
@Sibyx
Copy link
Owner

Sibyx commented Aug 21, 2018

Hi, nice idea. I am thinking of the implementation. If it's better to create a new attribute or create a configuration flag. What do you think?

Sorry for the later response, I was on holiday.

@Warxcell
Copy link
Author

Warxcell commented Aug 21, 2018

Well I guess it will be best if there is parallel property with calculated distance with included altitude. Right now in my project I'm using both of them. Distance with altitude to have real distance and Distance without altitude to calculate average grade between two points. :)

@Sibyx
Copy link
Owner

Sibyx commented Aug 21, 2018

OK then :) Would you like to offer PR or I should do the implementation?

@Warxcell
Copy link
Author

Warxcell commented Aug 21, 2018

I would probably refactor DistanceCalculator and use instance of it instead static method.
Something like that:

$calculator = new DistanceCalculator($points);
$rawDistance = $calculator->getRawDistance();
$distanceWithAltitude = $calculator->getRealDistance()

Better ideas for method names?

@Sibyx
Copy link
Owner

Sibyx commented Aug 21, 2018

Hmm, sounds good to me. I am just not sure about changing API (I am not proud about the library versioning :D )

@Warxcell
Copy link
Author

Well, isn't that DistanceCalculator for internal use only? If so, shouldn't be a problem.

@Sibyx
Copy link
Owner

Sibyx commented Aug 21, 2018

Ahh I see, sorry. So then is not problem at all ;)

@Sibyx Sibyx self-assigned this Apr 30, 2021
@Sibyx Sibyx added this to the 1.2 milestone Apr 30, 2021
@Sibyx
Copy link
Owner

Sibyx commented Jul 30, 2022

Implemented as realDistance property in Route, Segment, Stats, Track objects.

@Sibyx Sibyx closed this as completed Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants