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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
unit BibMaths1;
interface
uses
Windows, Math ;
type
TDPoint = record
X,Y : Double ;
end ;
TDSegment = record
Dp1,Dp2 : TDPoint ; // points
end ;
function AnglePoint(pt1 : TPoint) : double ;
function AnglePointA(pt1 : TDPoint) : double ;
funcTion DistanceDeuxPoints (Pt1 : TPoint; Pt2 : TPoint) : Double;
funcTion DistanceDeuxPointsA (Pt1 : TDPoint; Pt2 : TDPoint) : Double;
function CalculePoint (Distance, Angle : Double) : TDPoint ;
function CalculeIntersec (P1,P2,P3,P4 : TDPoint; var X,Y : Double ) : boolean ;
function ExisteIntersec (P1,P2,P3,P4 : TPoint; var X,Y : Integer ) : boolean ;
function CalculeMilieu (P1,P2 : TPoint) : TDPoint ;
function CalculePerpendiculaire (P1,P2,P3 : TDPoint; var P4 : TDPoint ) : boolean ;
procedure CalculeFibonnacci (l,h : integer ; var x,y : integer) ;
implementation
procedure CalculeFibonnacci (l,h : integer ; var x,y : integer) ;
var
i4,i5 : integer ;
procedure CalculeI5 ;
var
i1,i2,i3 : integer ;
begin
i5 := 0 ;
repeat
i1 := 1 ;
i2 := 1 ;
while true do
begin
i3 := i1 + i2 ;
if (I2+I3) > i4 then break ;
i1 := i2 ;
i2 := i3 ;
end ;
i5 := i5 + i1 ;
i4 := i4 - i1 - i2 ;
until i4 < 4 ;
end ;
begin
i4 := l ;
CalculeI5 ;
x := i5 ;
i4 := h ;
CalculeI5 ;
y := i5 ;
end ;
funcTion DistanceDeuxPoints (Pt1 : TPoint; Pt2 : TPoint) : Double;
var
dx,dy : Double;
begin
dx:= pt1.x - pt2.x;
dy:= pt1.y - pt2.y;
Result := Sqrt((Dx * Dx) + (Dy * Dy));
end;
funcTion DistanceDeuxPointsA (Pt1 : TDPoint; Pt2 : TDPoint) : Double;
var
dx,dy : Double;
begin
dx:= pt1.x - pt2.x;
dy:= pt1.y - pt2.y;
Result := Sqrt((Dx * Dx) + (Dy * Dy));
end;
function AnglePointA (pt1 : TDPoint) : double;
// angle point depuis 0,0
const
K1 = 180 / Pi ;
begin
if ((Pt1.x = 0) and (Pt1.y < 0)) then
Result := 270
else
if ((Pt1.x = 0) and (Pt1.y > 0)) then
Result := 90
else
if ((Pt1.x > 0) and (Pt1.y >= 0)) then
Result := ArcTan(Pt1.y / Pt1.x) * K1
else
if ((Pt1.x < 0) And (Pt1.y > 0)) then
Result := 180 - (ArcTan(Pt1.y / Abs(Pt1.x))* K1)
else
if ((Pt1.x < 0) And (Pt1.y <= 0)) then
Result := 180 + (ArcTan(Pt1.y / Pt1.x) * K1)
else
if ((Pt1.x > 0) and (Pt1.y < 0)) then
Result := 360 - (ArcTan(Abs(Pt1.y) / Pt1.x) * K1)
else
Result:=0;
end;
function AnglePoint (pt1 : TPoint) : double;
// angle point depuis 0,0
const
K1 = 180 / Pi ;
begin
if ((Pt1.x = 0) and (Pt1.y < 0)) then
Result := 270
else
if ((Pt1.x = 0) and (Pt1.y > 0)) then
Result := 90
else
if ((Pt1.x > 0) and (Pt1.y >= 0)) then
Result := ArcTan(Pt1.y / Pt1.x) * K1
else
if ((Pt1.x < 0) And (Pt1.y > 0)) then
Result := 180 - (ArcTan(Pt1.y / Abs(Pt1.x))* K1)
else
if ((Pt1.x < 0) And (Pt1.y <= 0)) then
Result := 180 + (ArcTan(Pt1.y / Pt1.x) * K1)
else
if ((Pt1.x > 0) and (Pt1.y < 0)) then
Result := 360 - (ArcTan(Abs(Pt1.y) / Pt1.x) * K1)
else
Result:=0;
end;
function CalculePoint (Distance, Angle : Double) : TDPoint ;
//convertit les coordonnées polaires en coordonnées rectangulaires
var
Pt1 : TDPoint ;
Radians : Double ;
begin
Radians := DegToRad (Angle) ;
Pt1.x := Distance * Cos(Radians);
Pt1.y := Distance * Sin(Radians);
Result := Pt1 ;
end ;
function CalculeIntersec (P1,P2,P3,P4 : TDPoint; var X,Y : Double ) : boolean ;
var
a1,a2,b1,b2 : Double ;
begin
Result := false ;
if ((P1.x-P2.x)=0) or ((P3.x-P4.x)=0) then
exit ;
a1 := (P1.y-P2.y)/(P1.x-P2.x) ;
b1 := P1.y - (P1.x * a1) ;
a2 := (P3.y-P4.y)/(P3.x-P4.x) ;
b2 := P3.y - (P3.x * a2) ;
if a1=a2 then exit ;
x := (b2-b1)/(a1-a2) ;
y := a1*x + b1 ;
Result := true ;
end ;
function ExisteIntersec (P1,P2,P3,P4 : TPoint; var X,Y : Integer ) : boolean ;
var
ia1,ia2,ib1,ib2 : Double ;
b1, b2 : boolean ;
begin
Result := false ;
if ((P1.x-P2.x)=0) or ((P3.x-P4.x)=0) then
exit ;
ia1 := (P1.y-P2.y)/(P1.x-P2.x) ;
ib1 := P1.y - (P1.x * ia1) ;
ia2 := (P3.y-P4.y)/(P3.x-P4.x) ;
ib2 := P3.y - (P3.x * ia2) ;
if ia1=ia2 then exit ;
x := Round((ib2-ib1)/(ia1-ia2)) ;
y := Round(ia1*x + ib1) ;
b1 := (P1.x<X) and (X<P2.x) and (P3.x<X) and (X<P4.x) ;
b2 := (P1.Y<Y) and (Y<P2.Y) and (P3.Y<Y) and (Y<P4.Y) ;
Result := b1 and b2 ;
end ;
function CalculeMilieu (P1,P2 : TPoint) : TDPoint;
var
Dp1 : TDpoint ;
begin
Dp1.X := (P1.X + P2.X) / 2 ;
Dp1.Y := (P1.Y + P2.Y) / 2 ;
Result := Dp1 ;
end ;
function CalculePerpendiculaire (P1,P2,P3 : TDPoint; var P4 : TDPoint ) : boolean ;
var
p5 : TPoint ;
a1 : double ;
dp6 : TDPoint ;
begin
p5.X := round(p3.x - p2.x) ;
p5.y := round(p3.y - p2.y) ;
a1 := AnglePoint (p5) + 90 ;
dp6 := CalculePoint (10,a1) ;
dp6.X := dp6.X+p1.x ;
dp6.y := dp6.y+p1.y ;
CalculeIntersec (p2,p3,p1,Dp6,p4.X,p4.Y) ;
result := true
end ;
end. |
Partager