Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Triangulating GPS coordinates

Tags:

math

geometry

gps

Say you have n GPS coordinates how could you work out the central GPS point between them?

like image 297
Malachi Avatar asked Feb 24 '09 21:02

Malachi


1 Answers

In case it helps anyone now or in the future, here's an algorithm that's valid even for points near the poles (if it's valid at all, i.e. if I haven't made a silly math mistake ;-):

  1. Convert the latitude/longitude coordinates to 3D Cartesian coordinates:

    x = cos(lat) * cos(lon)
    y = cos(lat) * sin(lon)
    z = sin(lat)
    
  2. Compute the average of x, the average of y, and the average of z:

    x_avg = sum(x) / count(x)
    y_avg = sum(y) / count(y)
    z_avg = sum(z) / count(z)
    
  3. Convert that direction back to latitude and longitude:

    lat_avg = arctan(z_avg / sqrt(x_avg ** 2 + y_avg ** 2))
    lon_avg = arctan(y_avg / x_avg)
    
like image 120
David Z Avatar answered Oct 22 '22 03:10

David Z