### centroid?

This is kind of embarrassing, but can anybody write out, in plain English, the centroid equation? I know there’s a snappy one in Lcent, but I need to do it in java, and I can’t work out how to get Dr. Elsea’s little equation to work… I’m not a mathematician by any stretch of the imagination, so all the equations I’ve found online wind up giving me some funky characters that are truly Greek to me (literally). Ssomething like "sum the list, take the average, and…" as an explanation would be brilliant.

Thanks in advance.

J.

Hi,

I think it’s like a weighted mean of the list values against its indices.

So…

1) compute the sum of each list element multiplied by its index

(presumably indexing from 1, not zero)

2) compute the sum of the list values

3) Divide (1) by (2)

So, something along the lines of:

float weightedsum = 0;

float sum = 0;

for(int i=0; i< mylist.length; i++)

{

weightedsum += (i+1) * mylist[i];

sum += mylist[i];

}

return (weightedsum / sum);

–

Owen

jbmaxwell wrote:

> This is kind of embarrassing, but can anybody write out, in plain

> English, the centroid equation? I know there’s a snappy one in Lcent,

> but I need to do it in java, and I can’t work out how to get Dr.

> Elsea’s little equation to work… I’m not a mathematician by any

> stretch of the imagination, so all the equations I’ve found online

> wind up giving me some funky characters that are truly Greek to me

> (literally). Ssomething like "sum the list, take the average, and…"

> as an explanation would be brilliant.

>

> Thanks in advance.

>

> J. _______________________________________________ maxmsp mailing

>

You rock.

That sounds about right to me… I know it’s supposed to give an interpolated index representing the "centre or gravity" of the list, so it would have to acknowledge the indices (and acknowledge zeros), that is to say, I think you’ve got the idea! I’ll give your code a shot a little later.

Thanks as always, Owen.

J.

Right, cool. So the only change is that it is indexing from 0 rather than 1. Other than that, you were on the money!

cheers,

J.

ah, to start at 0 or 1, the age old battle.

heh… the Romans had it sussed, in that regard. Though they would have had a hell of a time getting fuzzy logic to work!

J.

But in that case, it makes sense: if you use 0, you ignore the first value.

> ah, to start at 0 or 1, the age old battle.