geom.centroid
drafting: C = geom.centroid (P)
Area centroid of a simple polygon.
C = geom.centroid (P) returns the centroid of the polygon
whose vertices are the rows of the -by-2 matrix P, as the
1-by-2 row vector [x, y].
This is the area centroid, not the mean of the vertices. The two
differ whenever the vertices are unevenly spaced around the outline: for the
L-shaped polygon [0, 0; 4, 0; 4, 2; 2, 2; 2, 4; 0, 4] the area
centroid is [1.667, 1.667] while the vertex mean is [2, 2].
The area centroid is the one that behaves as a balance point.
The polygon is implicitly closed and its orientation is irrelevant, since the sign of the area cancels.
A polygon of zero area has no defined centroid and raises an error.
See also: geom.signedarea, geom.bbox
Source Code: geom.centroid
The centroid of the enclosed area, which for an L-shape lies well away from the centre of its bounding box --- and outside the material for a shape concave enough.
L = [0, 0; 60, 0; 60, 15; 20, 15; 20, 50; 0, 50]; C = geom.centroid (L)
C = 21.250 18.438
D = draw.Drawing ().polyline (L, true);
D.Colour = 'red';
D.Linetype = 'CENTER';
D = D.centremark (C, 8);
plot (D);
title ('the centroid of an L-shaped section');