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

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label1: TLabel;
    Label9: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    TabSheet2: TTabSheet;
    Image1: TImage;
    Button1: TButton;
    Button2: TButton;
    TabSheet3: TTabSheet;
    Button3: TButton;
    Button4: TButton;
    Label10: TLabel;
    Label11: TLabel;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Chart1: TChart;
    Series1: TLineSeries;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  x1,x2,x3,x4,y1,y2,y3,y4,m,i: integer;
  h,xn,xk,x,y:extended;

implementation
{$R *.dfm}

Function f(x: extended):extended;
 begin
  Result:=arctan(x);
 end;


procedure TForm1.FormCreate(Sender: TObject);
begin
 Edit1.Text:='20'; Edit2.Text:='20'; Edit3.Text:='20'; Edit4.Text:='300';
 Edit5.Text:='100';  Edit6.Text:='100'; Edit7.Text:='300';  Edit8.Text:='20';
 Edit9.Text:='-10'; Edit10.Text:='10'; Edit11.Text:='1000';

 end;


procedure TForm1.Button1Click(Sender: TObject);  // Рисование в Image1
var x,y,xmax,xmin,ymax,ymin,k: integer;
        hx,hy,kx,ky: extended;
begin
  Image1.Canvas.Brush.Color:=clWindow;
  x:=Image1.Width;
  y:=Image1.Height;

  Image1.Canvas.Rectangle(0,0,x,y);
  x1:=StrToInt(Edit1.Text);
  y1:=StrToInt(Edit2.Text);
  x2:=StrToInt(Edit3.Text);
  y2:=StrToInt(Edit4.Text);
  x3:=StrToInt(Edit5.Text);
  y3:=StrToInt(Edit6.Text);
  x4:=StrToInt(Edit7.Text);
  y4:=StrToInt(Edit8.Text);

  xmax:=x4;
  if x3>xmax then xmax:=x3;
  xmin:=x1;
  if x2<xmin then xmin:=x2;
  hx:=xmax-xmin;

  ymax:=y3;
  if y2>ymax then ymax:=y2;
  ymin:=y1;
  if y4<ymin then ymin:=y4;
  hy:=ymax-ymin;

  kx:=(x/hx)*(2/3);
  ky:=(y/hy)*(2/3);

  {Определение многоугольника}
  k:=1;
  with Image1.Canvas do begin
    Brush.Color:=clGreen;
    Image1.Canvas.Polygon([Point(Round(kx*x2),Round(ky*y2)),Point(Round(kx*x3),Round(ky*y3)),Point(Round(kx*x4),Round(ky*y4))]);
    if Pixels[x1,y1]=clGreen then k:=0;

    Image1.Canvas.Polygon([Point(Round(kx*x1),Round(ky*y1)),Point(Round(kx*x2),Round(ky*y2)),Point(Round(kx*x4),Round(ky*y4))]);
    if Pixels[x3,y3]=clGreen then k:=0;

    Image1.Canvas.Polygon([Point(Round(kx*x1),Round(ky*y1)),Point(Round(kx*x2),Round(ky*y2)),Point(Round(kx*x3),Round(ky*y3))]);
    if Pixels[x4,y4]=clGreen then k:=0;

    Image1.Canvas.Polygon([Point(Round(kx*x1),Round(ky*y1)),Point(Round(kx*x3),Round(ky*y3)),Point(Round(kx*x4),Round(ky*y4))]);
    if Pixels[x2,y2]=clGreen then k:=0;
  end;


     Image1.Canvas.Brush.Color:=clWindow;
     Image1.Canvas.Rectangle(0,0,x,y);

     
     with Image1.Canvas do begin
  Pen.Color:=clBlack;
  Brush.Color:=clGreen;
   Image1.Canvas.Polygon([Point(Round(kx*x1),Round(ky*y1)),Point(Round(kx*x2),Round(ky*y2)),Point(Round(kx*x3),Round(ky*y3)),Point(Round(kx*x4),Round(ky*y4))]);
  {Image1.Canvas.Polygon([Point(Round((xo-x1)/hx),Round((yo-y1)/hy)),Point(Round((xo-x2)/hx),Round((yo-y2)/hy)),Point(Round((xo-x3)/hx),Round((yo-y3)/hy)),Point(Round((xo-x4)/hx),Round((yo-y4)/hy))]);}
  end;


  if k=1 then
    Image1.Canvas.TextOut(20,20,'Выпуклый') else
    Image1.Canvas.TextOut(20,20,'Не выпуклый');
  end;




procedure TForm1.Button2Click(Sender: TObject);
begin
ClipBoard.Assign(Image1.Picture);  // Копировать в буфер обмена
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
xn:=StrToFloat(Edit9.Text);
  xk:=StrToFloat(Edit10.Text);
  m:=StrToInt(Edit11.Text);

         {Установка осей}
    with Chart1 do begin
      LeftAxis.Automatic:=True;

      BottomAxis.Automatic:=True;

        SeriesList[0].Clear;
      h:=(xk-xn)/(m-1);     x:=xn;
  for i:=1 to m do begin
      y:=f(x);
        SeriesList[0].AddXY(x,y);
      x:=x+h;
                         end;
                    end;

end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Chart1.CopyToClipboardMetafile(True);
end;



end.


