November 23, 2006 | 11:36 pm

Hi,

I want to analyze a matrix (1 plane, 2 dimensions) and get coordinates of the centre of gravity. I can’t really explain it much clearer but here’s an example of what I want:

input:

1 0 0

0 0 1

0 0 0

output:

x=1, y=0.5

Another example:

2 0 0

0 0 1

0 0 0

output:

x=0.66, y=0.33

…I hope this is clear?

I think that the calculations should be something like this:

(0 * sum of all cells in row 0/ sum of all cells in matrix) +

(1 * sum of all cells in row 1/ sum of all cells in matrix) +

etc. = y

… and of course the same thing goes for the columns.

But how can I do this efficiently?

- Tarik