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
| Function Ang2Line(X1, Y1, X2, Y2, X3,Y3, X4, Y4 : Double):Double;
Var
Ang : Double;
begin
Ang := arctan2(Y4 - Y3, X4 - X3)- arctan2(Y2 - Y1, X2 - X1) ; // Arc Tgte A1 Arc Tgte A2
Result := Ang;
if Abs(Ang) > Pi then
Result := 2*Pi - Abs(Ang);
Result := Abs(Result);
end;
Function Dist2Pnts(X1, Y1, X2, Y2 : Double):Double;
Begin
Result := Abs(Sqrt(Sqr(X2-X1)+Sqr(Y2-Y1)));
end;
Function DistPntLine(X1, Y1, X2, Y2, X3,Y3 : Double) : Double;
Var
A, B, C, L : Double;
begin
A := Y3 - Y2;
B := X2 - X3;
C := (X3*Y2)-(X2*Y3);
L := Sqrt(Sqr(X3-X2)+Sqr(Y3-Y2));
Result := ((A*X1)+(B*Y1)+ C)/L;
end;
Function PointOnSegment(X1, X2, X3 : Double) : Boolean;
Var
A: Double;
begin
//Result := (X1 <= X3) and (X3 <= X2);
A := (X3-X1)/(X2-X1);
if Not((A<0) or (A > 1)) then Result := True
else result := False;
end;
Function IntersectPnt(X1, Y1, X2, Y2, X3,Y3, X4, Y4 : Double):TInterArray;
Var
A1, A2, B1, B2, C1, C2, Divis: Double;
begin
Result[1] := 0;
Result[2] := 0;
A1 := Y2-Y1; B1 := X1-X2; C1 := (X2*Y1)- (X1*Y2);
A2 := Y4-Y3; B2 := X3-X4; C2 := (X4*Y3)- (X3*Y4);
Divis := A1*B2-B1*A2;
If Divis = 0 then exit;
Result[1] := ((B1*C2)-(C1*B2))/Divis;
Result[2] := ((C1*A2)-(A1*C2))/Divis;
end;
Function InterCircSegm(X1, Y1, X2, Y2, Xc, Yc, R : Double):TFourPntsArray;
Var
A, B, C, Dx, Dy, T, Discrim, D: Double;
begin
Dy := -(y2-y1); Dx := (x2-x1); // Droite de la forme Dx + Dy + C = 0
C := X1*Y2 - X2*Y1; // où C := X1*Y2 - X2*Y1
Discrim := Sqrt(Sqr(Dx)+Sqr(Dy)) ;
A := DY/Discrim ; // Cercle (Sqr(X - Xc) + Sqr(Y - Yc) := Sqr(R)
B := DX/Discrim ;
D := ((Dy*Xc)+(Dx*Yc)+C)/Discrim ;
T := Sqr(R)-Sqr(D) ; // si T = 0 tangence, si T < 0
Result[3] := T;
Result[4] := T;
if T < 0 then Exit ; // pas d'intersection
Result[1] := Xc-A*D+B*Sqrt(T);
Result[2] := Yc-B*D-A*Sqrt(T);
if T = 0 then Exit; // C'est le point de Tangence
Result[3] := Xc-A*D-B*Sqrt(T);
Result[4] := Yc-B*D+A*Sqrt(T);
end;
Function ParallelPnt(X1, Y1, X2, Y2, ParallelDist : Double):TFourPntsArray;
Var
Ang : Double;
begin
Ang := ArcTan((Y1-Y2)/(X1-X2));
if Ang < 0 then Ang := Ang + Pi;
Ang := -Ang;
if (Y2 <= Y1) then Ang := Pi + Ang;
Result[1] := X1+(ParallelDist*Sin(Ang));
Result[2] := Y1+(ParallelDist*Cos(Ang));
Result[3] := X2+(ParallelDist*Sin(Ang));
Result[4] := Y2+(ParallelDist*Cos(Ang));
end; |