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
| % Réinitialisation
close all;
clear all;
clc;
% Données
n = [1;1;1];
largeur = 30;
longueur = 50;
position = [10;-20;30];
% Plan de base
[x,y] = meshgrid(linspace(-largeur/2,largeur/2,10),linspace(-longueur/2,longueur/2,10));
z = zeros(size(x));
% Définition du référentiel
axez = n/norm(n); % Axe z est donc la normale
if all(cross(axez,[1;0;0]) == 0) % Gestion des cas problématiques
axex = [0;0;1];
axey = [0;1;0];
elseif all(cross(axez,[0;1;0]) == 0) % Gestion des cas problématiques
axex = [1;0;0];
axey = [0;0;1];
else
% Cas standard : X pointe vers l'axe X positif, Y pointe vers l'axe Y positif
axey = cross(axez,[1;0;0])/norm(cross(axez,[1;0;0]));
axex = cross(axey,axez)/norm(cross(axey,axez));
end
% Matrice de rotation générée appliquée aux données
tmp = [axex,axey,axez]*[x(:)';y(:)';z(:)'];
% Translation
x = reshape(tmp(1,:),size(x)) + position(1);
y = reshape(tmp(2,:),size(y)) + position(2);
z = reshape(tmp(3,:),size(y)) + position(3);
% Affichage
surf(x,y,z);
alpha(0.5);
hold all;
% RGB = XYZ du référentiel
quiver3(position(1),position(2),position(3),axex(1)*max(longueur,largeur)/10,axex(2)*max(longueur,largeur)/10,axex(3)*max(longueur,largeur)/10,0,'r');
quiver3(position(1),position(2),position(3),axey(1)*max(longueur,largeur)/10,axey(2)*max(longueur,largeur)/10,axey(3)*max(longueur,largeur)/10,0,'g');
quiver3(position(1),position(2),position(3),axez(1)*max(longueur,largeur)/10,axez(2)*max(longueur,largeur)/10,axez(3)*max(longueur,largeur)/10,0,'b');
hold off;
xlabel('x');
ylabel('y');
zlabel('z');
axis equal; |
Partager