4

In my application i need to find mid point of some number(3 or more) of GPS points.

i have find the distance between the two points as below

public class DistanceOfGeoPoints {
     public static long distanceinKMeters(double dblLat, double dblNewLat, double dblLong, double dblNewLong)
     {
         try
         {
             //double dblDistance = 180 / (dblPI * Math.Acos(Math.Sin(dblLat) * Math.Sin(dblNewLat) + Math.Cos(dblLat) * Math.Cos(dblNewLat) * Math.Cos(dblLong - dblNewLong)));

             double dblDegree2Radius = Math.PI / 180;
             double dbllongdiff = (dblNewLong - dblLong) * dblDegree2Radius;
             double dbllatdiff = (dblNewLat - dblLat) * dblDegree2Radius;
             double a = Math.pow(Math.sin(dbllatdiff / 2.0), 2) + Math.cos(dblNewLat * dblDegree2Radius) * Math.cos(dblLat * dblDegree2Radius) * Math.pow(Math.sin(dbllongdiff / 2.0), 2);
             double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
             double dblDistance = 6367 * c; //Earth Radius * value (result in KM)

             // return dblDistance;
             long intdistance = (Math.round(dblDistance * 1000));

             return intdistance;
         }
         catch (Exception ex)
         {
             return 0;
         }
     }
}

Now i want the mid point of the N number of GPS points

Please help me out.

4

1 回答 1

5

The midpoint of two points in Euclidean distance is just the average of the x and y coordinates. If we just average the Latitude and Longitude of points A and B, this gives us a point between A and B, but it need not be equidistant.

What you probably want is to convert the spherical coordinates to euclidean coordinates, find the midpoint by averaging x and y, then convert back to latitude, longitude.

If we do this with more than 2 points, we need to clarify what is meant by "midpoint."

If we wish to find the midpoint of N points in Euclidean geometry, we just average all of the x-values and average all the y-values. This gives us a reasonable "middle," but this average point is usually not equidistant to all three points. Given three points, we can calculate a unique point equidistant to those three; this point is the circumcenter of the triangle defined by the three points. But since three points define a circle, this process does not generalize to n-points. Given 4 or more point, there is probably no point equidistant to all 4. This is true whether we are working with eculidean distance or spherical geometry distance.

In the diagram below, we can see that the circumcenter point is exactly 5 units from points A, B, and C. Yet this point does not really feel like the "middle." The midpoint defined by average, on the other hand, does look like it's in the middle even though it is closer to A than to B or C.

Midpoint of three points

For n points defined by (lattitude, longitude), the best method is probably to convert all of these points to Euclidean points, computer the average, then convert back to (lattitude,longitude.) Some code for doing this conversion can be found here: Processing Forum And there is a good wikipedia page explain the background math that you need to understand.

于 2012-12-20T14:06:10.667 回答