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
|
function enveloppeconvexe
clc;
a=0;b=10;c=0;d=10;
clf;
axis([a b c d])
hold on
grid
[xn,yn,but]=ginput(1);
x=[xn];y=[yn];plot(xn,yn,'.r');
n=1;k=n;Go=1;
ListPt2=[k];
while Go==1;
[xn,yn,but]=ginput(1);
if but<3 x=[x xn]; y=[y yn];plot(xn,yn,'.r');n=n+1;
plot([x(n-1) x(n)],[y(n-1) y(n)],'-g');
end;
if but>1 ;plot([x(n) x(1)],[y(n) y(1)],'-g'); Go=0; end;
end;
ListPt2=[[1:n] 1];
triplot(delaunay(x,y),x,y)
pause;
plot(x,y,'.k');
hold on;
ListPt = convhull(x,y);
n=size(ListPt,2);
for i=1:n
j=ListPt(i);
end;
plot(x(ListPt),y(ListPt),'green',x,y,'.r');hold on;
pause;
plot(x(ListPt2),y(ListPt2),'-rs','LineWidth',2,...
'MarkerEdgeColor','black',...
'MarkerFaceColor','black',...
'MarkerSize',10)
pause;
clc;
NbTr=size(delaunay(x,y),1);
MC=[];
Triang=delaunay(x,y);
for l=1:NbTr
Tr=Triang(l,:);
i=Tr(1,1);j=Tr(1,2);k=Tr(1,3);
MC=[MC;[i,j];[j,k];[k,i] ];
end;
SML=sort(MC,2);
SML=sortrows(SML);
N=MC(1,:);
n=size(MC,1);
for i=2:n
if MC(i-1,:)==MC(i,:) ;else N=[N;MC(i,:)]; end;
end;
GGT=[];
n=size(MC,1);
for k=1:n
Cote=MC(k,:);i=Cote(1);j=Cote(2);
n=numel(x);
A=[x(i) y(i)]; B=[x(j) y(j)];
M=1/2*(A+B);R=(1/2)*norm(B-A);
Go=1;k=0;Bool=0;
while Go
k=k+1;
if ismember(k,[i j]);
else
C=[x(k) y(k)];d=norm(C-M);Bool=d<R;
end;
Go=not(Bool) & (k<n);
end;
BSG=not(Bool);
if BSG GGT=[GGT;Cote];
end;
end;
clf;
axis([a b c d]);
GGT
plot(x,y,'.r');
n=size(GGT,1);
for k=1:n
i=GGT(k,1);j=GGT(k,2);
plot([x(i) x(j)],[y(i) y(j)],'-b');hold on;
end; |
Partager