how to calculate Center of mass/gravity for circles

10 ビュー (過去 30 日間)
Ramon
Ramon 2014 年 1 月 21 日
回答済み: Andrea Molina 2014 年 1 月 21 日
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

回答 (1 件)

Andrea Molina
Andrea Molina 2014 年 1 月 21 日

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by