computeCentroid method

Polygon computeCentroid()

Computes the centroid for this polygon.

Implementation

Polygon computeCentroid() {
	final centroid = this.centroid;
	HalfEdge? edge = this.edge;
	int count = 0;

	centroid.set( 0, 0, 0 );

	do{
		centroid.add( edge!.vertex );
		count ++;
		edge = edge.next;
	} while ( edge != this.edge );

	centroid.divideScalar( count.toDouble() );

	return this;
}