Welcome to MapForums!

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

## Find center of a polygon

This is a discussion on Find center of a polygon within the MapPoint Desktop Discussion forums, part of the Map Forums category; Does anyone know how, given the lat,lon coordinates of all the points around a polygon shape I can then find ...

1. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137

## Find center of a polygon

Does anyone know how, given the lat,lon coordinates of all the points around a polygon shape I can then find the center of that shape. I'm trying to do this in VB .net but if anyone knows the equation or how this should be down in the real world it may help

2. The centre of a polygon is called the polygon's centroid.
In Euclidean space, a centroid is calculated by converting the vectors to cartesian vectors (if they aren't already), summing them together, and dividing by N, where N is the number of points.

Eg. the centre of a triangle with points (x1,y1); (x2,y2); (x3,y3) is:

Centroid X coord = (x1+x2+x3) / 3
Centroid Y coord = (y1+y2+y3) / 3

Depending on the size of your polygon and the acceptable errors, you could do this with longitudes and latitudes. I wouldn't even think about doing this near the poles, or anything bigger than about 100 miles. Your tolerances for errors might be greater or less though.

To do it "properly", you might be able to find a weighted addition for lat,long. Or you could convert each coordinate into 3d cartesian coords relative to the Earth's centre (this is simple trigonometry).
Do the add/divide, then convert back again.
Just before converting back, you may have normalise to bring the centroid onto the Earth's surface.

Richard

3. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137
Thanks for your help, this appears to work well and we don't really need a huge degree of accuracy, however I might try it as you suggested with 3d catesian coords, doesn't appear too much more work and if its going to increase the level of accuracy then I may as well put it in.

4. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137
Sorry just one more thing, given the lat, lon coords of both ends of two straight lines how can I determine if the lines cross or not. (I really should have paid more attention in Maths class!)

5. In Cartesian coordinates, you with a cross product I think. I'd have to look it up (the Graphics Gems series are good for that type of thing).

For "on a sphere", the Aviation Forumlary is a good source:

http://williams.best.vwh.net/avform.htm

The "Intersecting Radials" formula looks like it would be a good start, although it defines the lines as bearings from start points.

Richard

6. Senior Member Black Belt
Join Date
Jul 2002
Posts
5,137
Thanks for your help, just had a quick look at the link you sent and I think it covers a lot of the areas i'm looking for.

7. Yes, I find it a useful reference - probably one of my most useful "reference" bookmarks.

Richard

8. Junior Member White Belt
Join Date
Apr 2003
Posts
7
Originally Posted by Winwaed
The centre of a polygon is called the polygon's centroid.
In Euclidean space, a centroid is calculated by converting the vectors to cartesian vectors (if they aren't already), summing them together, and dividing by N, where N is the number of points.

Eg. the centre of a triangle with points (x1,y1); (x2,y2); (x3,y3) is:

Centroid X coord = (x1+x2+x3) / 3
Centroid Y coord = (y1+y2+y3) / 3

Depending on the size of your polygon and the acceptable errors, you could do this with longitudes and latitudes. I wouldn't even think about doing this near the poles, or anything bigger than about 100 miles. Your tolerances for errors might be greater or less though.
Richard
Hi Richard. Are you saying that the formula for a polygon with n points in decimal degrees is close to :

X = (x1 + x2 + x3 + ... + xn)/n ?

I found some other formula, but I'm not sure is this applies to geographic coordinates as it requires an A (area) calculation:

// X = SUM[(Xi + Xi+1) * (Xi * Yi+1 - Xi+1 * Yi)] / 6 / A
// Y = SUM[(Yi + Yi+1) * (Xi * Yi+1 - Xi+1 * Yi)] / 6 / A
// Here A is the area of the polygon and the sum is taken over all points 0 to n-1 where n = number of polypoints.
// BUT A is then in square hours ?

Couldn't find anything on polygons on the link you sent

9. The link was with reference to the second question about crossing lines.

The formula I gave for a centre-of-a-polygon is based on 2d Euclidean coordinates. It can be easily extended to 3 (or more) dimensions by performing the same calculation for the extra ordinates.

For longitude and latitude with some accuracy, I would consider converting your longitude,latitudes into Earth-centred Cartesian coordinates, finding the centroid, and then projecting back to the Earth's surface (the centre of a polygon on the Earth's surface will be inside the Earth).
Note that this might become unstable if you have coordinates over a wide area - ie. if the calculated centroid is near the centre of the Earth.

I'm not sure what the formula that you give, does. With an area calculation, does it measure somekind of point density????

Richard

10. Junior Member White Belt
Join Date
Apr 2003
Posts
7
Hi,

(this also mentions: some programs calculate the centroid by averaging the x and y coordinates of the polygon vertices
this does not give the centroid)

maybe your formula only works for regular polygons (octagons, etc)?

I'm still clueless.

Page 1 of 2 12 Last