How to find Mid Point / Coordinates of some GPS points?

In my application, I need to find the midpoint of a certain number (3 or more) GPS points.

I will find the distance between two points 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 need the midpoint N of the number of GPS points

Please help me.

+4
source share
1 answer

The midpoint of two points at the 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 should 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 the "middle".

If we want to find the midpoint of N points in Euclidean geometry, we simply average all the values ​​of x and average all the values ​​of y. This gives us a reasonable “middle”, but this midpoint is usually not equidistant for all three points. Given three points, we can calculate a unique point equidistant for these three; this point is the circle of a triangle defined by three points. But since three points define a circle, this process is not generalized to n-points. Given 4 or more points, there is probably no point that is equidistant for all 4. This is true if we are working with distance distance of eulidian or spherical geometry.

The diagram below shows that the point of the circle is exactly 5 units from points A, B and C. But this moment really does not look like a “middle” one. On the other hand, the midpoint defined by the average looks like in the middle, although it is closer to A than to B or C.

Midpoint of three points

For n points defined (latitude, longitude), the best way is probably to convert all these points to Euclidean points, calculate the average, and then convert back to (latitude, longitude). Some code for this conversion can be found here: Processing the forum And there is a nice wikipedia page explaining the basic math you need to understand.

+5
source

All Articles