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
| % On vide la mémoire
close all
clear all
clc
%% Plan_rotation.m
% Version 1 : trouver la matrice de rotation pour aligner le plan approximé
%% 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;
% Définition de l'anneau nominal 1 et 2
XAnneau_nom_1 = [];
YAnneau_nom_1 = [];
ZAnneau_nom_1 = [];
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];
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];
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;
end
X_1 = (Anneau_exp_1(1, :).');
Y_1 = (Anneau_exp_1(2, :).');
Z_1 = (Anneau_exp_1(3, :).');
b_1 = 10;
i_1 = size(X_1);
%% RESOLUTION
% 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);
%% AFFICHAGE
% Affichage du plan
figure('units','normalized','outerposition',[0 0 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 : 0.5 : R_max_1 + x_1 , -R_max_1 + z_1 : 0.5 : R_max_1 + z_1);
Yp_1 = @(Xp_1,Zp_1) (-d_1 - a_1 * Xp_1 - c_1 * Zp_1) / b_1;
surf(Xp_1 ,Yp_1(Xp_1, Zp_1), Zp_1); alpha(0.5);
title('Plan approximé de la tolérance A')
xlabel ('X')
ylabel('Y')
zlabel ('Z')
grid on
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
quiver3(oo(1),oo(2),oo(3),v1(1),v1(2),v1(3),0,'c','LineWidth',2);
quiver3(oo(1),oo(2),oo(3),v3(1)/100,v3(2)/100,v3(3)/100,0,'m','LineWidth',2);
quiver3(oo(1),oo(2),oo(3),v2(1),v2(2),v2(3),0,'y','LineWidth',2);
quiver3(oo(1),oo(2),oo(3),axex(1),axex(2),axex(3),0,'r','LineWidth',3);
quiver3(oo(1),oo(2),oo(3),axey(1),axey(2),axey(3),0,'g','LineWidth',3);
quiver3(oo(1),oo(2),oo(3),axez(1),axez(2),axez(3),0,'b','LineWidth',3);hold off
% Autres origines possibles
oo = mean(Anneau_exp_1,2); % Au lieu d'utiliser le coin, utiliser la valeur moyenne des points pour une rotation autour du centre
% oo = mean([xx(:)';yy(:)';zz(:)'],2); % Au lieu d'utiliser le coin, utiliser la valeur moyenne des données du plan pour une rotation autour du centre
% [axex';axey';axez'] est la matrice de rotation 3x3 à appliquer au plan
% Il faut ramener les données à l'origine avant la rotation autour de l'origine, donc on soustrait l'origine "oo" du plan
rotation = [axex';axey';axez'];
Anneau_exp_2 = bsxfun(@plus,rotation*bsxfun(@minus,[Anneau_exp_1(1,:);Anneau_exp_1(2,:);Anneau_exp_1(3,:)],oo),oo);
Yp_1_1 = Yp_1(Xp_1, Zp_1);
Plan_2 = bsxfun(@plus,rotation*bsxfun(@minus,[Xp_1(:).'; Yp_1_1(:).'; Zp_1(:).'],oo),oo);
figure;
plot3(Anneau_exp_2(1,:),Anneau_exp_2(2,:),Anneau_exp_2(3,:),'.m');hold on;
plot3(Anneau_exp_1(1,:), Anneau_exp_1(2,:), Anneau_exp_1(3,:), '.b');
plot3(Plan_2(1,:), Plan_2(2,:), Plan_2(3,:), '.m');
surf(Xp_1 ,Yp_1(Xp_1, Zp_1), Zp_1); alpha(0.5);
xlabel ('X');
ylabel('Y');
zlabel ('Z');
grid on; |
Partager