Вы находитесь на странице: 1из 11

1.

2. -15-08
3. 9
4. 2
5. - - , - ,
, -
.
6. 2
.
1) -
X Y,
( ).
2) ( )
(, ..):
-
,
(. )
- , ,
( ), (.
)
3), ,
,
.
4)
0.001, .. "a = b"

"abs(a-b) < 0.001".
5) -
, ,
, .
6)
-
( A,B,C), ( ),.
- (, , ,
..)
-
- ,
(, ..)

- ,
(.,
, ..),
.
7)
Menu, Memo.
8) :
;

( OpenDialog SaveDialog)
( Edit, StringGrid ..)

-
;
- OpenDialog

SaveDialog ( );
;
( )
9) .
10) ,
PaintBox. .
X Y,
.
11) :
1 - ,
;
1 - ,
.
12) 3- :
1 ( 1 , , ),
2.
2 ( /, ..)
3
7.

8. :

Form1

OnHide

Form2

OnClose

9. , :

procedure
Button1Click


, 1-
, .











,
Form4
-







Form4

procedure OnClose
procedure
TForm2.N2Click
procedure
TForm2.N6Click
procedure
TForm2.N3Click
procedure
TForm2.N7Click
procedure
TForm2.N8Click
procedure
TForm2.N9Click
procedure
TForm2.N5Click
function raznica
procedure koef
function prinad
procedure
Button1Click
procedure
Button2Click

10.

/
/
- /
- /
- /
/

()

tt

Otr

Tochka

. .

. .
.

Integer

Integer

t
nt
ntt


()

T1o,
T2o

Integer

()

Integer
Tochka

Otr

Tochka

. .

. .

Otr

Integer

Integer

Integer

integer
Otr

Integer

Real

Integer

-
. 1
-
. 2
.

1-

1-

integer

Integer

Otr

Real

Real

Integer

Tchk

otrez

Ft
Fo
T1,t2
R
Ropt
Flag
x
n
A,B,C
P
Kol1
Kol2
O
R1

R2

y,x,x1
,x2,y
1,y2

11. ,


12.

13. ( .dpr)
14. (.pas)

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
form2.show;
form2.Memo1.Text:=' ';
for i:=1 to 7 do
begin
form2.stringgrid1.Cells[0,i]:='' + floattostr(i);
form2.stringgrid2.Cells[0,i]:='' + floattostr(i);
end;
form2.stringgrid1.Cells[1,0]:='X1';
form2.stringgrid1.Cells[2,0]:='Y1';
form2.stringgrid1.Cells[3,0]:='X2';
form2.stringgrid1.Cells[4,0]:='Y2';
form2.stringgrid2.Cells[1,0]:='X';
form2.stringgrid2.Cells[2,0]:='Y';
hide;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, Grids, StdCtrls, ExtCtrls, Unit3;
type
TForm2 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;

N4: TMenuItem;
N5: TMenuItem;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
LabeledEdit2: TLabeledEdit;
LabeledEdit1: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
Memo1: TMemo;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
LabeledEdit4: TLabeledEdit;
procedure OnClose(Sender: TObject; var Action: TCloseAction);
procedure N6Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N7Click(Sender: TObject);
procedure N8Click(Sender: TObject);
procedure N9Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
c1,c2:integer;
implementation
uses Unit1, Unit4;
var tt:array[1..20] of otr; t:array[1..20] of tochka;
ntt,nt:integer; t2o,t1o:tochka; tchk:tochka; otrez:otr;
ft:file of tochka; fo:file of otr;
{$R *.dfm}
procedure TForm2.N2Click(Sender: TObject);
var t1,t2,r,ropt,flag,i:integer;
begin
ntt:=strtoint(LabeledEdit1.text);
nt:=strtoint(labelededit2.Text);
for i:=1 to ntt do
begin
tt[i].x1:=strtoint(stringgrid1.Cells[1,i]);
tt[i].y1:=strtoint(stringgrid1.Cells[2,i]);
tt[i].x2:=strtoint(stringgrid1.Cells[3,i]);
tt[i].y2:=strtoint(stringgrid1.Cells[4,i]);
end;
for i:=1 to nt do
begin
t[i].x:=strtoint(stringgrid2.Cells[1,i]);
t[i].y:=strtoint(stringgrid2.Cells[2,i]);
end;
flag:=0;
for t1:=1 to nt-1 do
for t2:=t1+1 to nt do
begin
if (t[t1].x<>t[t2].x)and(t[t1].y<>t[t2].y) then
begin
r:=raznica(t[t1],t[t2],ntt,tt);
if flag=0 then
begin
ropt:=r;
t1o:=t[t1]; c1:=t1;
t2o:=t[t2]; c2:=t2;
flag:=1;
end
else
begin
if r<ropt then
begin
ropt:=r;
t1o:=t[t1]; c1:=t1;
t2o:=t[t2]; c2:=t2;
end;
end;
end;
end;
if flag=1 then
Labelededit3.text:='x1:'+floattostr(t1o.x)+' '+'y1:'+floattostr(t1o.y)+' '+'x2:'+floattostr(t2o.x)+' '+'y2:'+floattostr(t2o.y)
else

