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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
| % On vide la mémoire
close all
clear all
clc
%% Tolerances_A_C.m
% Version 4 : rotation du plan de la tolérance A afin de simplifier le
% reste de l'étude
%% DONNEES
% Nombre de points nominaux des anneaux
N = 360;
% Centre de l'anneau 1
x_1 = 0;
y_1 = 0;
z_1 = 0;
% Rayon max de l'anneau 1
R_max_1 = 15;
% Rayon min de l'anneau 1
R_min_1 = 12;
% Centre de l'anneau 2
x_2 = 0;
y_2 = 4;
z_2 = 0;
% Rayon max de l'anneau 2
R_max_2 = 30;
% Rayon min de l'anneau 2
R_min_2 = 25;
% Définition de l'anneau nominal 1 et 2
XAnneau_nom_1 = [];
YAnneau_nom_1 = [];
ZAnneau_nom_1 = [];
XAnneau_nom_2 = [];
YAnneau_nom_2 = [];
ZAnneau_nom_2 = [];
for VTheta = 0:(2*pi)/N:2*pi
p_1 = rand(1);
X_1 = x_1 + (R_min_1 + (R_max_1-R_min_1) * p_1) * cos(VTheta);
Y_1 = y_1 * ones(size(VTheta));
Z_1 = z_1 + (R_min_1 + (R_max_1-R_min_1) * p_1) * sin(VTheta);
XAnneau_nom_1 = [XAnneau_nom_1 X_1];
YAnneau_nom_1 = [YAnneau_nom_1 Y_1];
ZAnneau_nom_1 = [ZAnneau_nom_1 Z_1];
p_2 = rand(1);
X_2 = x_2 + (R_min_2 + (R_max_2-R_min_2) * p_2) * cos(VTheta);
Y_2 = y_2 * ones(size(VTheta));
Z_2 = z_2 + (R_min_2 + (R_max_2-R_min_2) * p_2) * sin(VTheta);
XAnneau_nom_2 = [XAnneau_nom_2 X_2];
YAnneau_nom_2 = [YAnneau_nom_2 Y_2];
ZAnneau_nom_2 = [ZAnneau_nom_2 Z_2];
end
% Définition des anneaux expérimentaux 1 et 2
Ordre = 1 / 10000;
Anneau_exp_1 = [XAnneau_nom_1; YAnneau_nom_1; ZAnneau_nom_1];
Anneau_exp_2 = [XAnneau_nom_2; YAnneau_nom_2; ZAnneau_nom_2];
for i_1 = 1 : N + 1
p_1 = rand(1);
Anneau_exp_1(2, i_1) = Anneau_exp_1(2, i_1) + 2 * Ordre * p_1 - Ordre;
p_2 = rand(1);
Anneau_exp_2(2, i_1) = Anneau_exp_2(2, i_1) + 2 * Ordre * p_2 - Ordre;
end
%% Partie 1 : TOLERANCE A
% Résolution du plan
% Nous savons que l'équation d'un plan est de la forme : aX + bY + cZ + d = 0
% On pose aX + bY + cZ = -d
% On fixe la valeur de b
% Nous allors résoudre l'équation Y = (aX + cZ + d) / (-b)
X_1 = (Anneau_exp_1(1, :).');
Y_1 = (Anneau_exp_1(2, :).');
Z_1 = (Anneau_exp_1(3, :).');
b_1 = 100;
i_1 = size(X_1);
% Plan approximé
M_1 = [X_1/b_1 Z_1/b_1 ones(i_1)/b_1];
Res_1 = M_1 \ (-Y_1);
a_1 = Res_1(1); c_1 = Res_1(2) ;d_1 = Res_1(3);
% Calcul des distances orthogonales par rapport au plan
Distances_1 = zeros(size(X_1, 1), 1);
for i = 1 : i_1
Distances_1(i, 1) = (abs(a_1 * Anneau_exp_1(1, i) + b_1 * Anneau_exp_1(2, i) + ...
c_1 * Anneau_exp_1(3, i) + d_1) / (sqrt(a_1^2 + b_1^2 + c_1^2)));
end
%% Partie 2 : TOLERANCE C
% Résolution des plans
X_2 = (Anneau_exp_2(1, :).');
Y_2 = (Anneau_exp_2(2, :).');
Z_2 = (Anneau_exp_2(3, :).');
i_2 = size(X_2);
% Résolution du plan de la tolérance C parallèle au plan approximé sans
M_2 = ones(i_2);
a_2 = a_1; b_2 = b_1; c_2 = c_1;
Res_2 = M_2 \ (-a_1 * X_2 - b_1 * Y_2 - c_1 * Z_2);
d_2 = Res_2;
% Calcul des distances orthogonales par rapport au plan
Distances_2 = zeros(size(X_2, 1), 1);
for i = 1 : i_2
Distances_2(i, 1) = (abs(a_2 * Anneau_exp_2(1, i) + b_2 * Anneau_exp_2(2, i) + c_2 * Anneau_exp_2(3, i) + d_2) / (sqrt(a_2^2 + b_2^2 + c_2^2)));
end
%% Partie 3 : AFFICHAGE
% FIGURE 1 : points expérimentaux
% Affichage de l'anneau expérimental 1 et 2
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
plot3(Anneau_exp_1(1,:), Anneau_exp_1(2,:), Anneau_exp_1(3,:), '*b'); hold on
plot3(Anneau_exp_2(1,:), Anneau_exp_2(2,:), Anneau_exp_2(3,:), '*b'); hold off
title('Plans approximés paralèlle à XZ')
legend('Anneaux expérimentaux');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
% FIGURE 2 : plans approximés un par un
% Nombre de points composant le plan
P_grille = 50;
% Affichage du plan de la tolérance A
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
subplot(2,1,1)
plot3(Anneau_exp_1(1,:), Anneau_exp_1(2,:), Anneau_exp_1(3,:), '*b'); hold on
[Xp_1, Zp_1] = meshgrid(-R_max_1 + x_1 : (2 * R_max_1) / P_grille : R_max_1 + x_1 , -R_max_1 + z_1 : (2 * R_max_1) / P_grille : R_max_1 + z_1);
Yp_1 = @(Xp_1,Zp_1) (-d_1 - a_1 * Xp_1 - c_1 * Zp_1) / b_1;
plot3(Xp_1 ,Yp_1(Xp_1, Zp_1), Zp_1, '.g'); hold off
title('Plan approximé de la tolérance A')
legend('Points expérimentaux', 'Plan approximé');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
% Affichage du plan de la tolérance C
subplot(2,1,2)
plot3(Anneau_exp_2(1,:), Anneau_exp_2(2,:), Anneau_exp_2(3,:), '*b'); hold on
[Xp_2, Zp_2] = meshgrid(-R_max_2 + x_2 : (2 * R_max_2) / P_grille : R_max_2 + x_2 , -R_max_2 + z_2 : (2 * R_max_2) / P_grille : R_max_2 + z_2);
Yp_2 = @(Xp_2,Zp_2) (-d_2 - a_2*Xp_2 - c_2*Zp_2)/b_2;
plot3(Xp_2,Yp_2(Xp_2,Zp_2),Zp_2, '.g'); hold off
title('Plan approximé de la tolérance C')
legend('Points expérimentaux', 'Plan approximé');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
% FIGURE 3 : plans approximés ensembles
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
plot3(Anneau_exp_1(1,:), Anneau_exp_1(2,:), Anneau_exp_1(3,:), '*b'); hold on
plot3(Xp_1 ,Yp_1(Xp_1, Zp_1), Zp_1, '.g');
plot3(Anneau_exp_2(1,:), Anneau_exp_2(2,:), Anneau_exp_2(3,:), '*b');
plot3(Xp_2,Yp_2(Xp_2,Zp_2),Zp_2, '.g'); hold off
title('Plans approximés des tolérances A et C')
legend('Points expérimentaux', 'Plans approximés');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
% FIGURE 4 : distances
% Affichage des distances de la tolérance A
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
subplot(2,1,1)
plot(1 : i_1, Distances_1, '.b'); hold on
plot(1 : i_1, max(Distances_1), 'r'); hold off
title('Distances orthogonales entre les points expérimentaux et le plan de la tolérance A')
legend('Distance orthogonale des points', 'Distance maximale');
xlabel('Points expérimentaux')
ylabel('Distances orthogonales')
grid on
% Affichage des distances de la tolérance C
subplot(2,1,2)
plot(1 : i_1, Distances_2, '.b'); hold on
plot(1 : i_1, max(Distances_2), 'r'); hold off
title('Distances orthogonales entre les points expérimentaux et le plan de la tolérance C')
legend('Distance orthogonale des points', 'Distance maximale');
xlabel('Points expérimentaux')
ylabel('Distances orthogonales')
grid on
%% Partie 4 : ROTATION DES PLANS
% Calcul de la matrice de rotation
xx = Xp_1; % Données du plan en X
yy = Yp_1(Xp_1, Zp_1); % Données du plan en Y
zz = Zp_1; % Données du plan en Z
oo = [xx(1);yy(1);zz(1)]; % Origine du plan
v1 = [xx(1,end);yy(1,end);zz(1,end)]-oo; % Vecteur X du plan
v2 = [xx(end,1);yy(end,1);zz(end,1)]-oo; % Vecteur Z du plan
v3 = cross(v2,v1); % Vecteur Y du plan
axex = v1/norm(v1); % Référentiel axe X du plan
tmpz = v2/norm(v2); % Référentiel temporaire axe Z du plan (au où le plan n'aurait pas des coins orthogonaux)
axey = cross(tmpz,axex); % Référentiel axe Y du plan : Produit vectoriel des vecteurs Z et X
axez = cross(axex,axey); % Référentiel axe Z du plan : Produit vectoriel des vecteurs X et Y
oo = mean(Anneau_exp_1,2); % Au lieu d'utiliser le coin, utiliser la valeur moyenne des points pour une rotation autour du centre
rotation = [axex';axey';axez'];
% Rotation des points expérimentaux
Anneau_exp_1_1 = bsxfun(@plus,rotation*bsxfun(@minus,[Anneau_exp_1(1,:);Anneau_exp_1(2,:);Anneau_exp_1(3,:)],oo),oo);
Anneau_exp_2_1 = bsxfun(@plus,rotation*bsxfun(@minus,[Anneau_exp_2(1,:);Anneau_exp_2(2,:);Anneau_exp_2(3,:)],oo),oo);
% Rotation des plans approximés
Yp_1_1 = Yp_1(Xp_1, Zp_1);
Yp_2_1 = Yp_2(Xp_2, Zp_2);
Plan_1 = bsxfun(@plus,rotation*bsxfun(@minus,[Xp_1(:).'; Yp_1_1(:).'; Zp_1(:).'],oo),oo);
Plan_2 = bsxfun(@plus,rotation*bsxfun(@minus,[Xp_2(:).'; Yp_2_1(:).'; Zp_2(:).'],oo),oo);
%% Partie 5 : AFFICHAGE
% FIGURE 5 : Rotation des tolérances un par un
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
% Affichage des points avant-après rotation ainsi que des plans de la tolérance A
subplot(2,1,1)
% Points
plot3(Anneau_exp_1(1,:), Anneau_exp_1(2,:), Anneau_exp_1(3,:), '*b');hold on;
plot3(Anneau_exp_1_1(1,:), Anneau_exp_1_1(2,:), Anneau_exp_1_1(3,:), '*m');
% Plans
plot3(Xp_1 ,Yp_1(Xp_1, Zp_1), Zp_1, '.g');
plot3(Plan_1(1,:), Plan_1(2,:), Plan_1(3,:), '.c'); hold off;
title('Rotation de la tolérance A')
legend('Points expérimentaux', 'Points expérimentaux après rotation', 'Plan approximé', 'Plan approximé après rotation');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
% Affichage des points avant-après rotation ainsi que des plans de la tolérance C
subplot(2,1,2)
% Points
plot3(Anneau_exp_2(1,:),Anneau_exp_2(2,:),Anneau_exp_2(3,:),'*b'); hold on;
plot3(Anneau_exp_2_1(1,:),Anneau_exp_2_1(2,:),Anneau_exp_2_1(3,:),'*m');
% Plans
plot3(Xp_2 ,Yp_2(Xp_2, Zp_2), Zp_2, '.g');
plot3(Plan_2(1,:), Plan_2(2,:), Plan_2(3,:), '.c'); hold off;
title('Rotation de la tolérance C')
legend('Points expérimentaux', 'Points expérimentaux après rotation', 'Plan approximé', 'Plan approximé après rotation');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
% FIGURE 6 : Rotation des tolérances
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
% Tolérance A
plot3(Anneau_exp_1(1,:), Anneau_exp_1(2,:), Anneau_exp_1(3,:), '*b');hold on;
plot3(Anneau_exp_1_1(1,:), Anneau_exp_1_1(2,:), Anneau_exp_1_1(3,:), '*m');
% Tolérance C
plot3(Anneau_exp_2(1,:),Anneau_exp_2(2,:),Anneau_exp_2(3,:),'*b');
plot3(Anneau_exp_2_1(1,:),Anneau_exp_2_1(2,:),Anneau_exp_2_1(3,:),'*m'); hold off;
title('Rotation de la pièce')
legend('Points expérimentaux', 'Points expérimentaux après rotation');
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on |
Partager