• Jan 18th 2010, 10:18 AM
MarkH748
Hi,

I am writing a program where I need to work out the centroid of a quadrilateral given the coordinates of its 4 corners. I know this can be done graphically quite easily but I was wondering if there is a formula I can use to code it?

Mark.
• Jan 18th 2010, 08:02 PM
Wilmer
• Jan 20th 2010, 04:00 AM
HallsofIvy
Here's one way to do it: draw either of the diagonals, dividing the quadrilateral into two triangles. Triangles have the nice property that the centroid of a triangle is the average of the three vertices- that is, add each the x coordinates of the three triangles, the y coordinates, and the z coordinates (if this is in three dimensions) and divide by three. Those three averages will be the x, y, and z coordinates of the centroid of the triangle.

Once you have the centroids of the two triangles, the centroid of the quadrilateral is the weighted average of the two points, weighted by the area of the triangles. That is, if $P_1= (x_1, y_1, z_1)$ and $A_1$ are the centroid and area, respectively, of the first triangle, and $P_2= (x_2, y_2, z_2)$ and $A_2$ of the second triangle, then the centroid of the quadrilateral is $\frac{A_1P_1+ A_2P+2}{A_1+ A_2}$ $= \left(\frac{A_1x_1+ A_2x_2}{A_1+ A_2}, \frac{A_1y_1+ A_2y_2}{A_1+ A_2}, \frac{A_1z_1+ A_2z_2}{A_1+ A_2}\right)$
• Jun 22nd 2013, 01:25 PM