% -------------- center_gravity_1.m ------------- %
clear; clf
% 잠자리의 x좌표 데이터
x =[0.3; 0.5; 0.5; 7.5; 8.4; 0.8; 0.3]; % 잠자리의 y좌표 데이터
y=[-12.0; -5.6; -3; 1.6; 6.7; -1.5; 0]; % y축 대칭 데이터
x2 = -x(end:-1:1); y2 = y(end:-1:1);
nx = [x; x2; x(1)]; ny = [y; y2; y(1)];
plot(nx,ny,'bo-','LineWidth',1.8); hold on; axis image
% 보조선
culur = [0.4 0.4 0.4];
for i=-10:0.5:10
plot([i, i], [-15, 8],'LineWidth',0.5, 'Color', culur)
end
for i=-15:0.5:8
plot([-10, 10], [i, i],'LineWidth',0.5, 'Color', culur)
end
for i=-10:10
plot([i, i], [-15, 8],'LineWidth',1.5, 'Color', culur)
end
for i=-15:8
plot([-10, 10], [i, i],'LineWidth',1.5, 'Color', culur)
end
% 잠자리의 면적
A = 0.5*abs(sum(nx(1:end-1).*ny(2:end)-nx(2:end).*ny(1:end-1)));
% 잠자리의 무게중심 x좌표
Cx=sum((nx(1:end-1)+nx(2:end)).*(nx(1:end-1) ...
    .*ny(2:end)-nx(2:end).*ny(1:end-1)))/(6*A);
% 잠자리의 무게중심 y좌표
Cy=sum((ny(1:end-1)+ny(2:end)).*(nx(1:end-1) ...
    .*ny(2:end)-nx(2:end).*ny(1:end-1)))/(6*A);
% 무게중심 그리기
plot(Cx,Cy,'ro','MarkerFaceColor','red')

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: