Mapping & Distance Calc: Distance of 3rd point from a Route

Let’s say you’ve got a travel route such as you’d get on Google maps by plugging in two locations and asking for driving directions.

Is there a formulaic way (as opposed to hopping over to Google maps or ClassyGMaps and inputting a three-point travel route to see what it comes up with) to determine how many extra miles are incurred by stopping off at a specified 3rd location?

Assume I have longitude and latitutde for all three points.

If it helps for clarification, imagine I have a plan to travel from New York to Los Angeles, and a have 40 cities in a table. For each city I’d like a number to appear that represents the additional distance (“as the crow flies” would be adequate, “by an actual replanned highway driving path” would be fantastic) necessary to travel from New Yor to Los Angeles via the city in question.

Mapquest would probably serve your needs, although there is a 26 stop limit. You would have to do it in two parts. https://www.mapquest.com/routeplanner

Are we talking wiggly lines formed by taking roads or just straight lines between the points? For straight lines there are formulas to give distance between lat/longs, for wiggly lines you just have to map it because without the map you don’t know the route and you don’t know the distance.

Non-wiggly straight lines would be more useful than their absence. If I have lat and long coordinates for my starting points and then I insert a third point that’s sort-of along-the-way, and I have lat and long for that as well, is there a formula that lets me adjust the distance (which I already know) between the original two points to accommodate the third point?

The goal is to do a bunch of them mathematically rather than painstakingly inputting each set of three into a mapping website to have it calculate it for me.

I don’t think there’s anything easier than, in your example, dist(NY to X) + dist(X to LA) - dist(NY to LA). Here’s a formula for the distance between two cities, given their latitude and longitude, adapted from here:

D = (radius of Earth)·cos[sup]-1[/sup](sin(lata)·sin(latb) + cos(lata)·cos(latb)·cos(lonb-lona))

The arccos function will need to return a value in radians. If you’re going to make an Excel spreadsheet (or similar) with this, you’ll need to convert your latitudes and longitudes to radians before you take their sine or cosine. (Also, you may need to convert the lat/lon from degree-minute-second to decimal degrees. Also also, you may need to convert South latitude and West longitude to negative degrees.)

Fortunately, the table I’ve got — which converts US zip codes to lat and long — uses decimal configuration including negative vs positive.

Kimble, I think I can do this in FileMaker.

Note that the question in the title is not the same as the question described in the text of the OP. The distance of the intermediate point from the direct route is only relevant if the best path to the intermediate point is the same as the direct route. While this may be true if most of the route is high-value roads like interstates and the intermediate point is close to the interstate, it might also not be true (for instance, maybe the best route to get to the intermediate follows a different interstate, or maybe the intermediate is midway between two exits, so you won’t be getting back on the direct route at the same point you left it).

Kimble’s method is the answer. If you have an airplane. For road trips it’s substantially more complex.

It’d be pretty easy to see that a road trip NYC-Seattle-LA is going to be a longer flight or drive than NYC-Phoenix-LA. Any idiosyncrasies in the US road network are overwhelmed by the huge difference in the crow-flies geometric distance of the two routes.

Where it gets difficult is deciding whether NYC-Cleveland-LA is farther than NYC-Little Rock-LA.

You could easily find that the crow-flies geometric distance is 150 miles farther to Cleveland than Little Rock. But because of the layout of the Interstates, driving via Little Rock is a 100 mile longer drive than via Cleveland.

The only way to get the right answer is to plug it into a mapping app and see what actual routes and route mileages come out.

Late add: Agree with Chronos; the OP’s title is a different question altogether.

We often deal with the title question. e.g. as we go directly from NYC to LA, how far off to the side will Chicago be when we pass by it? Will it be to the left or the right? And how far off to that side will it be?

Not that that has much relevance to actually going there by plane or car.

Yeah, that’s just how I was trying to simplify it in my mind.

Having some formula-comprehension problems:

The “-1” you got in there…

