Center of a polygon

BlitzMax Forums/BlitzMax Programming/Center of a polygon

Ratchet(Posted 2012) [#1]
How to calculate the center of a polygon?
Got polygon data as array like DrawPoly parameter needs.


Derron(Posted 2012) [#2]
Regular Polygons would be easy...irregular ones..

Try something like creating a hull.
Or something like: search to points with the largest distance, the center of that line is the point where a circle would cover all polygon points.

But in general: irregular polygons don't have a center.

At http://mayastation.typepad.com/maya-station/2009/11/where-is-the-center-of-a-polygon.html

Someone suggests to use weighted points to get an average center.


So to conclude: you won't be able to do it in a feasonable time so look for a method to do it "quick and dirty".

bye Ron


Ratchet(Posted 2012) [#3]
Guess I will do the hull thing, calculate a rectangle from the maximum coordinates. That would do it.


matibee(Posted 2012) [#4]
If you wanted an accurate centre of gravity my experiments with the glu tesselator would be useful (http://www.blitzbasic.com/Community/posts.php?topic=97548)

Step 1: Tesselate the polygon
Step 2: Find the average point of each triangle
Step 3: Average the averages

The glu functions are not reliant on OpenGL so it doesn't matter what graphics driver you're using. Plus it's really fast.

In reality you'll probably find that averaging all points will be good enough.


Derron(Posted 2012) [#5]
Instead of an rectangle hull I think a circular one would fit better...

The longest Distance between two points contains at its middle the center of the circle... the half of this distance would be the radius.
so you have to do some calcs ...
Point A to Rest,
Point B to Rest but A,
Point C to Rest but A,B ...

There are surely some better procedures but thats the simplest one.

bye
Ron