unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart, ComCtrls;

type
  TForm1 = class(TForm)
    pgc1: TPageControl;
    ts1: TTabSheet;
    ts2: TTabSheet;
    ts3: TTabSheet;
    cht1: TChart;
    lnsrsSeries1: TLineSeries;
    edt1: TEdit;
    edt2: TEdit;
    lbl1: TLabel;
    lbl2: TLabel;
    btn1: TButton;
    edt3: TEdit;
    edt4: TEdit;
    edt5: TEdit;
    lbl3: TLabel;
    lbl4: TLabel;
    lbl5: TLabel;
    edt6: TEdit;
    edt7: TEdit;
    edt8: TEdit;
    edt9: TEdit;
    lbl6: TLabel;
    lbl7: TLabel;
    lbl8: TLabel;
    lbl9: TLabel;
    img1: TImage;
    btn2: TButton;
    btn3: TButton;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    procedure btn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  x1,x2,y,A,B,C,m1x,m1y,m2x,m2y,hx,hy:Extended;


implementation

{$R *.dfm}

Function fun(x,A,B,C: extended):extended;
 begin
  Result:=(-A*x-C)/B;
 end;


procedure TForm1.btn1Click(Sender: TObject);
begin
x1:=StrToFloat(edt1.Text);
x2:=StrToFloat(edt2.Text);
A:=StrToFloat(edt3.Text);
B:=StrToFloat(edt4.Text);
C:=StrToFloat(edt5.Text);
with cht1 do
 begin
      LeftAxis.Automatic:=False;
      LeftAxis.Minimum:=StrToFloat(edt8.Text);
      LeftAxis.Maximum:=StrToFloat(edt6.Text);
      BottomAxis.Automatic:=False;
      BottomAxis.Minimum:=StrToFloat(edt9.Text);
      BottomAxis.Maximum:=StrToFloat(edt7.Text);
      SeriesList[0].Clear;
      y:=fun(x1,A,B,C);
SeriesList[0].AddXY(x1,y);
      y:=fun(x2,A,B,C);
SeriesList[0].AddXY(x2,y);
   end;
Button3.Show;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Edt1.Text:='1';   Edt2.Text:='11';    Edt3.Text:='1';    Edt4.Text:='3';
 Edt5.Text:='0';      Edt6.Text:='20';   Edt7.Text:='20';    Edt8.text:='-20';
 Edt9.Text:='-20'; btn3.Hide; Button3.Hide; Edit1.Text:='2'; Edit3.Text:='0';
 Edit2.Text:='3'; Edit4.Text:='1';
end;

procedure TForm1.btn2Click(Sender: TObject);
var ymax, ymin, xmax, xmin, xo, yo,xImax, yImax:Integer;
    hx,hy:Extended;
begin
x1:=StrToFloat(edt1.Text);
x2:=StrToFloat(edt2.Text);
ymax:=Strtoint(edt7.text);
ymin:=StrToInt(edt9.text);
xmax:=StrToint(edt6.text);
xmin:=StrToInt(edt8.text);
A:=StrToFloat(edt3.Text);
B:=StrToFloat(edt4.Text);
C:=StrToFloat(edt5.Text);
  yo:=ymax div 2;
  xo:=xmax div 2;
    xImax:=Img1.Width;
    yImax:=Img1.Height;
    hx:=(xmax-xmin)/xImax;
    hy:=(ymax-ymin)/yImax;
  with Img1.Canvas do
  begin
             Brush.Color:=RGB(255,255,255);
         Pen.Color:=RGB(255,255,255);
         Rectangle(0,0,xImax,yImax);
    Pen.Color:=clBlack;
    Brush.Color:=clRed;
      MoveTo(Round(xo/hx),Round(yo/hy));
      LineTo(Round(xo/hx),yImax);
      MoveTo(Round(xo/hx),Round(yo/hy));
      LineTo(xImax,Round(yo/hy));
      Pen.Color:=clRed;
      y:=fun(x1,A,B,C);
      MoveTo(Round((xo+x1)/hx),Round((yo+y)/hy));
      y:=fun(x2,A,B,C);
      LineTo(Round((xo+x2)/hx),Round((yo+y)/hy));
  end;
 Btn3.Show;
 end;

 Function Expo(x:extended):extended;
    Begin
    Result:=exp(2*x);
    end;

procedure TForm1.Button2Click(Sender: TObject);
begin
x1:=StrToFloat(edt1.Text);
x2:=StrToFloat(edt2.Text);
 with cht1 do
 begin
      LeftAxis.Automatic:=False;
      LeftAxis.Minimum:=StrToFloat(edt8.Text);
      LeftAxis.Maximum:=StrToFloat(edt6.Text);
      BottomAxis.Automatic:=False;
      BottomAxis.Minimum:=StrToFloat(edt9.Text);
      BottomAxis.Maximum:=StrToFloat(edt7.Text);
     SeriesList[0].Clear;
  end;
While x1<=x2 do begin
y:=Expo(x1);
cht1.SeriesList[0].AddXY(x1,y);
x1:=x1+0.1;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var ximax,yImax,ymax,ymin,xmax,xmin,xo,yo:integer;
begin
x1:=StrToFloat(edt1.Text);
x2:=StrToFloat(edt2.Text);
ymax:=Strtoint(edt7.text);
ymin:=StrToInt(edt9.text);
xmax:=StrToint(edt6.text);
xmin:=StrToInt(edt8.text);
 yo:=ymax div 2;
 xo:=xmax div 2;
  with Img1.Canvas do
  begin
    Pen.Color:=clBlack;
    Brush.Color:=clRed;
    xImax:=Img1.Width;
    yImax:=Img1.Height;
    hx:=(xmax-xmin)/xImax;
    hy:=(ymax-ymin)/yImax;
      MoveTo(Round(xo/hx),Round(yo/hy));
      LineTo(Round(xo/hx),yImax);
      MoveTo(Round(xo/hx),Round(yo/hy));
      LineTo(xImax,Round(yo/hy));
      Pen.Color:=clRed;
       y:=expo(x1);
      MoveTo(Round((xo+x1)/hx),Round((yo+y)/hy));
      while x1<x2 do begin
        y:=expo(x1);
        LineTo(Round((xo+x1)/hx),Round((yo+y)/hy));
        x1:=x1+0.1;
        end;

  end;

end;

procedure TForm1.Button3Click(Sender: TObject);
var S,W,yT,xT:Extended;
begin
  m1x:=StrToFloat(Edit1.Text);
  m2x:=StrToFloat(Edit3.Text);
  m2y:=StrToFloat(Edit4.Text);
  m1y:=StrToFloat(Edit2.Text);
y:=fun(x1,A,B,C);
S:=sqrt(sqr(m1x-x1)+sqr(y-m1y))+sqrt(sqr(m2x-x1)+sqr(y-m1y));
xT:=x1; yT:=y;
While x1<x2 do begin
x1:=x1+0.1;
y:=fun(x1,A,B,C);
W:=sqrt(sqr(m1x-x1)+sqr(y-m1y))+sqrt(sqr(m2x-x1)+sqr(y-m2y));
if s>w then begin
s:=w;
xT:=x1; yT:=y;
end;
end;
cht1.SeriesList[0].AddXY(xT,yT,'',clBlack);
end;

procedure TForm1.btn3Click(Sender: TObject);
var S,W,xT,yT:Extended;
    ymax,ymin,xmax,xmin,xIMAX, yImax,xo,yo:integer;
begin
     m1x:=StrToFloat(Edit1.Text);
     m2x:=StrToFloat(Edit3.Text);
     m2y:=StrToFloat(Edit4.Text);
     m1y:=StrToFloat(Edit2.Text);
     ymax:=Strtoint(edt7.text);
     ymin:=StrToInt(edt9.text);
     xmax:=StrToint(edt6.text);
     xmin:=StrToInt(edt8.text);
     xImax:=Img1.Width;
     yImax:=Img1.Height;
     hx:=(xmax-xmin)/xImax;
     hy:=(ymax-ymin)/yImax;
     yo:=ymax div 2;
     xo:=xmax div 2;
     with img1.Canvas do begin
       MoveTo(Round(xo+m1x),Round(yo+m1y));
       Rectangle(Round((xo+m1x-0.2)/hx),Round((yo+m1y-0.2)/hy),Round((xo+m1x+0.2)/hx),Round((yo+m1y+0.2)/hy));
       MoveTo(Round(xo+m2x),Round(yo+m2y));
       Rectangle(Round((xo+m2x-0.2)/hx),Round((yo+m2y-0.2)/hy),Round((xo+m2x+0.2)/hx),Round((yo+m2y+0.2)/hy));
     end;
   S:=sqrt(sqr(m1x-x1)+sqr(y-m1y))+sqrt(sqr(m2x-x1)+sqr(y-m2y));
 While x1<x2 do begin
x1:=x1+0.1;
y:=fun(x1,A,B,C);
W:=sqrt(sqr(m1x-x1)+sqr(y-m1y))+sqrt(sqr(m2x-x1)+sqr(y-m2y));
if s>w then begin
s:=w;
xT:=x1; yT:=y;
end;
end;
img1.Canvas.Rectangle(Round((xo+xT-0.2)/hx),Round((yo+yT-0.2)/hy),Round((xo+xT+0.2)/hx),Round((yo+yT+0.2)/hy));
end;

end.













