# the center of a polygon

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

given n coordinates, how do you calculate the center of the polygon they compose? at first i thought you just sum up the X's, sum up the Y's, and divide by n. but that's wrong, because if i have 999 coordinates at (0,0), and one at (1,1), the center would be at (0.0001,0.0001),and not at (0.5,0.5), as i would have liked it to be... help, please? thanks, noam

##### Share on other sites
find the extents (minimum/maximum in each axis), then average the min/max.
eg, centerX = (maxX + minX) / 2.0f

##### Share on other sites
Quote:
 Original post by Anonymous Posterfind the extents (minimum/maximum in each axis), then average the min/max.eg, centerX = (maxX + minX) / 2.0f

That is not correct.

The only way to do this is to split the polygon into trinagles. Then you do something like this:

center = Vector(0,0)area = 0for triangle in triangles:	center += tirangle.getArea()*triangle.getCenter()	area += tirangle.getArea()center /= area

##### Share on other sites
Considering there are about a million different ways you can define the "center of the polygon", you'll need to be more precise about what kind of center you want. In-center, ortho-center, circum-center, center of mass, etc.

##### Share on other sites
the first way, though simple, works finr for me :)

##### Share on other sites
Quote:
 Original post by No_Germsthe first way, though simple, works finr for me :)

The method the AP posted finds the center of the axis aligned bounding box of the polygon not the center of the polygon.

##### Share on other sites
yes, i knew it, but i gave it a chance, and it works fine for what i need, so i'll settle for that... :)

##### Share on other sites
Quote:
 Original post by No_Germsgiven n coordinates, how do you calculate the center of the polygon they compose?at first i thought you just sum up the X's, sum up the Y's, and divide by n. but that's wrong, because if i have 999 coordinates at (0,0), and one at (1,1), the center would be at (0.0001,0.0001),and not at (0.5,0.5), as i would have liked it to be...help, please?thanks, noam

Your "example" of a possible polygon doesn't really work. The vertices of a polygon must be unique; if they aren't, it violates the definition of a polygon: "a closed plane figure with n sides and n vertices".

##### Share on other sites
Quote:
 Original post by No_Germsyes, i knew it, but i gave it a chance, and it works fine for what i need, so i'll settle for that... :)

Are you sure? Consider this "boomerang" polygon, where the vertices are marked with *'s. The bounding box is enclosed in #'s. The "x" marks the center of the bounding box. But notice that x isn't even inside the polygon!

##########################                       ## *-------------------* ##  -----              | ##       -----         | ##            ----*    | ##                 |   | ##           x     |   | ##                 |   | ##                  | |  ##                  | |  ##                  | |  ##                   *   ##                       ##########################

##### Share on other sites
The center of a polygon is not necessarily in the polygon. It really all depends what you mean by "center". "Center" is not really a mathematically precise term... it has lots and lots and lots of interpretations. In the case of the geometric centroid (the most common interpretation for this type of figure), the center of mass of a boomerang is indeed outside the boomerang itself. What really matters here is how you intend to USE the "center point".

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633351
• Total Posts
3011476
• ### Who's Online (See full list)

There are no registered users currently online

×