Memo1.text:=(' .');
end;
procedure TForm2.N6Click(Sender: TObject);
var i:integer;
begin
for i:=1 to strtoint(labelededit1.text) do
begin
stringgrid1.Cells[1,i]:=floattostr(random(13)-4);
stringgrid1.Cells[2,i]:=floattostr(random(13)-4);
stringgrid1.Cells[3,i]:=floattostr(random(13)-4);
stringgrid1.Cells[4,i]:=floattostr(random(13)-4);
end;
for i:=1 to strtoint(labelededit2.Text) do
begin
stringgrid2.Cells[1,i]:=floattostr(random(13)-4);
stringgrid2.Cells[2,i]:=floattostr(random(13)-4);
end;
end;
procedure TForm2.OnClose(Sender: TObject; var Action: TCloseAction);
begin
Form1.Close;
end;
procedure TForm2.N3Click(Sender: TObject);
var i:integer;
begin
if SaveDialog1.Execute then
begin
LabeledEdit4.Text:=SaveDialog1.Filename;
AssignFile(ft,SaveDialog1.Filename);
Rewrite(ft);
for i:=1 to strtoint(labelededit2.text) do
begin
tchk.x:=StrToint(StringGrid2.Cells[1,i]);
tchk.y:=StrToint(StringGrid2.Cells[2,i]);
write(ft,tchk);
end;
if FileExists(SaveDialog1.Filename) then
Memo1.text:= ' '
else
Memo1.text:= ' ';
CloseFile(ft);
end
else
Memo1.text:=' SaveDialog1';
end;
procedure TForm2.N7Click(Sender: TObject);
var i:integer;
begin
if SaveDialog1.Execute then
begin
LabeledEdit4.Text:=SaveDialog1.Filename;
AssignFile(fo,SaveDialog1.Filename);
Rewrite(fo);
for i:=1 to strtoint(labelededit1.text) do
begin
otrez.x1:=StrToint(StringGrid1.Cells[1,i]);
otrez.y1:=StrToint(StringGrid1.Cells[2,i]);
otrez.x2:=StrToint(StringGrid1.Cells[3,i]);
otrez.y2:=StrToint(StringGrid1.Cells[4,i]);
write(fo,otrez);
end;
if FileExists(SaveDialog1.Filename) then
Memo1.text:= ' '
else
Memo1.text:= ' ';
CloseFile(fo);
end
else
Memo1.text:=' SaveDialog1';
end;
procedure TForm2.N8Click(Sender: TObject);
var i:integer;
begin
if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
labelededit4.Text:=OpenDialog1.FileName;
memo1.text:=' ';
AssignFile(ft,OpenDialog1.FileName);

