Finding the Center of Mass

Thanks to Pau Santos who requested a Physics 71 review two weeks ago, I was able to relearn the art of locating the center of mass.


Equation for locating the center of mass


Say we have a binarized image of an object, assuming that it has uniform density and symmetrical along the axis perpendicular to the plane of the image, we can find its center of mass with this simple bit of code in Scilab:

First we find the pixels representing the object

x = Img;
xcoord = linspace(1,size(Img,2),size(Img,2));
for i = 1:size(Img,1)
    x(i,:) = x(i,:).*xcoord;

Finally, computing for the center of mass

xcom = sum(x)/sum(Img);

I guess with ndgrid() we can make the code shorter by eliminating the for() loop.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s