<p>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.</p>

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

<pre><code>(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)  
</code></pre>

<p>I've attached an image showing what I mean.</p>

<p><a href="https://i.sstatic.net/zQng6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zQng6.png" alt="Hexagonal tesselation. The black circles are the centres of gravity of each cell - in clear, or monochrome, cells it is in the centre of the cell. In those with a green splodge, the cog is pulled towards the splodge"></a></p>

<p>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?</p>

CC BY-SA 3.0
2016-09-09T11:50:24.430Z
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 is on Codidact now
CC BY-SA 3.0
2016-09-09T14:32:52.820Z
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
<opengl><gpu><mathematics><physics><polygon>
What is a good algorithm, and framework, to calculate centres of gravity or mass (cog)?
Peter Brooks
# What is a good algorithm, and framework, to calculate centres of gravity or mass (cog)?

(Asked by: username_0 on 2016-09-09)

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.

[![Hexagonal tesselation. The black circles are the centres of gravity of each cell - in clear, or monochrome, cells it is in the centre of the cell. In those with a green splodge, the cog is pulled towards the splodge](https://i.sstatic.net/zQng6.png)](https://i.sstatic.net/zQng6.png)

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?

**Tags:** opengl, gpu, mathematics, physics, polygon

> **Comments:**
> **username_1**: 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.  
> **username_0**: Good question. Yes colour value is good enough. Actually I'll be working with B&W, so its really the cog of the ink.  

---

## 0 answers

