11,633,454 members (78,623 online)
Rate this:
See more:
hi to all

Posted 13-Jun-12 2:10am

Rate this:

## Solution 1

First of all define the "middle point" in terms of mathematical concepts.
If you mean the center of a polygon:
Regular Polygon case:
In the case of regular polygons the center is the point that is equidistant from each vertex or corner. It is also the center of the polygon's incircle and circumcircle.
Irregular Polygon case
Irregular polygons are not considered as having a center, since there is unlikely to be any one point equally distant form each vertex. However, an irregular polygon can have a centroid, or center of gravity.
If you mean the centroid of a polygon see this article: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/[^].
You can also calculate a vector mean, by calculating a mean for longitude and latitude values respectively.
v2

5+
Zoltán Zörgő at 14-Jun-12 2:21am

Thank you.
Rate this:

## Solution 3

this is a JavaScript function who get a Polygon and return a Point. you can use this function to calculate center of a Polygon.

Function:
```function getCenterOfPolygon(polygon){
var PI=22/7
var X=0;
var Y=0;
var Z=0;
polygon.getPath().forEach(function (vertex, inex) {
lat1=vertex.lat();
lon1=vertex.lng();
lat1 = lat1 * PI/180
lon1 = lon1 * PI/180
X += Math.cos(lat1) * Math.cos(lon1)
Y += Math.cos(lat1) * Math.sin(lon1)
Z += Math.sin(lat1)
})
Lon = Math.atan2(Y, X)
Hyp = Math.sqrt(X * X + Y * Y)
Lat = Math.atan2(Z, Hyp)
Lat = Lat * 180/PI
Lon = Lon * 180/PI
}
```

Use:
```var pt=getCenterOfPolygon(mapPolygon);
```
v2
kimberly ping at 24-Jan-15 0:06am

What is this algorithm called?
Rate this:

## Solution 2

Solution 1 is well detailed and thank you Zoltan

Below is simplified version

Consider polygon (Pentagon) with co-ordinates (x1,y1); (x2,y2); (x3,y3); (x4,y4); (x5,y5) then centroid should be

Centroid X coord = (x1+x2+x3+x4+x5) / 5
Centroid Y coord = (y1+y2+y3+y4+y5) / 5

You can use X as latitude and Y as longitude and can point Centroid.

If you are using any mapping tool/library then that library itself should have this functionality to create a polygon with centroid.

If you are creating any functionality on a DigitalMap then attached formulas might help you in future http://williams.best.vwh.net/avform.htm[^].

Cheers and best of luck!

Thanks
Rushikesh Joshi
v2

5+
Joshi, Rushikesh at 13-Jun-12 23:50pm

Thanks Wonde :)
Pardeep singh from Chandigarh at 14-Jun-12 3:21am

thanx for give me solution