Great circle + height calculation for accurrate distance

Rej

New member
Joined
Apr 5, 2021
Messages
18
It's been a little too long since I have been in school so I'm hoping someone whose mind is still fresh with math can answer this with ease compared to me.

Imagine you have two points on the Earth where one is at an elevation, perhaps on a hill or mountain, while the other may or may not be above ground level.

The shortest path in that case would be partly a great circle (assuming the points were far enough apart) and partly a straight line. One way to imagine this is to think of a piece of string stretched, say about a foot long, and then taking a tennis ball and pushing it up into the string at some point along it. Now part of the string is wrapped around the ball and part of it is straight. For my purposes I'm only concerned with points on the Earth so the tennis ball analogy is a little off but hopefully it serves as a mental visual aid.

Does anyone know a formula that would calculate the distance between two points on a sphere where they may not be at the surface of the sphere so that we take into account both the great circle part and the straight part(s) of the path given two coordinates both of the form x,y,z and a radius for the sphere? We can ignore that the Earth is a spheroid for this purpose.

Thanks!
Reg
 
Last edited:
It's been a little too long since I have been in school so I'm hoping someone whose mind is still fresh with math can answer this with ease compared to me.

Imagine you have two points on the Earth where one is at an elevation, perhaps on a hill or mountain, while the other may or may not be above ground level.

The shortest path in that case would be partly a great circle (assuming the points were far enough apart) and partly a straight line. One way to imagine this is to think of a piece of string stretched, say about a foot long, and then taking a tennis ball and pushing it up into the string at some point along it. Now part of the string is wrapped around the ball and part of it is straight. For my purposes I'm only concerned with points on the Earth so the tennis ball analogy is a little off but hopefully it serves as a mental visual aid.

Does anyone know a formula that would calculate the distance between two points on a sphere where they may not be at the surface of the sphere so that we take into account both the great circle part and the straight part(s) of the path given two coordinates both of the form x,y,z and a radius for the sphere? We can ignore that the Earth is a spheroid for this purpose.

Thanks!
Reg
Contradictory question. The part of the path which is not on the hill is described as straight and curved at the same time. What about the hill's shape?
 
Imagine you have two points on the Earth where one is at an elevation, perhaps on a hill or mountain, while the other may or may not be above ground level.

The shortest path in that case would be partly a great circle (assuming the points were far enough apart) and partly a straight line. One way to imagine this is to think of a piece of string stretched, say about a foot long, and then taking a tennis ball and pushing it up into the string at some point along it. Now part of the string is wrapped around the ball and part of it is straight. For my purposes I'm only concerned with points on the Earth so the tennis ball analogy is a little off but hopefully it serves as a mental visual aid.

Does anyone know a formula that would calculate the distance between two points on a sphere where they may not be at the surface of the sphere so that we take into account both the great circle part and the straight part(s) of the path given two coordinates both of the form x,y,z and a radius for the sphere? We can ignore that the Earth is a spheroid for this purpose.
I think you are asking for the distance in red here, from A to B via C:
1617711761169.png
You aren't really thinking of B being on the earth and traveling along the earth, but B being up in the air, walking from A to C and then flying to B along a straight line. (Mountains don't have straight slopes.)

Now, what data do you have about the two points?
 
I am assuming that Dr. Peterson has interpreted your question correctly.

It is easiest to solve that question by setting up a coordinate system using the center of the earth as the origin and assuming the earth is a perfect sphere. Determine the equation of the line joining A and B. Find the point on that line where the distance to the origin equals the sphere’s radius.That point is C. Your distance then is the sum of the Euclidian distance between B and C and the arc length for AC.
 
Yes, the red line is what I am looking for. There is a potential for A to also not be at surface level however that obviously is no problem if it's already solved for how it's shown.

