unit Unit1;

interface

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

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

var
  Form1: TForm1;
  xn,xk,x,y,h,xomin,xomax,yomin,yomax,o1,o2,a,b,c: extended;
  i,m: integer;

implementation

{$R *.dfm}

function f(x: extended): extended;
begin
  Result:=sin(x);
end;  

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.Text:='0';
  Edit2.Text:='10';
  Edit3.Text:='100';
  Edit4.Text:='0';
  Edit5.Text:='-1';
  Edit6.Text:='10';
  Edit7.Text:='1';
  Edit8.Text:='60';
  Edit9.Text:='80';
  Edit10.Text:='100';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  xn:=StrToFloat(Edit1.Text);
  xk:=StrToFloat(Edit2.Text);
  m:=StrToInt(Edit3.Text);
  xomin:=StrToFloat(Edit4.Text);
  xomax:=StrToFloat(Edit6.Text);
  yomin:=StrToFloat(Edit5.Text);
  yomax:=StrToFloat(Edit7.Text);
  with Chart1 do begin
    LeftAxis.Automatic:=False;
    LeftAxis.Minimum:=yomin;
    LeftAxis.Maximum:=yomax;
    BottomAxis.Automatic:=False;
    BottomAxis.Minimum:=xomin;
    BottomAxis.Maximum:=xomax;
    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.Button2Click(Sender: TObject);
begin
 Chart1.CopyToClipboardMetafile(True);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Image1.Picture:=nil;
  a:=StrToFloat(Edit8.Text);
  b:=StrToFloat(Edit9.Text);
  c:=StrToFloat(Edit10.Text);
  if (a<b+c) and (b<a+c) and (c<a+b) then begin
    if (a>200) or (b>200) or (c>200) then
    repeat
      a:=a/2;
      b:=b/2;
      c:=c/2;
    until (a<=200) and (b<=200) and (c<=200);
    o1:=(sqr(a)+sqr(b)-sqr(c))/(2*a);
    o2:=sqrt(sqr(b)-sqr(o1));
    with Image1.Canvas do begin
      Pen.Width:=2;
      MoveTo(Round((320-a)/2),Round((240-o2)/2+o2));
      Pen.Color:=clRed;
      LineTo(Round((320-a)/2+a),Round((240-o2)/2+o2));
      Pen.Color:=clGreen;
      LineTo(Round((320-a)/2+a-o1),Round((240-o2)/2));
      Pen.Color:=clBlue;
      LineTo(Round((320-a)/2),Round((240-o2)/2+o2));
    end;
  end
  else Image1.Canvas.TextOut(70,110,'Такого треугольника не существует');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  ClipBoard.Assign(Image1.Picture);
end;

end.
