5

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?

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323

1 Answers1

9

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574