How to use linear interpolation estimate current position between two Geo Coordinates?

Mark Renouf picture Mark Renouf · Nov 15, 2009 · Viewed 7.1k times · Source

I have the following available:

  • last reported lat,lon w/timestamp
  • target lat,lon
  • estimated time to target
  • heading

How can I interpolate an estimated position over time?

I know that's enough to calculate the required average velocity for the remainder of the trip. Given a straight-line distance, it's pretty trivial. I know it has to do with vectors but I'm a bit rusty and thought it better to consult some experts.

The reason I need this update rate is limited, so to show smooth animation I need to guess at the current position between updates.

The target platform is a Google Maps application so I have available some basic functionality like a Geo-correct function for distance between two coordinates. Language is unimportant as I know many and can port or adapt any examples if needed. General solutions would be preferred however.


Is this simply two independent vector calculations?

latestimate = latstart + (Δlat * P)
lonestimate = lonstart + (Δlon * P)

Where:
   testimated = the reported estimated time to target
   telapsed = time since last time estimate
   P = telapsed / testimated
   Δlat = latreported - lattarget
   Δlon = lonreported - lontarget

Answer

comingstorm picture comingstorm · Nov 16, 2009

You want to use a Slerp, or spherical linear interpolation.

Convert your latitude and longitude to a unit 3-vector:

p=(x,y,z)=(cos(lon)*cos(lat), sin(lon)*cos(lat), sin(lat))

Then, "Slerp" gives you a constant-velocity interpolation along the surface of the unit sphere:

theta= angle between 3-vectors p0 and p1 (e.g., cos(theta)= p0.p1)
Slerp(p0,p1,t)= ( p0*sin((1-t)*theta) + p1*sin(t*theta) ) / sin(theta)

Note that if theta is very close to 0 or 180 degrees, this formula can be numerically unstable. In the small-angle case, you can fall back to linear interpolation; in the 180 degree case, your path is genuinely ambiguous.