Thread: Calculate distance on terrain?

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    106

    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. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    106
    Well I guess it's not an issue

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    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"
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    106
    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. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    106
    Quote Originally Posted by Salem View Post
    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 03-06-2012, 10:24 PM
  2. Help! Why does it keep showing Distance = 0.00?
    By toobee in forum C Programming
    Replies: 4
    Last Post: 02-19-2012, 11:38 PM
  3. distance algorythm help
    By MicroFiend in forum Game Programming
    Replies: 9
    Last Post: 06-12-2004, 09:28 PM
  4. Hex distance
    By waterst in forum C Programming
    Replies: 7
    Last Post: 11-02-2002, 01:59 PM
  5. love and distance
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-19-2002, 01:51 PM