how to calculate Center of mass/gravity for circles
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!