# What is a good algorithm, and framework, to calculate centres of gravity or mass (cog)?

I'd like to take an photograph, subdivide it into a tesselation, either of squares, or (ideally), hexagons, and then find the centre of gravity (or, if you prefer, centre of mass) of each cell of the tesselation.

The output, for any image, would be a matrix of points. For the attached diagram, something like this (in polar coordinates - $(r,\theta)$ ):

(5,5Π/4) (0,0) (1,7Π/4) (1,5Π/4)
(5,3Π/4) (0,0) (5,Π/2)
(0.0) (0,0) (0.0) (0,0)


I've attached an image showing what I mean.

My question, to put it simply, is the best method to use to calculate the cog, in this tessellation... For squares, it'd be easy to calculate the weighted mean for each row, but that would be too rough an approximation. What's a good way to iterate either a general tessellation (ideal), or an hexagonal one?

• Could you explain what you mean by mass in this context? Does it depend on the colour values of the hexagonal cells? Are you trying to find the centre of the light pixels/dark pixels/a particular specified colour? This is likely to affect the answer so it's worth giving as much detail as you have. – trichoplax Sep 9 '16 at 11:50
• Good question. Yes colour value is good enough. Actually I'll be working with B&W, so its really the cog of the ink. – Peter Brooks Sep 9 '16 at 14:32