My problem is that after 3+ decades away from my school years I'm more than just a little rusty with my math and I'm not sure how to figure out where C happens. Once that's figured out I can see it's pretty easy to figure out BC and AC. The input coordinates are in the form of xyz but that should be easy enough to convert to polar (I think that's the correct term) coordinates.
 
Yes, the red line is what I am looking for. There is a potential for A to also not be at surface level however that obviously is no problem if it's already solved for how it's shown.

My problem is that after 3+ decades away from my school years I'm more than just a little rusty with my math and I'm not sure how to figure out where C happens. Once that's figured out I can see it's pretty easy to figure out BC and AC. The input coordinates are in the form of xyz but that should be easy enough to convert to polar (I think that's the correct term) coordinates.

If you search, you can easily find a formula for the distance to the horizon from a given point at a given height; that will give you the distance BC. Then you need to find the surface distance from B' to C (a different formula you may find online), and subtract that from the surface distance from A to B to get the distance AC.

1617736917546.png

Or I can just tell you those formulas.

Distance \(d_1\) is found by solving the right triangle OBC using the Pythagorean theorem: \(d_1 = \sqrt{(R+h)^2-R^2} = \sqrt{2Rh+h^2} = \sqrt{h(2R+h)}\).

Distance \(d_0\) is the radius R times angle \(\alpha = \arctan\left(\frac{d_1}{R}\right)\) (in radians).

Then the distance you want is \(d_1+d_2=d+d_1-d_0\) where d is the great circle distance from B' to A.

I'll have to trust that you know how to get those numbers from the coordinates you have. If you knew latitude and longitude rather than (x,y,z), I could direct you to the right formulas for that.
 
Wow, thank you!

I think I made a mistake when I said x,y,z. I probably should have said latitude, longitude and height... I didn't realize there was a difference. However, I don't think there will be a problem, formulas for conversions between coordinate systems is pretty easy to find out there but if you happen to know where they are then much appreciated.

Thanks again!
Reg
 
Wow, thank you!

I think I made a mistake when I said x,y,z. I probably should have said latitude, longitude and height... I didn't realize there was a difference. However, I don't think there will be a problem, formulas for conversions between coordinate systems is pretty easy to find out there but if you happen to know where they are then much appreciated.

Thanks again!
Reg
There is a huge difference between rectangular coordinates and latitude/longitude. The best formula for distance along a sphere is covered here. I also recently discussed it in my own blog, here.
 
Well, I can say I'm getting quite an education on math and spheres/spheroids. Your blog article answered one of my questions too and that was what to use as a radius given that the Earth is not a perfect sphere.

I followed the Wiki through a link and learned that the Haversine formula helped the navigators because it meant they didn't have to deal with squares and more importantly square roots. I can imagine they used tables for sine and cosine much like I had in one of my trigonometry math book back at school. I bet with computers they don't bother with those tables anymore!

I feel terrible asking this because it feels like I'm asking for the exact same thing twice but if moving over to using Haversine instead of x,y,z, when we add a height so that we get like you drew above how do we now figure out AC & BC? Again, I'm going to assume that I can actually extrapolate to how to figure it out if there was a height at both ends... I think I can figure that much out myself!

BTW, in the extreme case where two people were only a building width apart but one was at the top of a tall building and the other at the base then the height would essentially be all the distance whereas if they are far enough apart, like two different cities, the height would make a negligible contribution and the Haversine distance would be essentially all of the distance so it's important that I take into account both the straight line portion and the great circle portion in the calculations as both of these scenarios and anything in between is possible in this project I'm tinkering with... in case you were interested in why I needed to take into account height.
 
I feel terrible asking this because it feels like I'm asking for the exact same thing twice but if moving over to using Haversine instead of x,y,z, when we add a height so that we get like you drew above how do we now figure out AC & BC? Again, I'm going to assume that I can actually extrapolate to how to figure it out if there was a height at both ends... I think I can figure that much out myself!
Just use the Haversine formula to find B'A (which I called d). I told you everything else in post #6.

BTW, in the extreme case where two people were only a building width apart but one was at the top of a tall building and the other at the base then the height would essentially be all the distance whereas if they are far enough apart, like two different cities, the height would make a negligible contribution and the Haversine distance would be essentially all of the distance so it's important that I take into account both the straight line portion and the great circle portion in the calculations as both of these scenarios and anything in between is possible in this project I'm tinkering with... in case you were interested in why I needed to take into account height.
Here you'd need a straight line distance that is not tangent to a sphere, which I haven't covered. I would probably convert from spherical coordinates to rectangular and use the Pythagorean theorem (distance formula). Or, use this: https://en.wikipedia.org/wiki/Spherical_coordinate_system#Distance_in_spherical_coordinates . But be aware that there are different ways to express spherical coordinates (read the top of the page), and that latitude is an "elevation" rather than "inclination" as used there.
 
Beer soaked query follows.
... My problem is that after 3+ decades away from my school years I'm ...
... I can imagine they used tables for sine and cosine much like I had in one of my trigonometry math book back at school. ...
Which book was that?
I'll bet some of us might have used it.
 
Sorry, I certainly don't remember the book after that amount of time and I grew up in Australia although I'm in Arizona now so I would image the books were different. What I do remember is that it was a small thin book full of tables for all sorts of things to do with math so now that I think about it it probably had more than just trig. tables in it but I really don't remember the specifics of it.
 
Using the resources you gave me I added in estimating the mean radius of the Earth between two points on the Earth's surface and with that got so I was only different to an online map measuring distance between Dallas and Tempe AZ by 0.0021% so I can be happy with that.

For dealing with the height I'm just calculating the line of sight d1 and if the angle it creates is greater than the angle a+b (I don't know how to create the fancy symbols you create) created by the Haversine calculation then I just do an x,y,z1 to x,y,z2 straight line calculation but if the angle is less than the angle created by the Haversine calculation then I do the combination calculation like you showed so there is an "if" in the algorithm but as a programmer I certainly have no problem with that although I am mildly curious on whether there's a cleaner way than that.

In any case, thanks! It all seems to be working now. By the way, do you use some special math package to create those formulas and the diagrams? If so please do tell as it/they seem like mighty handy tools.
 
There is nothing cleaner than separate cases.

My pictures are made with GeoGebra. My formulas are made with LaTeX, a standard formatting language that is supported on this site. You can also surround basic notation like "sqrt(x^2+y^2)" or "a/b" with backquotes to display `sqrt(x^2+y^2)` and `a/b`, respectively, with no fuss.
 
  • Like
Reactions: Rej
Beer soaked ramblings follow.
Sorry, I certainly don't remember the book after that amount of time and I grew up in Australia although I'm in Arizona now so I would image the books were different. What I do remember is that it was a small thin book full of tables for all sorts of things to do with math so now that I think about it it probably had more than just trig. tables in it but I really don't remember the specifics of it.
Brings back fond memories of table hunting and frequent regrettable crosseyed errors.
 
  • Like
Reactions: Rej
Now that I have been playing with it and learned a bit I have one more question. This is probably me getting a little too pedantic but I feel like I have a refinement that only goes partly through the equations and it's annoying me.

I used a refinement from digging through your blog and sites it references to make minor adjustment to the radius at each point (better taking into account that Earth is a spheroid by adding in eccentricity ( https://web.archive.org/web/20010405121423/http://www.census.gov/cgi-bin/geo/gisfaq?Q5.1 )) before calculating the distance using Haversine and I use the average of those two radii which is what got me so close to the same distance as an online map... There's probably a more accurate way than that but I'm happy with the accuracy this method gives.

However, looking at the calculation for d1 it seems to me that there is going to be a discrepancy between where C is when the radii at A & B1 are not the same as each other vs. as they are currently assumed to be. I suspect it will be a very small discrepancy and I'm not sure if it's worth trying to figure out the adjustment but I thought I would ask if you have an idea about how to factor that?

By the way, the way I opted to determine whether to use a straight line calculation or to use Haversine + what you showed in #6 is by doing a "hidden height" calculation and if the hidden height is less than or equal to the actual height of the target then I just do a straight line calculation and I got the hidden height formula from http://walter.bislins.ch/bloge/inde...lator#H_Exact_Equations_for_the_Hidden_Height using (4). I did that because I couldn't see only comparing results between the two ways to calculate logically correct for making that determination but then again I could easily be wrong, I'm still absorbing and re/learning much.

I'm definitely not getting into calculations that factor for refraction (I'm not sure if it's even legitimate in my case to consider it)... at some point you have to stop with the complexity and I think I've gone far enough in that respect just factoring combinations of line of sight and Earth's curvature to make a total distance.
 
I went looking around and it seems the formulas for spheroids can get incredibly complicated. I think I should probably stick with where I am up to as good enough.
 
I went looking around and it seems the formulas for spheroids can get incredibly complicated. I think I should probably stick with where I am up to as good enough.
Yes, I've never attempted the real-earth case at all.
 
  • Like
Reactions: Rej
Dr. Peterson, thank you so much! I know this is very belated, like many I'm very busy but I can't speak if most have many things pulling them many ways which I do... not a bad thing.

I had a thought that's not hard core maths but certainly related. If you have a propensity for topics related to but perhaps not precisely focused on your profession then please do weigh in on my off-the-cuff question: https://www.freemathhelp.com/forum/threads/math-physics-probably-a-dose-of-philosophy.131692/ .

Thanks again for all your help!
 
Last edited:
Top