# Math Help - Centroid of a Quadrilateral?

1. ## Centroid of a Quadrilateral?

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?

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)$