Having 4 points A (ax, ay), B (bx, by), C (cx, cy) and D (dx, dy) that describe any quadrangular in 2D, with x and y in range [-100, 100] I would like to calculate point E (ex, ey), which would be a center of this quadrangular.

What algorithm can be used for such calculation and why?

The formula for a polygon's centroid is easily expressed in Mathematica:

PolygonCentroid[pts_?MatrixQ] := With[{dif = Map[Det, Partition[pts, 2, 1, {1, 1}]]},
ListConvolve[{{1, 1}}, Transpose[pts], {-1, -1}].dif/(3 Total[dif])]


This works for any Polygon[], not just quadrilaterals.

• I'll note that I used this routine previously to help with coloring the proposed mathematica.SE logo... – J. M. is away Jun 30 '12 at 14:32
• Thank you for prompt answer. Where can I find a algorithm/formula in simple math that can be used for coding in programming language such as C, Perl, etc.? – user1585 Jun 30 '12 at 14:33
• @Ωmega: I linked to the formula already; you should not have any trouble translating the formula to your computing environment of choice. If you do have trouble, then this site is not the place to ask questions not related to Mathematica. – J. M. is away Jun 30 '12 at 14:35
• @J.M. Ahhh! The infamous pointlike massless cow ... – Dr. belisarius Jun 30 '12 at 15:05
• @belisarius I immediately thought of spherical horses in vacuum when I read J.M.'s comment. – Heike Jun 30 '12 at 16:56