% draws a plane normal to N and center in P0
% DrawPlane(N,P0,wref,tam,color)
%


function []=DrawPlane(N,P0,wref,tam,color)



% Check input:
error(nargchk(2,5,nargin));



[n m]=size(N);
if (n~=3) && (m~=1)
 error('N must be 3x1 vector');
 return;
end
[n m]=size(P0);
if (n~=3) && (m~=1)
 error('P0 must be 3x1 vector');
 return;
end

if ~exist('tam','var');tam=10;end
if ~exist('wref','var'); wref=eye(4);end
if ~exist('color','var');color=[0.8,0.8,0.8];end


N=N/norm(N);
N=wref*[N;1];
N(4)=[];
P0=wref*[P0;1];
P0(4)=[];



[dum, ix] = sort(abs(N), 'ascend'); % independent variable is the one with

lims = [ P0-tam P0+tam ]';

[v(:,:,ix(1)), v(:,:,ix(2))] = meshgrid([lims(:,ix(1)), lims(:,ix(1))], ...
 [lims(:,ix(2)), lims(:,ix(2))]);
alfa = .1;

v(:,:,ix(3)) = ( - N(ix(1))*v(:,:,ix(1)) - N(ix(2))*v(:,:,ix(2)) )/N(ix(3)) + P0(ix(3));

hs = surf( v(:,:,1), v(:,:,2), v(:,:,3), 'FaceColor',color, ...
 'EdgeColor', color,   ...
 'LineWidth', 1  );

