unit Un_1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, math, Spin, Menus, ComCtrls; type TForm1 = class(TForm) Image1: TImage; Button1: TButton; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; SaveDialog1: TSaveDialog; Button2: TButton; Button3: TButton; SpinEdit1: TSpinEdit; SpinEdit2: TSpinEdit; SpinEdit3: TSpinEdit; SpinEdit4: TSpinEdit; SpinEdit5: TSpinEdit; SpinEdit6: TSpinEdit; Label6: TLabel; Label8: TLabel; Image3: TImage; Label9: TLabel; MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; N9: TMenuItem; Image2: TImage; N10: TMenuItem; Image4: TImage; Button4: TButton; TrackBar1: TTrackBar; Label10: TLabel; Label7: TLabel; Label11: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure N7Click(Sender: TObject); procedure N2Click(Sender: TObject); procedure N3Click(Sender: TObject); procedure N4Click(Sender: TObject); procedure N9Click(Sender: TObject); procedure N5Click(Sender: TObject); procedure N10Click(Sender: TObject); procedure Image4Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); Const t=0.05; Var Vx0,Vy0,Vx,Vy,Vc,Vs,x,y,x1,y1,xx,yy,xx1,yy1,z1,z2,a0,b0,K,Cs,Sn:real; a,b,c,d,i,p:integer; Begin Image1.Canvas.Brush.Color:=ClWhite; Image1.Canvas.Rectangle(-10,-10,810,610); Image1.Canvas.Pen.Width:=1; Image1.Canvas.Pen.Color:=clBlack; Image1.Canvas.MoveTo(400,0); Image1.Canvas.LineTo(400,600); Image1.Canvas.MoveTo(0,300); Image1.Canvas.LineTo(800,300); a:=abs(Round(spinedit1.value)); b:=abs(Round(spinedit2.value)); d:=abs(Round(spinedit5.value)); Vx0:=spinedit3.value; Vy0:=spinedit4.value; if ((Vx0=0) and (Vy0=0)) then begin Vx0:=4; Vy0:=3; spinedit1.value:=4; spinedit1.value:=3; end; Vc:=-Vx0/sqrt(sqr(Vx0)+sqr(Vy0)); Vs:=Vy0/sqrt(sqr(Vx0)+sqr(Vy0)); Image1.Canvas.Pen.Width:=2; Image1.Canvas.Pen.Color:=Clblue; Image1.Canvas.MoveTo(round(400+a*Vc),round(300-a*Vs)); For i:=-a to +a do begin x:=-i*Vc+b*sqrt(1-sqr(i/a))*Vs; y:=-i*Vs-b*sqrt(1-sqr(i/a))*Vc; Image1.Canvas.LineTo(round(400+x),round(300-y)); end; For i:=a downto -a do begin x:=-i*Vc-b*sqrt(1-sqr(i/a))*Vs; y:=-i*Vs+b*sqrt(1-sqr(i/a))*Vc; Image1.Canvas.LineTo(round(400+x),round(300-y)); end; Image1.Canvas.Pen.Color:=ClRed; p:=round(1152/d); If a<>b then begin c:=abs(sqr(a)-sqr(b)); a0:=(1+sqr(a+b)/c)/2; b0:=(1-sqr(a+b)/c)/2; For i:=1-p to p do begin if Vx0=0 then begin x:=d*i; y:=-500*Vs; end else if Vy0=0 then begin x:=500*Vc; y:=d*i; end else begin x:=-d*i*abs(Vx0)/Vx0+500*Vc; y:=d*i*abs(Vy0)/Vy0-500*Vs; end; while ((x>-800) and (x<800) and (y>-800) and (y<800)) do begin yy:=2*x*y; xx:=sqr(x)-sqr(y)-c; K:=sqrt(sqr(xx)+sqr(yy)); if y<0 then Sn:=-sqrt((1-xx/k)/2) else Sn:=sqrt((1-xx/k)/2); if x<0 then Cs:=-sqrt((1+xx/k)/2) else Cs:=sqrt((1+xx/k)/2); K:=sqrt(K); z1:=(x*Cs+y*Sn)/K; z2:=(y*Cs-x*Sn)/K; Vx:=Vx0*a0+Vx0*b0*z1+Vy0*a0*z2; Vy:=Vy0*b0+Vy0*a0*z1-Vx0*b0*z2; x1:=x+Vx*t; y1:=y+Vy*t; xx:=-x*Vc+y*Vs; yy:=-x*Vs-y*Vc; xx1:=-x1*Vc+y1*Vs; yy1:=-x1*Vs-y1*Vc; if ((xx>-400) and (xx<400) and (yy>-300) and (yy<300)) then begin Image1.Canvas.MoveTo(round(400+xx),round(300-yy)); Image1.Canvas.LineTo(round(400+xx1),round(300-yy1)); end; x:=x1; y:=y1; if sqr(x/a)+sqr(y/b)<=1 then x:=801; if sqr(Vx)+sqr(Vy)<1E-5 then x:=801; end; end; end else For i:=1-p to p do begin if Vx0<0 then x:=799 else x:=-799; y:=18-i*d; if Vx0<0 then Vx0:=-sqrt(sqr(Vx0)+sqr(Vy0)) else Vx0:=sqrt(sqr(Vx0)+sqr(Vy0)); Vy0:=0; while ((x>-800) and (x<800) and (y>-800) and (y<800)) do begin yy:=2*x*y; xx:=sqr(x)-sqr(y); K:=(sqr(xx)+sqr(yy)); Vx:=Vx0-a*a*Vx0*xx/K-a*a*Vy0*yy/K; Vy:=Vy0-a*a*Vx0*yy/K+a*a*Vy0*xx/K; x1:=x+Vx*t; y1:=y+Vy*t; if ((x>-400) and (x<400) and (y>-300) and (y<300)) then begin Image1.Canvas.MoveTo(round(400+x),round(300-y)); Image1.Canvas.LineTo(round(400+x1),round(300-y1)); end; x:=x1; y:=y1; if sqr(x/a)+sqr(y/a)<=1 then x:=801; if sqr(Vx)+sqr(Vy)<1E-5 then x:=801; end; end; End; procedure TForm1.Button2Click(Sender: TObject); var c,a0,b0,Q,K,V0x,Vx,Vy,x1,y1,x,y,t,z1,z2:real; a,b,i,i1,a10,a1:integer; begin Image1.Canvas.Pen.Width:=2; button2.Enabled:=false; spinedit6.Enabled:=false; a1:=spinedit6.Value; for i1:=1 to trunc(0.4*a1) do begin image1.Canvas.Rectangle(-1,-1,1000,1000); a:=-(a1-5)+i1; b:=trunc(a1*(a1-5)/abs(a)); c:=a*a-b*b; a0:=a/(a-b); b0:=b/(b-a); image1.Canvas.Pen.Color:=clblue; image1.Canvas.Ellipse(400-a,300-b,400+a,300+b); for i:=1 to 16 do begin a10:=0;V0x:=-40;t:=0.1;x:=-399;y:=340-i*40; while ((x1>-400) and (x1<400) and (y1>-300) and (y1<300) and (a10=0)) do begin if x>0 then a10:=1; Q:=1/2*arctan2(2*x*y,x*x-y*y-c); K:=sqrt(sqrt(sqr(sqr(x)-sqr(y)-c)+4*x*x*y*y)); z1:=(x*cos(Q)+y*sin(Q))/K; z2:=(y*cos(Q)-x*sin(Q))/K; Vx:=V0x*a0+V0x*b0*z1; Vy:=-V0x*b0*z2; x1:=x+Vx*t; y1:=y+Vy*t; Image1.Canvas.Pen.Color:=clred; image1.Canvas.MoveTo(400-trunc(x),300-trunc(y)); image1.Canvas.LineTo(400-trunc(x1),300-trunc(y1)); image1.Canvas.MoveTo(399+trunc(x),300-trunc(y)); image1.Canvas.LineTo(399+trunc(x1),300-trunc(y1)); y:=y1;x:=x1; end; x1:=0;y1:=0; end; application.ProcessMessages; end; button2.Enabled:=true; spinedit6.Enabled:=true; end; procedure TForm1.Button3Click(Sender: TObject); var a0,b0,c,Q,K,V0x,Vx,Vy,x1,y1,x,y,t,z1,z2:real; x11,a1,b1,i,i1,a10,j,a,b:integer; begin Image1.Canvas.Pen.Width:=2; b1:=spinedit6.value; a1:=b1-5; button3.Enabled:=false; spinedit6.Enabled:=false; x11:=-trunc(400-b1);i1:=0; for j:=1 to 800+b1 do begin if trunc(j/24)=j/24 then i1:=i1+1; x11:=x11+1; image1.Canvas.Rectangle(-1,-1,1000,1000); a:=-trunc(a1*b1/abs(b)); b:=a1-i1; c:=abs(a*a-b*b); a0:=a/(a-b); b0:=b/(b-a); image1.Canvas.Pen.Color:=clblue; image1.Canvas.Ellipse(x11+400-a,300-b,x11+400+a,300+b); for i:=1 to 16 do begin a10:=0; V0x:=20;t:=1.01;x:=-399;y:=340-i*40; while ((x1>-400) and (x1<400) and (y1>-300) and (y1<300) and (a10=0)) do begin if x>0 then a10:=1; Q:=1/2*arctan2(2*x*y,x*x-y*y-c); K:=sqrt(sqrt(sqr(sqr(x)-sqr(y)-c)+4*x*x*y*y)); z1:=(x*cos(Q)+y*sin(Q))/K; z2:=(y*cos(Q)-x*sin(Q))/K; Vx:=V0x*a0+V0x*b0*z1; Vy:=-V0x*b0*z2; x1:=x+Vx*t; y1:=y+Vy*t; image1.Canvas.Pen.Color:=clred; if i>1 then begin image1.Canvas.MoveTo(801,300-trunc(340-i*40)); image1.Canvas.lineto(801+trunc(x11)-2,300-trunc(340-i*40)); // pravii linii image1.Canvas.MoveTo(-1,300-trunc(340-i*40)); // levii linii image1.Canvas.lineto(-1+trunc(x11)+2,300-trunc(340-i*40)); end; image1.Canvas.MoveTo(x11+400+trunc(x),300-trunc(y)); image1.Canvas.lineTo(x11+400+trunc(x1),300-trunc(y1)); image1.Canvas.MoveTo(x11+401-trunc(x),300-trunc(y)); image1.Canvas.lineTo(x11+401-trunc(x1),300-trunc(y1)); y:=y1;x:=x1; end; x1:=0;y1:=0; end; application.ProcessMessages; end; button3.Enabled:=true; spinedit6.Enabled:=true; end; procedure TForm1.FormCreate(Sender: TObject); begin image1.Canvas.Rectangle(-1,-1,1000,1000); image3.Canvas.Rectangle(-1,-1,106,106); n5.Enabled:=false; n6.Enabled:=false; end; procedure speed(x,y:real;var Vxx,Vyy:real); var a,b:integer;Vx,Vy,z1,z2,Sn,Cs,K,c,a0,b0,Vx0,Vy0,Vs,Vc:real; begin a:=abs(Round(form1.spinedit1.value)); b:=abs(Round(form1.spinedit2.value)); Vx0:=form1.spinedit3.value; Vy0:=form1.spinedit4.value; Vc:=-Vx0/sqrt(sqr(Vx0)+sqr(Vy0)); Vs:=Vy0/sqrt(sqr(Vx0)+sqr(Vy0)); c:=abs(sqr(a)-sqr(b)); a0:=(1+sqr(a+b)/c)/2; b0:=(1-sqr(a+b)/c)/2; K:=sqrt(sqr(sqr(x)-sqr(y)-c)+sqr(2*x*y)); if y<0 then Sn:=-sqrt((1-(sqr(x)-sqr(y)-c)/k)/2) else Sn:=sqrt((1-(sqr(x)-sqr(y)-c)/k)/2); if x<0 then Cs:=-sqrt((1+(sqr(x)-sqr(y)-c)/k)/2) else Cs:=sqrt((1+(sqr(x)-sqr(y)-c)/k)/2); K:=sqrt(K); z1:=(x*Cs+y*Sn)/K; z2:=(y*Cs-x*Sn)/K; Vx:=Vx0*a0+Vx0*b0*z1+Vy0*a0*z2; Vy:=Vy0*b0+Vy0*a0*z1-Vx0*b0*z2; Vxx:=-Vx*Vc+Vy*Vs; Vyy:=-Vx*Vs-Vy*Vc; end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); var Vxx,Vyy:real; begin if n5.Checked=true then if image1.Canvas.Pixels[x,y]=clred then begin x:=x-400;y:=300-y; speed(x,y,Vxx,Vyy); Vxx:=abs(Vxx); Image3.Canvas.Brush.Color:=Clwhite; Image3.Canvas.Rectangle(-1,-1,106,106); Image3.Canvas.Brush.Color:=Clgreen; image3.Canvas.MoveTo(3,52); image3.Canvas.LineTo(3+trunc(7*Vxx),52); image3.Canvas.MoveTo(3,52); image3.Canvas.LineTo(3,52-trunc(7*Vyy)); image3.Canvas.MoveTo(3,52); image3.Canvas.LineTo(3+trunc(7*Vxx),52-trunc(7*Vyy)); label7.Caption:='Vx = '+floattostr(Vxx); label8.Caption:='Vy = '+floattostr(Vyy); end; end; procedure TForm1.N7Click(Sender: TObject); begin showmessage('Test build v 0.94.01 - RiaSoft (C) 29.04.2007'); end; procedure TForm1.N2Click(Sender: TObject); begin image1.Canvas.Rectangle(-1,-1,1000,1000); n2.Checked:=true; n3.Checked:=false; n4.Checked:=false; button1.Visible:=true; button2.Visible:=false; button3.Visible:=false; ////////////////// button4.Visible:=true; //////////// n5.Enabled:=true; ///////////// spinedit1.Enabled:=true; spinedit2.Enabled:=true; spinedit3.Enabled:=true; spinedit4.Enabled:=true; spinedit5.Enabled:=true; spinedit6.Enabled:=false; end; procedure TForm1.N3Click(Sender: TObject); begin label11.Visible:=false; image1.Visible:=true; image4.Visible:=false; spinedit6.MaxValue:=200; image1.Canvas.Rectangle(-1,-1,1000,1000); n2.Checked:=false; n3.Checked:=true; n4.Checked:=false; button1.Visible:=false; button2.Visible:=true; button3.Visible:=false; n5.Checked:=false; n5.Enabled:=false; ///////////// button4.Visible:=false; trackbar1.Visible:=false; ////////////// label7.Visible:=false; label8.Visible:=false; label9.Visible:=false; image3.Visible:=false; /////////////// spinedit1.Enabled:=false; spinedit2.Enabled:=false; spinedit3.Enabled:=false; spinedit4.Enabled:=false; spinedit5.Enabled:=false; spinedit6.Enabled:=true; end; procedure TForm1.N4Click(Sender: TObject); begin label11.Visible:=false; image1.Visible:=true; image4.Visible:=false; spinedit6.MaxValue:=150; image1.Canvas.Rectangle(-1,-1,1000,1000); n2.Checked:=false; n3.Checked:=false; n4.Checked:=true; button1.Visible:=false; button2.Visible:=false; button3.Visible:=true; n5.Checked:=false; n5.Enabled:=false; ////////////////// button4.Visible:=false; trackbar1.Visible:=false; //////////////////// label7.Visible:=false; label8.Visible:=false; label9.Visible:=false; image3.Visible:=false; /////////////////// spinedit1.Enabled:=false; spinedit2.Enabled:=false; spinedit3.Enabled:=false; spinedit4.Enabled:=false; spinedit5.Enabled:=false; spinedit6.Enabled:=true; end; procedure TForm1.N9Click(Sender: TObject); begin Savedialog1.Filter := 'Bitmap files (*.bmp)|*.bmp'; if image1.Visible=true then if SaveDialog1.Execute=true then image1.Picture.SaveToFile(savedialog1.FileName+'.bmp'); if image4.Visible=true then if SaveDialog1.Execute=true then image4.Picture.SaveToFile(savedialog1.FileName+'.bmp'); end; procedure TForm1.N5Click(Sender: TObject); begin n5.Checked:=not(n5.Checked); if n5.Checked=true then begin label7.Visible:=true; label8.Visible:=true; label9.Visible:=true; image3.Visible:=true; end; if n5.Checked=false then begin label7.Visible:=false; label8.Visible:=false; label9.Visible:=false; image3.Visible:=false; end; end; procedure TForm1.N10Click(Sender: TObject); begin form1.Close; end; procedure TForm1.Image4Click(Sender: TObject); var a,b,i,c:integer;P,Vx0,Vy0,Vc,Vs,x,y,Vxx,Vyy,vy,vx,zzz:real; begin trackbar1.Enabled:=false; Image4.Canvas.Brush.Color:=Clwhite; Image4.Canvas.Rectangle(-1,-1,1060,1060); Image4.Canvas.Pen.Width:=1; Image4.Canvas.Pen.Color:=clBlack; Image4.Canvas.MoveTo(400,0); Image4.Canvas.LineTo(400,600); Image4.Canvas.MoveTo(0,300); Image4.Canvas.LineTo(800,300); a:=abs(Round(form1.spinedit1.value));b:=abs(Round(form1.spinedit2.value)); Vx0:=form1.spinedit3.value;Vy0:=form1.spinedit4.value; Vc:=-Vx0/sqrt(sqr(Vx0)+sqr(Vy0));Vs:=Vy0/sqrt(sqr(Vx0)+sqr(Vy0)); Image4.Canvas.Pen.Width:=1;Image4.Canvas.Pen.Color:=Clgreen; speed(-400,0,vx,vy); For i:=-a to a do begin ///////////////////verh x:=-i*Vc+b*sqrt(1-sqr(i/a))*Vs; y:=-i*Vs-b*sqrt(1-sqr(i/a))*Vc; Speed(x,y,Vxx,Vyy); P:=-0.5*(trackbar1.Position+0.5*(vx*vx+vy*vy-Vxx*Vxx-Vyy*Vyy)); Image4.Canvas.pixels[round(400+x),round(300-y)]:=clblue; //image4.Canvas.MoveTo(trunc(400+x),300); //image4.Canvas.lineTo(trunc(400+x),300-trunc(p*10)); {image4.Canvas.MoveTo(400,300); Image4.Canvas.Pen.Width:=1;Image4.Canvas.Pen.Color:=Clgreen; image4.Canvas.LineTo( 400+ trunc(100*x*p/(sqrt(x*x+y*y)*10)) ,300-trunc(100*y*p/(sqrt(x*x+y*y)*10)) ); } image4.Canvas.MoveTo(400+trunc(x),300-trunc(y)); //image4.Canvas.LineTo( 400+ trunc(100*i*p/(a*10)) ,300-trunc(100*sqrt(a*a-i*i)*p/(a*10)) ); if 1-x*x/(a*a)<>0 then if x<>0 then begin if p>0 then zzz:=arctan(-b*x/(sqrt(1-x*x/(a*a))*a*a))+pi/2; if p<0 then zzz:=arctan(-b*x/(sqrt(1-x*x/(a*a))*a*a))-pi/2; end; p:=abs(p); c:=c+1;if c/3=trunc(c/3) then image4.Canvas.LineTo( 400+trunc(x+5*p*cos(zzz)) ,300+trunc(-y-5*p*sin(zzz)) ); {if c/3=trunc(c/3) then begin image4.Canvas.MoveTo(400,300); image4.Canvas.lineTo(trunc(400+x),300-trunc(y));end; } application.ProcessMessages; /////////////////// niz x:=-i*Vc-b*sqrt(1-sqr(-i/a))*Vs; y:=-i*Vs+b*sqrt(1-sqr(-i/a))*Vc; Speed(x,y,Vxx,Vyy); P:=-0.5*(trackbar1.Position+0.5*(vx*vx+vy*vy-Vxx*Vxx-Vyy*Vyy)); Image4.Canvas.pixels[round(400+x),round(300-y)]:=clblue; image4.Canvas.MoveTo(400+trunc(x),300-trunc(y)); if 1-x*x/(a*a)<>0 then if x<>0 then begin if p>0 then zzz:=arctan(-b*x/(sqrt(1-x*x/(a*a))*a*a))+pi/2; if p<0 then zzz:=arctan(-b*x/(sqrt(1-x*x/(a*a))*a*a))-pi/2; end; p:=abs(p); c:=c+1;if c/3=trunc(c/3) then image4.Canvas.LineTo( 400+trunc(x+5*p*cos(zzz)) ,300-trunc(y-5*p*sin(zzz)) ); end; trackbar1.Enabled:=true; end; procedure TForm1.Button4Click(Sender: TObject); begin image1.Visible:=not image1.Visible; image4.Visible:=not image4.Visible; label11.Visible:=image4.Visible; trackbar1.Visible:=image4.Visible; end; end.