📄 form1.h
字号:
this->groupBox2->Controls->Add(this->label8);
this->groupBox2->Controls->Add(this->hScrollBar_yscale);
this->groupBox2->Controls->Add(this->label7);
this->groupBox2->Controls->Add(this->hScrollBar_xscale);
this->groupBox2->Controls->Add(this->label6);
this->groupBox2->Controls->Add(this->label5);
this->groupBox2->Controls->Add(this->txtCTY);
this->groupBox2->Controls->Add(this->label4);
this->groupBox2->Controls->Add(this->label3);
this->groupBox2->Controls->Add(this->txtCTX);
this->groupBox2->Location = System::Drawing::Point(784, 292);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(140, 233);
this->groupBox2->TabIndex = 6;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"坐标系";
//
// listBox_nGrid
//
this->listBox_nGrid->FormattingEnabled = true;
this->listBox_nGrid->ItemHeight = 12;
this->listBox_nGrid->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L"4", L"8", L"16"});
this->listBox_nGrid->Location = System::Drawing::Point(14, 117);
this->listBox_nGrid->Name = L"listBox_nGrid";
this->listBox_nGrid->Size = System::Drawing::Size(111, 16);
this->listBox_nGrid->TabIndex = 16;
this->listBox_nGrid->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listBox_nGrid_SelectedIndexChanged);
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::Point(12, 178);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(41, 12);
this->label8->TabIndex = 15;
this->label8->Text = L"yscale";
//
// hScrollBar_yscale
//
this->hScrollBar_yscale->Location = System::Drawing::Point(14, 194);
this->hScrollBar_yscale->Maximum = 800;
this->hScrollBar_yscale->Minimum = 200;
this->hScrollBar_yscale->Name = L"hScrollBar_yscale";
this->hScrollBar_yscale->Size = System::Drawing::Size(111, 20);
this->hScrollBar_yscale->TabIndex = 14;
this->hScrollBar_yscale->Value = 200;
this->hScrollBar_yscale->ValueChanged += gcnew System::EventHandler(this, &Form1::btnStart_Click);
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(12, 140);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(41, 12);
this->label7->TabIndex = 13;
this->label7->Text = L"xscale";
//
// hScrollBar_xscale
//
this->hScrollBar_xscale->Location = System::Drawing::Point(14, 156);
this->hScrollBar_xscale->Maximum = 400;
this->hScrollBar_xscale->Minimum = 100;
this->hScrollBar_xscale->Name = L"hScrollBar_xscale";
this->hScrollBar_xscale->Size = System::Drawing::Size(111, 20);
this->hScrollBar_xscale->TabIndex = 12;
this->hScrollBar_xscale->Value = 100;
this->hScrollBar_xscale->ValueChanged += gcnew System::EventHandler(this, &Form1::btnStart_Click);
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(12, 102);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(53, 12);
this->label6->TabIndex = 11;
this->label6->Text = L"网格数量";
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(15, 109);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(0, 12);
this->label5->TabIndex = 9;
//
// txtCTY
//
this->txtCTY->Enabled = false;
this->txtCTY->Location = System::Drawing::Point(14, 78);
this->txtCTY->Name = L"txtCTY";
this->txtCTY->Size = System::Drawing::Size(111, 21);
this->txtCTY->TabIndex = 7;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Enabled = false;
this->label4->Location = System::Drawing::Point(12, 63);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(83, 12);
this->label4->TabIndex = 6;
this->label4->Text = L"中心点横坐标Y";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Enabled = false;
this->label3->Location = System::Drawing::Point(6, 24);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(83, 12);
this->label3->TabIndex = 5;
this->label3->Text = L"中心点横坐标X";
//
// txtCTX
//
this->txtCTX->Enabled = false;
this->txtCTX->Location = System::Drawing::Point(14, 39);
this->txtCTX->Name = L"txtCTX";
this->txtCTX->Size = System::Drawing::Size(111, 21);
this->txtCTX->TabIndex = 0;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(936, 598);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->tabControl1);
this->Controls->Add(this->groupBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"数值作业:逼近";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->numericUpDown_Input))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->tabControl1->ResumeLayout(false);
this->tabPage_FunctionShow->ResumeLayout(false);
this->tabPage_ErrorShow->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void ctor() {
this->InitializeComponent();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
pictureBox1->BackColor = Color::White;
pictureBox2->BackColor = Color::White;
//
//Connect the Paint event of the PictureBox to the event handler method.
pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &Form1::pictureBox1_Paint );
this->listBox_nGrid->SetSelected(0,true);
this->listBox_Method->SetSelected(0,true);
}
private:System::Void pictureBox1_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^ e )
{
// Create a local version of the graphics object for the PictureBox.
}
private: System::Void btnStart_Click(System::Object^ sender, System::EventArgs^ e) {
if(numericUpDown_Input->Text==""){
MessageBox::Show( "您必须输入误差或者", "Name Entry Error",
MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
}
else
{
Method mthd=Taylor;
if(this->listBox_Method->Text=="Taylor")mthd=Taylor;
else if(this->listBox_Method->Text=="Lagrange")mthd=Lagrange;
if(!radioByError->Checked)
{
int nOrder=Convert::ToInt32(numericUpDown_Input->Text);
DrawSome(mthd,nOrder,Convert::ToInt32(listBox_nGrid->Text),3000);
lblOrder->Text="阶数n为:"+numericUpDown_Input->Text;
}
else
{
int nOrder=3;
while(DrawSome(mthd,nOrder,Convert::ToInt32(listBox_nGrid->Text),3000)>Math::Pow(10,-Convert::ToDouble(numericUpDown_Input->Text)))
{
nOrder++;
}
lblOrder->Text="阶数n为:"+Convert::ToString(nOrder);
}
}
}
private: System::Void radioByError_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
groupBox1->Text="方式:以误差限计算";
lblInput->Text="误差限:10^-n";
}
private: System::Void radioByOrder_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
groupBox1->Text="方式:以阶数计算";
lblInput->Text="阶数n";
}
private: double DrawSome(Method mthd,int nOrder,int nGrid,int nPoint)
{
Bitmap ^ myBitmap = gcnew Bitmap(pictureBox1->Right,pictureBox1->Bottom);
Graphics ^ g = Graphics::FromImage(myBitmap);
pictureBox1->Image=myBitmap;
cvsFun=gcnew Canvus(pictureBox1->Width,pictureBox1->Height,Point(0,pictureBox1->Height/2),hScrollBar_xscale->Value,hScrollBar_yscale->Value);
//int nGrid=Convert::ToInt32(comboBox_nGrid->Text);
{//坐标系
g->DrawLine(System::Drawing::Pens::Black,0,pictureBox1->Bottom/2,pictureBox1->Right,pictureBox1->Bottom/2);
g->DrawLine(System::Drawing::Pens::Black,0,0,0,pictureBox1->Bottom);
for(double j=0;j<nGrid;j++)
{
double h = (j/ nGrid )*pictureBox1->Height;
g->DrawLine(System::Drawing::Pens::Black,0,h,pictureBox1->Right,h);
g->DrawString( String::Format("{0:E2}",cvsFun->Ytoy(h))/*Convert::ToString(cvsFun->Ytoy(h))*/,
gcnew System::Drawing::Font( "Arial",8 ), System::Drawing::Brushes::Blue, Point(0,h) );
h=(j/ nGrid )*pictureBox1->Width;
g->DrawLine(System::Drawing::Pens::Black,h,0,h,pictureBox1->Width);
g->DrawString( String::Format("{0:E2}",cvsFun->Xtox(h)),
gcnew System::Drawing::Font( "Arial",8 ), System::Drawing::Brushes::Blue, Point(h,pictureBox1->Height/2) );
}
}
double n=nPoint;
GraphicPoint ^p1=GraphicPoint::From(0/n,Math::Sin(0/n),cvsFun);
GraphicPoint ^p2=GraphicPoint::From(1/n,Math::Sin(1/n),cvsFun);
for(double i=0;i<n;i++)
{
double t=i*2*Math::PI/n;
g->DrawLine(System::Drawing::Pens::Red,p1->X(),p1->Y(),p2->X(),p2->Y());
p2=p1;
p1=GraphicPoint::From(t,Math::Sin(t),cvsFun);
}
p1=GraphicPoint::From(0/n,AF::AF_func(0/n,mthd,nOrder),cvsFun);
p2=GraphicPoint::From(1/n,AF::AF_func(1/n,mthd,nOrder),cvsFun);
for(double i=0;i<n;i++)
{
double t=i*2*Math::PI/n;
if(IsInCanvus(myBitmap->Width,myBitmap->Height,p1,p2))g->DrawLine(System::Drawing::Pens::Green,p1->X(),p1->Y(),p2->X(),p2->Y());
p2=p1;
p1=GraphicPoint::From(t,AF::AF_func(t,mthd,nOrder),cvsFun);
}
Bitmap ^ myBitmapErr = gcnew Bitmap(pictureBox2->Right,pictureBox2->Bottom);
Graphics ^ ge = Graphics::FromImage(myBitmapErr);
pictureBox2->Image=myBitmapErr;
double yscale=100000000000000;
double most_err=0;
double most_err_at=0;
for(double i=0;i<n;i++)
{
double t=i*2*Math::PI/n;
double temp=Math::Abs(Math::Sin(t)-AF::AF_func(t,mthd,nOrder));
if(temp>most_err)
{
most_err=temp;
most_err_at=t;
}
yscale=pictureBox2->Height/2/most_err;
}
yscale=yscale*0.9;
/*ge->DrawString( String::Format("最大误差={0:E2}",most_err),
gcnew System::Drawing::Font( "Arial",8 ), System::Drawing::Brushes::Blue, Point(cvsErr->xtoX(most_err_at),cvsErr->ytoY(most_err)) );*/
this->lblDisp2->Text=String::Format("最大误差: {0:E2}",most_err);
cvsErr=gcnew Canvus(pictureBox2->Width,pictureBox2->Height,Point(0,pictureBox2->Height/2),hScrollBar_xscale->Value,yscale);
{//坐标系
ge->DrawLine(System::Drawing::Pens::Black,0,pictureBox2->Bottom/2,pictureBox2->Right,pictureBox2->Bottom/2);
ge->DrawLine(System::Drawing::Pens::Black,0,0,0,pictureBox2->Bottom);
for(double j=0;j<nGrid;j++)
{
double h = (j/ nGrid )*pictureBox2->Height;
ge->DrawLine(System::Drawing::Pens::Black,0,h,pictureBox2->Right,h);
ge->DrawString( String::Format("{0:E2}",cvsErr->Ytoy(h)),
gcnew System::Drawing::Font( "Arial",8 ), System::Drawing::Brushes::Blue, Point(0,h) );
h=(j/ nGrid )*pictureBox2->Width;
ge->DrawLine(System::Drawing::Pens::Black,h,0,h,pictureBox2->Width);
ge->DrawString( String::Format("{0:E2}",cvsErr->Xtox(h)),
gcnew System::Drawing::Font( "Arial",8 ), System::Drawing::Brushes::Blue, Point(h,pictureBox2->Height/2) );
}
}
p1=GraphicPoint::From(0/n,Math::Sin(0)-AF::AF_func(0,mthd,nOrder),cvsErr);
p2=GraphicPoint::From(1/n,Math::Sin(1/n)-AF::AF_func(1/n,mthd,nOrder),cvsErr);
for(double i=0;i<n;i++)
{
double t=i*2*Math::PI/n;
if(IsInCanvus(myBitmap->Width,myBitmap->Height,p1,p2))ge->DrawLine(System::Drawing::Pens::Blue,p1->X(),p1->Y(),p2->X(),p2->Y());
p2=p1;
p1=GraphicPoint::From(t,Math::Sin(t)-AF::AF_func(t,mthd,nOrder),cvsErr);
}
return most_err;
}
private: Boolean IsInCanvus(int w,int h,GraphicPoint^ p1,GraphicPoint^ p2)
{
if(p1->X()<0 ||p1->X()> w)return false;
if(p1->Y()<0 ||p1->Y()> h)return false;
if(p2->X()<0 ||p2->X()> w)return false;
if(p2->Y()<0 ||p2->Y()> h)return false;
return true;
}
private: System::Void listBox_nGrid_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -