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
| type
TVector = record X,Y: Double; end;
TVectorArray = Array of TVector;
function Jarvis(T: TVectorArray; N: Integer): TVectorArray;
function SensDirect(A,B,C: TVector): Boolean;
begin
Result:=(((C.X-A.X)*(B.Y-A.Y)-(B.X-A.X)*(C.Y-A.Y))>0);
end;
var
I,A0,A,B: Integer;
MinX: Double;
begin
SetLength(Result,0);
// Recherche du point le plus à gauche
MinX:=T[0].X;
A0:=0;
For I:= 0 to N-1 do
if (T[I].X<=MinX) then
begin
MinX:=T[I].X;
A0:=I;
end;
// Génération de l'enveloppe convexe
A:=A0;
Repeat
if (A=0) then
begin
B:=1;
For I:= 2 to N-1 do
if SensDirect(T[A],T[B],T[I]) then B:=I;
end
else
begin
B:=0;
For I:= 1 to A-1 do
if SensDirect(T[A],T[B],T[I]) then B:=I;
For I:= A+1 to N-1 do
if SensDirect(T[A],T[B],T[I]) then B:=I;
end;
SetLength(Result,Length(Result)+1);
Result[Length(Result)-1]:=T[B];
A:=B;
Until (A=A0);
end; |
Partager