# Calculating speed given change in latitude/longitude over time?

I'm writing a program that takes in two latitudes and longitudes and the time taken to reach the destination. The program then outputs the estimated speed of the moving object. The location of the object is the only information available.

Update:

@Howard:

Thanks. The problem is I want the straight-line (loxodrome) distance, along an ellipsoid (not a perfect sphere).

Update 2:

@bpiguy:

Thank you! At least your answer was better than Howard's. For that, I gave you a thumbs-up. Spherical trigonometry's not too terrible, it's just not as accurate as formulas for oblate ellipsoids. And I want my program to be as accurate as it can (without using too much CPU)

Update 3:

One more thing, Howard:

I asked for a formula, not a calculator.

Relevance

If you don't use the "great circle calculator," here's how to do it.

First, you need to translate latitude/longitude to a position vector in three dimensions. Here's how to do that. Let's use latitude 30° N and 75° W as an example. (Draw a 3D coordinate system to visualize this, where the xy plane is the equatorial plane, and the z direction gives you latitude.) Project the point P onto the equatorial plane using ρ = r cos 30, where r is the radius of the earth (3960 miles). The z-coordinate of P is r sin 30.

Now get the x and y coordinates. The x-coordinate is ρ cos 75 = r cos 30 cos 75, and the y-coordinate is ρ sin 75 = r cos 30 sin 75. Your position vector is P = <(r cos 30 cos 75)i + (r cos 30 sin 75)j + (r cos 30)k>. Repeat this procedure for your other point Q. You'll end up with two position vectors P and Q.

The great circle distance between two points P and Q on the earth's surface is rθ, where r is the radius of the earth and θ is the angle between the position vectors P and Q. (θ is the central angle between the vectors at the earth's center.)

You get the angle θ by using a marvelous device called the "dot product" of the two position vectors. The formula is P dot Q = (magnitude of P) (magnitude of Q) cos θ. Since both magnitudes equal r. we have cos θ = (P dot Q) / r^2. And since r is a factor in each of the two position vectors, the r's cancel out. (And you can remove r from the formulas in your computer program.)

If your two position vectors (with the r's removed) are P = <ai + bj + ck> and Q = <di + ej + fk>, then

P dot Q = ad + be + cf, so cos θ = ad + be + cf (with the r's removed).

Once you have θ by this method, then your great circle distance is simply rθ. And be sure to use radian measure for θ.

That's how to do it, thanks mostly to the dot product operation. (The alternative is probably spherical trigonometry, and that's got to be awful, IMO.)

[Edit: Montana, I saw your note. Thanks for the "thumbs up." I sure don't know anything about oblate ellipsoids, except that they exist, so I can't help any more. Good luck with your program. End edit.]

Source(s): I've done this exercise quite a few times, e.g., the distance between New York and Rome. It's quite marvelous, and I think relatively few people know how to do this procedure.
• I'll save you the trouble. Here's a great circle calculator. Just divide the distance traveled by the time.