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
| close all;
clear all;
clc;
A = [-1;0;1]; % Point A
an = [-1;3;-2]; % Vecteur directionnel
p = randn(3,10); % Points
% Pour chaque point "p", on soustrait "A" pour les ramener selon "A"
% Ensuite, on normalise "an" et on effectue le produit scalaire
t = dot(bsxfun(@minus,p,A),(an/norm(an))*ones(1,size(p,2))); % Distance avec sens
d = abs(t); % Distance absolue
figure;
quiver3(A(1),A(2),A(3),an(1),an(2),an(3),0,'b'); hold all;
plot3(p(1,:),p(2,:),p(3,:),'.r');
for i = 1:size(p,2);
tmp = A + t(i)*(an/norm(an));
plot3([p(1,i),tmp(1)],[p(2,i),tmp(2)],[p(3,i),tmp(3)],'-g');
tmp = p(:,i) + t(i)*(-an/norm(an));
plot3([p(1,i),tmp(1)],[p(2,i),tmp(2)],[p(3,i),tmp(3)],'-m');
end
[x,y] = meshgrid(-3:3);
z = -an(1)/an(3)*x + -an(2)/an(3)*y;
surf(x+A(1),y+A(2),z+A(3));
alpha(0.5);
axis equal; |
Partager