need help calculating point between two coordinates.

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Aug 14 06:58:30 EDT 2009


On Thu, 13 Aug 2009 14:26:54 -0700, PeteDK wrote:

> Hi there
> 
> I'am working on a route comparison tool for carpools.
> 
> The route comparison is based on 'steps' retrieved from google maps
> GDirection. These steps vary in length and i use the coordinates at the
> beginning of each "step". However, sometimes the distance of these steps
> is too long(ex. driving 30-40 km. on the freeway). Therefore i would
> like to calculate/find the coordinate located in between two given
> coordinates.
> Lets say one step starts at:
> 56.043185,9.922714
> and ends at:
> 56.234287,9.864521
> 
> I would then like to calculate the point right in the middle of these
> coordinates.

Can you assume that the coordinate system is virtually flat between those 
points? That is, are the distances small enough that the curvature of the 
earth isn't relevant?

If so, the following should be close enough:

def midpoint(a, b):
    """Return the two-dimensional point midway between points a and b."""
    x = (a[0] + b[0])/2.0
    y = (a[1] + b[1])/2.0
    return (x, y)

Otherwise, you can probably start here:

http://www.geomidpoint.com/methods.html

http://mathforum.org/library/drmath/results.html?contexts=drmath&levels=college&passed_id=51416&passed_title=College+Physics&search_cats=no&textsearch=spherical&textsearch_bool_type=and&topics=physics


-- 
Steven



More information about the Python-list mailing list