Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shortest distance (height) to Earth's surface between mountain tops

Started by bleabox Sep 3, 2010 at 8:03 PM 10 replies 1.8k views
Original Post
bleabox
bleabox
I think image says it all.



Any suggestions?

If the line crosses the surface of the earth, distance should be 0.
Emergent
Emergent
Orthogonally project the center of the sphere onto the line. If that point is outside the sphere, then it's the location of the minimum. Otherwise the line intersects the sphere and the distance is zero.

How to do this?

Denote by p1,p2 the mountain tops (points in R^3) and c the center of the sphere.

Then let

p = p1 + / v

where

v = p2 - p1.

This is the projection of the center of the sphere onto the line. The distance between the line and the surface of the sphere is thus,

d = max{0, ||p - c||} .
incin
incin
Maybe I don't understand that notation, but it seems more complicated than it has to be. Here's how I would do it:
m = (p1+p2)/2 -- the midpoint of the two points
|m| - RadiusOfEarth -- altitude (or -depth) at midpoint
adam4813
adam4813
Consider that each mountain is the point on a triangle and that the center of the earth is the third. You can use Pythagorean theorem using half the distance between each mountain as the right angle side. The hypotenuse is the mountain to earth center and the other right angle side is the midpoint between the mountains to earth center. All that is left is to subtract the earths radius.

So in math we get
let q be half the distance between a and b (to make a right triangle)
a = distance from a to q
b = distance from q to earth center
c = distance from a to earth center
a^2 + b^2 = c^2
height = b - earth_radius
luca-deltodesco
luca-deltodesco
incin and adam: both your solutions rely on the assumption that the two mountains are the exact same height and will fail instantly if they differ (aswell as yours incin assuming that the earth is at the origin). Emergent's is the correct solution with the slight modification of distance being max{0,||p-c||-R} with R being the radius of the earth.

There is however one last ambiguity. That is: do you want the distance from the line between the two mountain tops, as in the finite line segment starting at one end; ending at the other. Or of the infinite line passing through both mountain tops?

If you want it to be the finite line segment joining them you would need to modify emergent's again like so:

t = clamp{ /, [0,1] }
p = p1 + t*v
distance = max{0,||p-c||-R}
bleabox
bleabox
The mountains can differ in height.

I don't understand this notation.

What does "<" mean?

for example. What is that.
alvaro
alvaro
Quote:
Original post by bleabox
The mountains can differ in height.

I don't understand this notation.

What does "<" mean?

for example. What is that.


It's a common notation for the dot product.
Emergent
Emergent
Quote:
Original post by luca-deltodesco
Emergent's is the correct solution with the slight modification of distance being max{0,||p-c||-R} with R being the radius of the earth.


Good catch.
bleabox
bleabox
What is "v"?
Emergent
Emergent
Quote:
Original post by bleabox
What is "v"?


Quote:
Original post by Emergent
where

v = p2 - p1.
bleabox
bleabox
Thank you for the clarifications.

I probably should've pointed out this is for GPS coordinates and altitudes. The 2D image is just a way to visualize the problem. This algorithm is for 2D only, isn't it?
luca-deltodesco
luca-deltodesco
Quote:
Original post by bleabox
Thank you for the clarifications.

I probably should've pointed out this is for GPS coordinates and altitudes. The 2D image is just a way to visualize the problem. This algorithm is for 2D only, isn't it?


no (as in, it's fine for 3d or any dimension if you take the circle/sphere to be a hypersphere)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.