# Thread: Calculate distance on terrain?

1. ## Calculate distance on terrain?

Hi
I have Haversine great circle formula working to calculate distances
across a sphere for a GPS program.
Everyone knows the distance is virtually 2D on the Earth's surface,
and does not account for terrain.

Say I know there is terrain in a given area,
and the user is of higher elevation than where he/she started a track log,
I was thinking of using Pythagoras' theorem to attempt a better
overall distance estimation by taking horizontal land distance,
the difference between start and end elevation, and filling in the
3D distance with Pythagoras' theorem.

I don't mean for it to sound perfect, but should it not be a better approximation of overall distance every time?

2. > I don't mean for it to sound perfect, but should it not be a better approximation of overall distance every time?
How big a distance?

The difference in distance between 1000 miles flat, and 1000 miles with a 1000 feet height difference is just over 1 inch.

Given most other geoid approximations measure their errors in yards, who's going to notice?

Sure, there are some edge cases like travelling directly from one side of a mountain to another.

3. Well I guess it's not an issue

4. If you want to work out the distance from point A to point B over a sphere, you need to imagine that you are cutting the sphere in half intersecting A & B -> You problem then becomes one of working out the distance along the arc of a circle.

If you have latitude/longitude co-ordinates, there is a formula known as the "Haversine Formula"

5. I already have Haversine formula working, and understand that it is three dimensional
with respect to curvature of the Earth, but I was meaning to compensate for some terrain in a small area.

6. Originally Posted by Salem
> I don't mean for it to sound perfect, but should it not be a better approximation of overall distance every time?
How big a distance?

The difference in distance between 1000 miles flat, and 1000 miles with a 1000 feet height difference is just over 1 inch.

Given most other geoid approximations measure their errors in yards, who's going to notice?

Sure, there are some edge cases like travelling directly from one side of a mountain to another.
Whoa there... back up..

My GPS program is limited to this map data:
Mt Barney National Park 3D Terrain Render - YouTube
which covers terrain (and roads and trails that aren't shown) for a single national park in Australia.

The most popular peak is 1350 meters, the ground level where cars are driven into the park is 350 meters.
Most of the ascent for one popular ridge happens over 2.7 Kilometres (2700 meters).

The 2700 meters is the 2D calculation using only the Haversine formula.

So the difference in elevation is an even 1000 meters, the hypotenuse is 2879 meters,
so the new distance is 179 meters greater distance.

I could do this calculation for every leg of a track log.