getCenter function for polygons

Putting this into a PR since it's very useful for one of my projects as well.

Implementation taken directly from @Solider-Boy's comments.

References #1196