Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
I'll note that I used this routine previously to help with coloring the proposed mathematica.SE logo... – J. M. 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. Jun 30 '12 at 14:35
@J.M. Ahhh! The infamous pointlike massless cow ... – belisarius has settled 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.