Hi:

what is the function to calculate center of mass or

centroid of a 2d object.

Thank

NBT

Hi:

what is the function to calculate center of mass or

centroid of a 2d object.

Thank

NBT

what is the function to calculate center of mass or

centroid of a 2d object.

Thank

NBT

do you have the coordinates of each point on the object? what about

the weight of each point? if you have those, then its just a trivial

sum (the definition of centroid).

-noob

I have the coord. of each point, actually it is b/w nonsymatical

image taht I try to find the center of the image.

How I go about to use sum. I get rusted on the math stuff.

thanks

---------------------------

In your problem, NBT, it is important to distinguish between two

possibilities. One is that you consider your points to be mass points and

you want the simple center of mass of the points themselves. If all the

points have the same mass, then, as Noob indicated, it is a simple matter

of taking the means of the x and y coordinates.

However, if what you want is the area centroid of the entire interior

region surrounded by a polygon running through the points, that is a very

different problem. Here is a function I gave someone else on CSSM some

time ago. I have reason to believe there are some functions in MathWorks'

File Exchange that do the same thing, but anyway here it is:

function [x0,y0,a] = centroid(x,y)

% x and y must be non-scalar column vectors of the

% same length defining a polygonal region in clockwise

% sequence. a is returned with the polygon's area, and

% (x0,y0) with the coordinates of the polygon's centroid.

% Note: with counterclockwise order, x0 and y0 are

% still correct but a is the negative of the area.

% RAS - 1/17/05

n = length(x);

x2 = [x(2:n);x(1)];

y2 = [y(2:n);y(1)];

a = 1/2*sum(x2.*y-x.*y2);

x0 = 1/6*sum((x2.*y-x.*y2).*(x+x2))/a;

y0 = 1/6*sum((x2.*y-x.*y2).*(y+y2))/a;

(Remove "xyzzy" and ".invalid" to send me email.)

Roger Stafford

Similar Threads

1. Center of mass / Center of gravity - MATLAB

2. center of mass of objects in a 3D box

Hello, I have created a 3D box with particles in it. These particles have odd shapes and I want to find the center of mass of each particle and then connect these centers. Could someone guide me how to do this? Many thanks in advance.

3. How to compute center of mass for an image - MATLAB

4. Calculating the Center of Mass of a 3D Binary Array/Matrix

Hi, I'm an undergraduate doing some some physics research. I apologize if this is the wrong group, but this is the only thing that popped up on google groups. Here is my task: 1) Import 10 images into matlab in binary format and superimpose them on top of each other 2) Put it back into Binary Format (because superimposing 10 images will yield overlaps and those overlaps values will now contain values that are greater than 1. 3) Find the 3D center of mass of the volumetric matrix The object I have is a tumor in 3 Dimensions - The tumor is bounded within a matrix that is 512,512,117. The tumor does not compromise the whole of the matrix, just a small portion. I thought the math behind finding the Center of Mass (CM) would be simple but after getting the equations down and pondering over it I realized that it wouldn't work. I've finished with steps 1 and 2 (quite easy). I wanted to do the following (not using the sum matlab function = sum() represents equals large-sigma with bounds) A = sum(mx)/M B = sum(my)/M C = sum(mz)/M where m = mass (or the value at the specified coordinate) where x = the x (or first) dimension where y = the y (or second) dimension where z = the z (or third) dimension where M = total mass over three dimensions (easy to do using a triple sum function in matlab) where (A,B,C) = will equal the new coordinates (in decimal format), but multiplying them by a multiplicative factor shoudl fix that ( a total guess) Major problems: I am keeping the two coordinates that I'm not summing over at a constant number (i.e. zero) If I do this, then all I am adding up/summing over are the outer edges of the matrix which don't contain the tumor (I know this for a fact). After researching on the internet, I have come to the conclusion that I am dealing with a centroid, something which I have never seen in my life. I'd appreciate any and all help, thank you.

5. Calculating the center of mass per line - MATLAB

Hi all, I need some help in finding out a way to calculate the center of mass of a waveform. I have seen a lot of posts about finding it for a triangle and a polygon, but I am not sure if I can apply that to a waveform. The waveform has 40 data points and you could assume it looks like the positive half of a standard sine wave. any help would be appreciated. Rahul Shingrani

8. faster way to calculate "center of mass" than using regionprops

hi guys, does anyone know if there is a faster way to calculate the center of mass of an image than using the Centroid property of the command regionprops. the image is an 240x320 rgb image. stats = regionprops(image, 'Centroid'); lasts at my computer system at least 0.5 sec. i need to be faster than 0.1 sec to calculate the center of mass. please help me. thanks. k.