cosign to the minus-one power of what follows in parentheses?
subtract one from the cosign?
the entirety of (radius of Earth)·cos to the minus-one’th power?

Yeah, my nonmathitude is showing.

is

(radius of Earth)·cos[sup]-1[/sup]

the same as

1 / ( (radius of Earth)·cos )

?

ETA: or perhaps the same as

(radius of Earth)· (1/cos)

??

The cos[sup]-1[/sup] is the inverse cosine function (i.e., cos[sup]-1/sup is the angle whose cosine is x). It’s also sometimes written “acos” or “arccos”, and is usually accessed on a calculator by pressing the “2nd” or “alternate” button followed by the “cos” button.

Trying to obtain distance from any point A to a point B based on lat and long of each.

Constant: radius of earth is input as 3959 miles.

Raw Data:

New Hyde Park NY (point A in all cases):
Lat 40.745347
Long -73.680292

Old Westbury NY (should be ~15 miles away)
Lat 40.786929
Long -73.596490

Stony Brook NY (should be ~ 35 miles away)
Lat 40.913360
Long -73.124883

Valdosta GA (should be a massively larger number of miles away)
Lat 30.848944
Long -83.289570

Formula Attempt A:
1 / (EarthRadius Sin(LatNHP) * Sin(Latitude) + Cos(LatNHP) * Cos(Latitude) * Cos(Longitude-LongNHP)) *

a) New Hyde Park appears to be .027 miles from itself
b) Old Westbury is .047 miles away
c) Stony Brook is somewhat closer than either one at -.0377 miles away
d) Valdosta is also at a negative distance, at - 0.0049 miles

OK, then. Formula Attempt B:
EarthRadius 1/ (Sin(LatNHP) * Sin(Latitude) + Cos(LatNHP) * Cos(Latitude) * Cos(Longitude-LongNHP))*

a) New Hyde Park is not 3959 miles from itself
b) Old Westbury is at 3976 miles.
c) Stony Brook is 4731.78 miles away. That makes it roughly 800 miles farther away than Old Westbury.
d) Valdosta sits at 5112.978 miles away
Formula help, please?

Is my problem here, perhaps?:

Is that a separate process that I need to do mathematically before I can go on with the formula?

Or is it just my misinterpretation of the formula itself that’s in need of adjustment?

Sorry, Chronos’ post wasn’t in place when I was typing that mess out.

OK, good, “cos-1” is the same as acos. I have an acos function!

new formula:

EarthRadius* Acos (Sin(LatNHP) * Sin(Latitude) + Cos(LatNHP) * Cos(Latitude) * Cos(Longitude-LongNHP))

Results:

New Hyde Park is 0 miles from itself (that’s good)
Old Westbury is 369.521 miles away (ouch)
Stony Brook is at 2294.639 miles
Valdosta is 2712.634 miles

something still aint’ right

Aha! There’s a custom function for it!

~5 miles to Old Westbury (closer than I realized but google maps confirms)
~ 30 miles to Stony Brook
868.59 miles to Valdosta
and 0 miles to itself.

Now that I can do that, I can use global fields to input any selected Point B and compare that distance to the distance from Point A to each Point C. Yay!

Yay!

You ninja’d me with the custom function, but FWIW, FileMaker has a Radians() function that will convert your latitude measurements from degrees to radians, where 2*pi radians = 360 degrees. This formula would work:

EarthRadius* Acos (Sin(Radians(LatNHP)) * Sin(Radians(Latitude)) + Cos(Radians(LatNHP)) * Cos(Radians(Latitude)) * Cos(Radians(Longitude)-Radians(LongNHP)))

(I hope I didn’t mess up any parentheses in there.)

Also, everything LSLGuy and Chronos said is right. This is just a gross estimate that could be very wrong in certain cases. Doing anything that’s accurate would probably involve writing a program that connects to Google Maps and gets directions to the locations you specify. But if what you have works for you, that’s great. :slight_smile: