1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| function [ CDG ] = B_calcul_cdg( XY_Noeud_func , Tri_func )
Poids_Tot = 0;
Somme = 0;
for i_func = 1:size(Tri_func,1)
Noeud_1 = Tri_func(i_func,1);
Noeud_2 = Tri_func(i_func,2);
Noeud_3 = Tri_func(i_func,3);
X_1 = XY_Noeud_func(Noeud_1,1);
Y_1 = XY_Noeud_func(Noeud_1,2);
X_2 = XY_Noeud_func(Noeud_2,1);
Y_2 = XY_Noeud_func(Noeud_2,2);
X_3 = XY_Noeud_func(Noeud_3,1);
Y_3 = XY_Noeud_func(Noeud_3,2);
Pt_1 = [X_1;Y_1];
Pt_2 = [X_2;Y_2];
Pt_3 = [X_3;Y_3];
CDG_Tri = (Pt_1 + Pt_2 + Pt_3) / 3;
Vect_1 = Pt_2 - Pt_1;
Vect_2 = Pt_3 - Pt_1;
Aire_Tri = abs((Vect_1(1)*Vect_2(2)-Vect_1(2)*Vect_2(1))/2);
Somme = Somme + Aire_Tri*CDG_Tri;
Poids_Tot = Poids_Tot + Aire_Tri;
end
CDG = Somme/Poids_Tot;
clear Noeud_1 Noeud_2 Noeud_3 X_1 Y_1 X_2 Y_2 X_3 Y_3 Pt_1 Pt_2 Pt_3
clear CDG_Tri Vect_1 Vect_2 Poids_Tot Somme
end |
Partager