Бугреев ПЗ (1231492), страница 12
Текст из файла (страница 12)
end;
str:=(10*(StrToInt(Edit1.Text)-1)+1) //Длина (гипотенуза) между каждыми точками
while str<(10*(StrToInt(Edit1.Text))+1) do begin
a:=StrToFloat(SG2.Cells[1,str+1]); b:=strtofloat(SG2.Cells[1,str]);
c:=strtofloat(SG2.Cells[2,str+1]); d:=strtofloat(SG2.Cells[2,str]);
l:=sqrt(sqr(a-b)+sqr(c-d)); PromDat[str].L:=l; SG2.Cells[5,0]:='L';
SG2.Cells[5,str+1]:=FloatToStr (PromDat[str].L); inc(str);
end;
str:=(10*(StrToInt(Edit1.Text)-1)+1); //Вычисление арктангенса угла для векторов
while str<(10*(StrToInt(Edit1.Text))+1) do begin
a:=strtofloat(Sg2.cells[4,str+1]); b:=strtofloat(Sg2.cells[3,str+1]); arc:=arctan(a/b);
PromDat[str].arc:=arc; SG2.Cells[6,0]:='arc';
SG2.Cells[6,str+1]:=FloatToStr (PromDat[str].arc); inc(str);
end;
end;
### Процедура промежуточных вычислений углов поворота тележек и вагонов ###
procedure moveshapeto (Shp:integer;delta:real);
var dx,dy,dfi1:real;
begin
dx:=delta*cos(Vec[S[Shp].NVec].f); dy:=delta*sin(Vec[S[Shp].NVec].f);
S[Shp].L:=S[Shp].L-delta; S[Shp].X:=S[Shp].X+dx; S[Shp].Y:=S[Shp].Y+dy;
dfi1:=((Vec[S[Shp].NVec].f)-(Vec[S[Shp].NVec+1].f))/((S[shp].L/delta)+500);
if dfi1<0 then dfi:=dfi+dfi1;
If dfi1>=0 then dfi:=dfi-dfi1;
end;
### Процедура отрисовки вспомогательных линий кривой Безье ###
procedure LinXY(PX,PY, PTox,PToy: Integer; C: TColor);
begin
Form2.PaintBox1.Canvas.Pen.Color := C; Form2.PaintBox1.Canvas.MoveTo(Px,PY);
Form2.PaintBox1.Canvas.LineTo(PToX, PToY);
end;
### Вычисления координат углов прямоугольника, имитирующего вагон, при его движении ###
procedure Tr (Rectan:Trect;angle:real;pos:Tpoint;ii:Integer);
var fi,rad:real; a,b,c,d:integer; pip:array [0..4] of TPoint;
begin
Pos.X:=Vagon[ii].Pos.x+sh[ii].Width div 2; Pos.Y:=Vagon[ii].Pos.y+sh[ii].Width div 2;
rad:=42; a:=Rectan.Left; b:=Rectan.Bottom; c:=Rectan.Right; d:=Rectan.Top;
fi:=Arctan(((c-a)/2)/((d-b)/2)); pip[0].X:=Pos.X+round(rad*sin(pi-fi+angle));
pip[0].Y:=Pos.Y-round(rad*cos(pi-fi+angle)); pip[1].X:=Pos.X+round(rad*sin(fi+angle));
pip[1].Y:=Pos.Y-round(rad*cos(fi+angle)); pip[2].X:=Pos.X+round(rad*sin(-fi+angle));
pip[2].Y:=Pos.Y-round(rad*cos(-fi+angle)); pip[3].X:=Pos.X+round(rad*sin(pi+fi+angle));
pip[3].Y:=Pos.Y-round(rad*cos(pi+fi+angle));pip[4].X:=pip[0].X;pip[4].Y:=pip[0].Y;
Form2.PaintBox1.Color:=clBlack; Form2.PaintBox1.Canvas.Polyline(pip);
end;
### Назначение векторам номеров, начальные установки для движения, запуск движения ###
procedure TForm2.BitBtn7Click(Sender: TObject);
var i,l:integer;
begin
for i:=1 to (10*strtoint(Edit1.Text)) do begin
Vec[i].X:=PromDat[i].RealX; Vec[i].Y:=PromDat[i].RealY; Vec[i].L:=PromDat[i].L;
Vec[i].F:=PromDat[i].arc; Vec[i].Dx:=PromDat[i].DeltX;
if i<>(10*strtoint(Edit1.Text)) then begin Vec[i].Next:=i+1;end else Vec[i].Next:=0;
end;
for l:=0 to strtoint(edit5.Text)-1 do begin
S[l].NVec:=1; S[l].L:=Vec[S[l].NVec].L; S[l].X:=0; S[l].Y:=0;
end; nos:=0; kol:=0; Timer6.Enabled:=true;
end;
var ii,radius,cNx,cNy:integer; a,b,c,alf,gip:real; Bpar : BMPPar;
### Движение вагонных тележек и вагонов по сплайнами, занесение данных о движении в базу ###
procedure TForm2.Timer6Timer(Sender: TObject);
begin
for ii:=0 to Kol do begin
if (S[ii].L >0) then begin moveshapeto (ii,(strtoint(edit3.Text))); Sh[ii].Brush.Color:=clRed;
if (Vec[(S[ii].NVec)].dx<0) then begin
Cent[ii].X := Trunc(Vec[S[ii].NVec].X)-Trunc(S[ii].X);
Cent[ii].Y := Trunc(Vec[S[ii].NVec].Y)-Trunc(S[ii].Y); pb_Display_Paint(Paintbox1,(ii));
end;
if (Vec[(S[ii].NVec)].dx>=0) then begin
Cent[ii].X := Trunc(Vec[S[ii].NVec].X)+Trunc(S[ii].X);
Cent[ii].Y := Trunc(Vec[S[ii].NVec].Y)+Trunc(S[ii].Y); pb_Display_Paint(Paintbox1,(ii));
end;
if (s[0].l <0) and (Vec[S[ii].NVec].Next=0) then begin timer6.Enabled:=false;
end;
If (ii>0) then begin
vagon[ii].PerT.X:=Cent[ii-1].X; vagon[ii].PerT.Y:=Cent[ii-1].Y;
vagon[ii].ZadT.X:=Cent[ii].X; vagon[ii].ZadT.Y:=Cent[ii].Y;
vagon[ii].Vector:=PromDat[S[ii].NVec]; a:=vagon[ii].ZadT.X-vagon[ii].PerT.X;
b:=vagon[ii].ZadT.Y-vagon[ii].PerT.Y;
vagon[ii].Pos.X:=vagon[ii].ZadT.X-trunc(a/2)-(Sh[ii].width div 2);
vagon[ii].Pos.Y:=vagon[ii].ZadT.Y-trunc(b/2)-(Sh[ii].width div 2);
If form2.Cb1.Checked then begin
Cent[15+ii].X := Vagon[ii].Pos.X+Sh[ii].width div 2;
Cent[15+ii].Y := Vagon[ii].Pos.Y+Sh[ii].width div 2; pb_Display_Paint(Paintbox1,(15+ii));
end;
if a>0 then if (b>0) and (a>0) then Vagon[ii].ygol:=arctan(b/a);
if (b<0) and (a>0) then Vagon[ii].ygol:=-3.14-arctan(b/a)
else if b>0 then Vagon[ii].ygol:=1.57-arctan(a/b)
else if b<0 then Vagon[ii].ygol:=-1.57-arctan(a/b)
else if a=0 then if b>0 then Vagon[ii].ygol:=1.57 else Vagon[ii].ygol:=-1.57
else if b=0 then if a>0 then Vagon[ii].ygol:=3.14 else Vagon[ii].ygol:=0;
Form2.Memo1.Lines.Add('VG№'+Inttostr(ii)+':'+Floattostr(Vagon[ii].ygol));
Ds3.Insert; Ds3.FBN('PER_T_X').AsInteger:=Vagon[ii].PerT.X;
Ds3.FBN('PER_T_Y').AsInteger:=Vagon[ii].PerT.Y;
Ds3.FBN('ZAD_T_X').AsInteger:=Vagon[ii].ZadT.X;
Ds3.FBN('ZAD_T_Y').AsInteger:=Vagon[ii].ZadT.Y;
Ds3.FBN('VECTOR').AsInteger:=S[ii].Nvec; Ds3.FBN('VAG_C_X').AsInteger:=Vagon[ii].Pos.X;
Ds3.FBN('VAG_C_Y').AsInteger:=Vagon[ii].Pos.Y;
Ds3.FBN('YGOL').AsFloat:=Vagon[ii].ygol; Ds3.Post;
end;
end else begin if Vec[S[ii].NVec].Next<>0 then begin
S[ii].NVec:=S[ii].NVec+1; S[ii].L:=Vec[S[ii].NVec].L;S[ii].X:=0; S[ii].Y:=0; dfi:=0; end;
end; inc(nos); label1.Caption:=inttostr(nos);
if (kol=0) or (kol=2) or (kol=4) or (kol=6) then Edit4.Text:='45';
if (kol=1) or (kol=3) or (kol=5) or (kol=7) then Edit4.Text:='65';
if nos=(strtoint(Edit4.text))*(kol+1) then begin Inc(kol);
If (ii>(strtoint(edit5.text)-1)) then Kol:=ii; nos:=0;
end;
end;
end;
procedure TForm2.Button10Click(Sender: TObject);
begin
Timer6.Enabled:=not Timer6.Enabled;
end;
### Загрузка опорных точек сплайнов с базы данных ###
procedure TForm2.Button14Click(Sender: TObject);
var N,y,p:integer;
begin N:=Strtoint(Edit1.text)-1;for p:=0 to N do begin
for y:=0 to 3 do begin DS1.Locate('id',p,[]);
Sh[100-10*p-y].Left:=Ds1.fbn('X'+inttoStr(y)).AsInteger-(Sh[0].Width div 2);
Sh[100-10*p-y].Top:=Ds1.fbn('Y'+inttoStr(y)).AsInteger-(Sh[0].Width div 2);
Rop[p,y].X:=Ds1.fbn('X'+inttoStr(y)).AsInteger; Rop[p,y].Y:=Ds1.fbn('Y'+inttoStr(y)).AsInteger;
Pb[p+1,y+1].X:=Rop[p,y].X;Pb[p+1,y+1].Y:=Rop[p,y].Y;
end; end;
for y:=0 to StrtoInt(edit1.Text) do begin
PaintBox1.Canvas.Brush.Color:=clNavy;PaintBox1.Canvas.Pen.Color:=clBlack;
PaintBox1.Canvas.PolyBezier(Rop[y]); BitBtn2Click(nil);
end;
end;
### Занесение данных об аппроксимирующих векторах в базу данных ###
procedure TForm2.Button15Click(Sender: TObject);
var str,i:integer;
begin str:=(10*(StrToInt(Edit1.Text)));
for i:=str+1 downto 1 do begin
Ds2.Insert; Ds2.FBN('X').AsFloat:=PromDat[i].RealX;
Ds2.FBN('Y').AsFloat:=PromDat[i].RealY; Ds2.FBN('L').AsFloat:=PromDat[i].L;
Ds2.FBN('ARC').AsFloat:=PromDat[i].Arc; Ds2.FBN('NUM').Asinteger:=i; Ds2.Post; DS2.Open;
end;
end;
### Занесение данных о вагонах в базу данных ###
procedure TForm2.Button17Click(Sender: TObject);
var ii:integer;
begin
Ds3.Insert; Ds3.FBN('PER_T_X').AsInteger:=Vagon[ii].PerT.X;
Ds3.FBN('PER_T_Y').AsInteger:=Vagon[ii].PerT.Y;
Ds3.FBN('ZAD_T_X').AsInteger:=Vagon[ii].ZadT.X;
Ds3.FBN('ZAD_T_Y').AsInteger:=Vagon[ii].ZadT.Y;
Ds3.FBN('VECTOR').AsInteger:=S[ii].Nvec; Ds3.FBN('VAG_C_X').AsInteger:=Vagon[ii].Pos.X;
Ds3.FBN('VAG_C_Y').AsInteger:=Vagon[ii].Pos.Y;
Ds3.FBN('YGOL').AsFloat:=Vagon[ii].ygol;Ds3.Post;
end;
end.
Приложение Б
Листинг программы исследования рекурсивного алгоритма
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, ComCtrls;
type
TForm1 = class(TForm)
Shape1: TShape; Shape2: TShape; Shape3: TShape; Shape4: TShape;
BitBtn1: TBitBtn; BitBtn2: TBitBtn; SG2: TStringGrid; BitBtn4: TBitBtn;
BitBtn5: TBitBtn; StatusBar1: TStatusBar; Memo1: TMemo; Button1: TButton;
Button2: TButton; Label1: TLabel; Edit1: TEdit; BitBtn3: TBitBtn; SG1: TStringGrid;
BitBtn6: TBitBtn; Label2: TLabel; Label3: TLabel; Label5: TLabel; Label6: TLabel;
Label7: TLabel; Label9: TLabel; Label10: TLabel; Label8: TLabel; Edit2: TEdit;
Label4: TLabel; Label11: TLabel;
procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure BitBtn4Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject); procedure BitBtn6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type Tp=record
X1,Y1,S1:Real;
end;
var
Form1: TForm1;
const n=5;
var T: array [0..100] of Tp;
x0,y0,x1,y1,x2,y2,x3,y3,a1,b1,c1,d1,e1,f1,g1,h1,j1,k1,px,py:real;
L,i,p,Kol,W:integer; AC,AB,BC,Perx,AD,Dx,Dy,DD,k:real;
procedure a(x0,y0,x1,y1,x2,y2,x3,y3:real;L:integer);forward;
implementation
{$R *.dfm}
### Алгоритм рекурсии с условием проверки кривой ###
procedure a(x0,y0,x1,y1,x2,y2,x3,y3:real;L:integer);
begin
a1:=(x0)+(x1-x0) / 2;b1:=(y0)+(y1-y0) / 2;c1:=(x1)+(x2-x1) / 2; d1:=(y1)+(y2-y1) / 2;
e1:=(x2)+(x3-x2) / 2;f1:=(y2)+(y3-y2) / 2;g1:=(a1)+(c1-a1) / 2;h1:=(b1)+(d1-b1) / 2;
j1:=(c1)+(e1-c1) / 2; k1:=(d1)+(f1-d1) / 2;pX:=(g1)+(j1-g1)/2;pY:=(h1)+(k1-h1)/2;
AC:=sqrt(sqr(x3-x0)+sqr(y3-y0)); AB:=sqrt(sqr(Px-x0)+sqr(Py-y0)); //Начало условия
BC:=sqrt(sqr(x3-Px)+sqr(y3-Py)); PerX:=abs(AB+BC+AC)/2;
AD:=sqrt(abs(sqr(AB)-(4*(Perx*(PerX-AB)*(PerX-AC)*(PerX-BC))/sqr(AC))));
k:=AC/AD; Dx:=x0+((x3-x0)/k); Dy:=y0+((y3-y0)/k); DD:=sqrt(sqr(Px-Dx)+sqr(Py-Dy));
If DD<(StrToFloat(Form1.Edit1.Text)) then exit;
Form1.Canvas.Brush.Color:=RGB(L*24,L*48,255); //Конец условия
Form1.Canvas.Ellipse((Trunc(px)-10),(Trunc(py)-10),(Trunc(px)+10),(Trunc(py)+10));
Kol:=i; T[i].X1:=px; T[i].Y1:=py;
T[i].S1:=sqrt(Sqr((Form1.Shape1.Left)-(T[i].X1))+Sqr(Form1.Shape1.Top-T[i].Y1));
Form1.SG2.Cells[0,i]:=IntToStr(i); Form1.SG2.Cells[1,i]:=FloatToStr(T[i].X1);
Form1.SG2.Cells[2,i]:=FloatToStr(T[i].Y1);Form1.SG2.Cells[3,i]:=FloatToStr(T[i].S1);inc(i); L:=L+1;
if L=n then exit; a(x0,y0,a1,b1,g1,h1,px,py,L);















