how to calculate Center of mass/gravity for circles
조회 수: 7 (최근 30일)
이전 댓글 표시
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
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!