how to calculate Center of mass/gravity for circles
Show older comments
I am trying to calculate Center Of Mass (Center of Gravity) of buttons. But I could not get correct answers. My code for (b) of the attached file is as follow.The statement of the question is: "Assume that each particle’s weight for all buttons is equal, find the COM for all buttons. Display the position with red “*” in the original image" Can anyone check the coding?
% (b) Centre of mass for all buttons with equal mass (assuming 1)
D=imfill(C,'holes'); % remove noise from within circles obtained figure(3), imshow(D) [L7,num7]=bwlabel(D); stab=regionprops(L7,'Centroid'); for m=1:num7 a=stab(m).Centroid; r(m)=a(1); c(m)=a(2); end figure(4), imshow(D) hold on plot(r,c,'r*') axis on
% Show Centroids for i=1:num7 fprintf(['\n The centroid of object no. ',num2str(i),' is (',... num2str(round(r(i))),' , ',num2str(round(c(i))),')\n']) end mean_x=mean(r); mean_y=mean(c); fprintf(['\n COM of Buttons with equal weights = ( ',num2str(round(mean_x)),' , ',... num2str(round(mean_y)),' )\n']) figure(5), imshow(A) hold on plot(mean_x,mean_y,'r*') axis on
Answers (1)
Andrea Molina
on 21 Jan 2014
0 votes
Hi, check this answer!
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!