copy of ftestdisplay.cpp

来自「C++ Math Lib. C++ Builder must use.」· C++ 代码 · 共 95 行

CPP
95
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "fTestDisplay.h"
#include "dynarrays.h"
#include "dynarrutils.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
  pPlotBox2D = new PlotBox2D(this);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  delete pPlotBox2D;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  pPlotBox2D->Parent = PanelBox;
  pPlotBox2D->NYTicks = 5;
  pPlotBox2D->NXTicks = 5;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  pPlotBox2D->SetLimits(-3.0,3.0,0.0,10.0);
  pPlotBox2D->PlotFrame();
  pPlotBox2D->OnPaint = PlotBox2DPaint;
  pPlotBox2D->SetPenColor(clRed);
  PlotBox2DPaint(this);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::PlotBox2DPaint(TObject *Sender)
{
  FArr1D x(100);
  FArr1D y(100);
  FArr1D z(100);
  double x1, x2, y1, y2, xx, dx;
  xx = -3.0;
  dx = 0.06;
  for (int i = 1; i <= 100; i++)
  {
    x(i) = xx; xx += dx;
    y(i) = exp(-xx*xx);
    z(i) = xx*y(i);
  };

  switch (RadioGroup1->ItemIndex)
  {
    case 0:
    {
    minmax(x, x1, x2, true);
    minmax(y, y1, y2, true);
    minmax(z, y1, y2, false);
    pPlotBox2D->SetLimits(x1,x2,y1,y2);
    pPlotBox2D->PlotFrame();
    pPlotBox2D->PlotArrays(x,y,clRed);
    pPlotBox2D->PlotArrays(x,z,clBlue);
    };
    break;
    case 1:
    {
    x1 = y.L1();
    x2 = y.H1();
    minmax(y, y1, y2, true);
    minmax(z, y1, y2, false);
    pPlotBox2D->SetLimits(x1,x2,y1,y2);
    pPlotBox2D->PlotFrame();
    pPlotBox2D->PlotArray(y,clRed);
    pPlotBox2D->PlotArray(z,clBlue);
    };
    break;
    default:;
  }; 

}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)
{
  Button1->Click();      
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?