-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrientation.txt
29 lines (29 loc) · 1.33 KB
/
Orientation.txt
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
procedure OrientationGenerale(o:objet;out p1,p2:tpoint);
var M1:array of real; L:real; i,j,i1,i2,np,m:integer; w,x,y,z:tpoint;Ind1,Ind2,Ind3,Ind4:integer;
begin
//Initialization
np:=length(o.ListePoint);m:=np-1;
setlength(M1,(m)*(m));
for i:=0 to length(M1)-1 do M1[i]:=0;
//All the distances
for i:=0 to np-2 do
for j:=i+1 to np-1 do
M1[((np-1)*i)+(j-1)]:=distpoint(o.ListePoint[i],o.ListePoint[j]);
//The 2 max distances
L:=0;
for i:=0 to length(M1)-1 do
if M1[i]>L then begin L:=M1[i]; i1:=i; end;
ind1:=i1 div m;Ind2:=(i1 mod m)+1;
L:=0;
for i:=0 to length(M1)-1 do
if (i div m<>Ind1)and((i mod m)+1<>Ind2)and(i div m<>Ind2)and((i mod m)+1<>Ind2)then
if M1[i]>L then begin L:=M1[i]; i2:=i; end;
ind3:=i2 div m;Ind4:=(i2 mod m)+1;
//The average
w.X:=(o.ListePoint[ind1].X+o.ListePoint[ind3].X)div 2;w.Y:=(o.ListePoint[ind1].Y+o.ListePoint[ind3].Y)div 2;
X.X:=(o.ListePoint[ind2].X+o.ListePoint[ind4].X)div 2;X.Y:=(o.ListePoint[ind2].Y+o.ListePoint[ind4].Y)div 2;
y.X:=(o.ListePoint[ind1].X+o.ListePoint[ind4].X)div 2;y.Y:=(o.ListePoint[ind1].Y+o.ListePoint[ind4].Y)div 2;
z.X:=(o.ListePoint[ind2].X+o.ListePoint[ind3].X)div 2;z.Y:=(o.ListePoint[ind2].Y+o.ListePoint[ind3].Y)div 2;
if DistPoint(w,x)>DistPoint(y,z) then begin p1:=w;p2:=x; end
else begin p1:=y;p2:=z; end;
end;