function op=closest(P,p,x,N);

// polyhedra is P, p is point outside and x is starting point. 
// N is number of iterations

[M,ig]=size(P);
op=[];
for i=1:N
op=[op;x];
v=p-x;
dot=P*v'-x*v';

[maxi,ii]=max(dot);
disp(maxi);
disp(ii);
if maxi<0.0001
return;
end;
diro=P(ii,:)-x;
disp(diro);
lam=min((diro*(p-x)')/(diro*diro'),1);
x=x+lam*diro;
disp(x);
end;

return;


