From: Ron Parker <ron@pa...>  20060127 21:15:52

Beverly Howard wrote: > a tp (a) where ((wp_lat  tp_lat) + (wp_long  tp_long)) is the lowest > > a tp (b) where ((tp_lat  wp_lat) + (tp_long  wp_long)) is the lowest That's what's called "taxicab" or "L1" distance. If you're going to do it that way, you should instead use the Pythagorean or L2 distance (square root of the sum of the squares.) However, if you're writing code for GPSBabel, you don't need to do that. There's already a gcdist (great circle distance) function defined in grtcirc.c. It's about as accurate as you can get while still pretending that the Earth is a sphere. There's also a linedist function that will determine the distance to the closest point on a line segment, which is actually far more useful for this task. > I naively assume that (for at least a fairly straight track) that the > waypoint would be between the two trackpoints and that it's "time" > would be the proportional difference between the two trakpoint's times. You can do a little better than that, actually; it's not too hard to compute the actual closest point on the line. You should even be able to adapt some of the code from the linedist function to compute that point for you, if you can make sense of the math. (Perhaps surprisingly, I can compute the distance from the line segment without ever completely calculating the location of the closest point.) One problem might be that the closest approach to the waypoint actually is a single trackpoint. That'd happen if the track has been simplified. If you're adapting the linedist code, you can easily catch that case too; linedist already has to. 