Reset(ft);
for i:=1 to Filesize(ft) do
begin
Read(ft,tchk);
StringGrid2.Cells[1,i]:= FloatToStr(tchk.x);
StringGrid2.Cells[2,i]:= FloatToStr(tchk.y);
end;
labelededit2.Text:=floattostr(Filesize(ft));
CloseFile(ft);
end
else
memo1.text:=' ';
end
else
memo1.text:=' OpenDialog1';
end;
procedure TForm2.N9Click(Sender: TObject);
var i:integer;
begin
if OpenDialog1.Execute then
begin
if FileExists(OpenDialog1.FileName) then
begin
labelededit4.Text:=OpenDialog1.FileName;
memo1.text:=' ';
AssignFile(fo,OpenDialog1.FileName);
Reset(fo);
for i:=1 to Filesize(fo) do
begin
Read(fo,otrez);
StringGrid1.Cells[1,i]:= FloatToStr(otrez.x1);
StringGrid1.Cells[2,i]:= FloatToStr(otrez.y1);
StringGrid1.Cells[3,i]:= FloatToStr(otrez.x2);
StringGrid1.Cells[4,i]:= FloatToStr(otrez.y2);
end;
labelededit1.Text:=floattostr(Filesize(fo));
CloseFile(fo);
end
else
memo1.text:=' ';
end
else
memo1.text:=' OpenDialog1';
end;
procedure TForm2.N4Click(Sender: TObject);
begin
form4.Show;
hide;
end;
procedure TForm2.N5Click(Sender: TObject);
begin
form4.Close;
form2.Close;
end;
end.
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, Grids, StdCtrls, ExtCtrls;
type otr=record x1:integer; y1:integer; x2:integer; y2:integer; end;
tochka=record x:integer; y:integer; end;
function raznica(t1,t2:tochka; n:integer; x:array of otr):integer;
procedure koef(t1,t2:tochka; var A,B,C:integer);
function prinad(o:otr; A,B,C:integer):integer;
implementation
function raznica(t1,t2:tochka; n:integer; x:array of otr):integer;
var A,B,C,kol1,kol2,i,p:integer;
begin
kol1:=0; kol2:=0;
for i:=1 to n do
begin
koef(t1,t2,A,B,C);
p:=prinad(x[i],A,B,C);
if p=1 then kol1:=kol1+1
else if p=2 then kol2:=kol2+1;
end;
if (kol1=0)and(kol2=0) then result:=100000

else result:=abs(kol1-kol2);
end;
procedure koef(t1,t2:tochka; var A,B,C:integer);
begin
A:=t1.y-t2.y;
B:=t2.x-t1.x;
C:=t1.x*t2.y-t2.x*t1.y;
end;
function prinad(o:otr; A,B,C:integer):integer;
var r1,r2:real;
begin
result:=0;
r1:=(A*o.x1+B*o.y1+C)/sqrt(sqr(A)+sqr(B));
r2:=(A*o.x2+B*o.y2+C)/sqrt(sqr(A)+sqr(B));
if (r1>0)and(r2>0) then result:=1
else if (r1<0)and(r2<0) then result:=2;
end;
end.
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Unit2, Unit3;
type
TForm4 = class(TForm)
Button1: TButton;
PaintBox1: TPaintBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.Button1Click(Sender: TObject);
begin
form2.show;
hide;
end;

procedure TForm4.Button2Click(Sender: TObject);


var i:integer; A,B,C,y,x,x1,x2,y1,y2:integer;
begin
with Paintbox1.canvas do
begin
pen.color:= clred;
pen.width:=1;
moveto(280,0);
lineto(280,560);
moveto(0,280);
lineto(560,280);
pen.color:= clGreen;
pen.width:=2;
for i:=1 to strtoint(form2.LabeledEdit1.Text) do
begin
moveto(280+strtoint(form2.StringGrid1.Cells[1,i])*31,280-strtoint(form2.StringGrid1.Cells[2,i])*31);
lineto(280+strtoint(form2.StringGrid1.Cells[3,i])*31,280-strtoint(form2.StringGrid1.Cells[4,i])*31);
end;
x1:=280+strtoint(form2.StringGrid2.Cells[1,c1])*31-2;
x2:=280+strtoint(form2.StringGrid2.Cells[1,c1])*31+2;
y1:=280-strtoint(form2.StringGrid2.Cells[2,c1])*31-2;
y2:=280-strtoint(form2.StringGrid2.Cells[2,c1])*31+2;
brush.color:=clBlue;
brush.style:=bsSolid;
ellipse(x1,y1,x2,y2);
x1:=280+strtoint(form2.StringGrid2.Cells[1,c2])*31-3;
x2:=280+strtoint(form2.StringGrid2.Cells[1,c2])*31+3;
y1:=280-strtoint(form2.StringGrid2.Cells[2,c2])*31-3;
y2:=280-strtoint(form2.StringGrid2.Cells[2,c2])*31+3;

brush.color:=clBlue;
brush.style:=bsSolid;
ellipse(x1,y1,x2,y2);
x1:=280+strtoint(form2.StringGrid2.Cells[1,c1])*31;
x2:=280+strtoint(form2.StringGrid2.Cells[1,c2])*31;
y1:=280-strtoint(form2.StringGrid2.Cells[2,c1])*31;
y2:=280-strtoint(form2.StringGrid2.Cells[2,c2])*31;
A:=y1-y2;
B:=x2-x1;
C:=x1*y2-x2*y1;
x:=trunc((-C-B*560)/A);
y:=trunc((-C-A*560)/B);
pen.color:= clred;
pen.width:=2;
moveto(x,560);
lineto(560,y);
end;
end;
end.