# Compute centroid of a polyhedron

## Alec Jacobson

## February 18, 2014

I ran into a concise algorithm for compute the centroid (center of mass) of an arbitrary closed 3D polyhedron. If you have a closed triangle mesh with vertices `V`

and faces in `F`

then here's an implementation in matlab:

```
% Rename corners
A = V(F(:,1),:);
B = V(F(:,2),:);
C = V(F(:,3),:);
% Needs to be **unnormalized** normals
N = cross(B-A,C-A,2);
% total volume via divergence theorem: ∫ 1
vol = sum(sum(V(F(:,1),:).*N))/6;
% centroid via divergence theorem and midpoint quadrature: ∫ x
C = 1/(2*vol)*(1/24* sum(N.*((A+B).^2 + (B+C).^2 + (C+A).^2)));
```