📄 form1.cs
字号:
//
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.textBox10);
this.groupBox3.Controls.Add(this.textBox9);
this.groupBox3.Controls.Add(this.textBox8);
this.groupBox3.Controls.Add(this.textBox7);
this.groupBox3.Controls.Add(this.textBox6);
this.groupBox3.Controls.Add(this.textBox5);
this.groupBox3.Location = new System.Drawing.Point(0, 272);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(672, 80);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "转换参数";
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 24);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(616, 16);
this.label5.TabIndex = 7;
this.label5.Text = " a b c d e " +
" f ";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(552, 48);
this.textBox10.Name = "textBox10";
this.textBox10.Size = new System.Drawing.Size(96, 21);
this.textBox10.TabIndex = 6;
this.textBox10.Text = "";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(440, 48);
this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(104, 21);
this.textBox9.TabIndex = 5;
this.textBox9.Text = "";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(120, 48);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(96, 21);
this.textBox8.TabIndex = 4;
this.textBox8.Text = "";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(224, 48);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(96, 21);
this.textBox7.TabIndex = 3;
this.textBox7.Text = "";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(328, 48);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(104, 21);
this.textBox6.TabIndex = 2;
this.textBox6.Text = "";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(16, 48);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(96, 21);
this.textBox5.TabIndex = 1;
this.textBox5.Text = "";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem5});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem2});
this.menuItem1.Text = "项目";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "由坐标求仿射参数";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "仿射变换";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click_1);
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4});
this.menuItem5.Text = "转换";
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "执行";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(688, 365);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
double x1,x2,x3,y1,y2,y3,xx1,xx2,xx3,yy1,yy2,yy3,a,b,c,d,ee,f;
double s1,s2,s3,s4,s5,s6;
x1=double.Parse(this.textBox1.Text) ;
y1=double.Parse(this.textBox2.Text );
x2=double.Parse(this.textBox11.Text) ;
y2=double.Parse(this.textBox12.Text );
x3=double.Parse(this.textBox13.Text) ;
y3=double.Parse(this.textBox14.Text );
if (isaffirm==true)
{
a=double.Parse(this.textBox5.Text );
b=double.Parse(this.textBox8.Text );
c=double.Parse(this.textBox7.Text );
d=double.Parse(this.textBox6.Text );
ee=double.Parse(this.textBox9.Text );
f=double.Parse(this.textBox10.Text );
affirm(x1, y1, a, b, c, d, ee, f,out s1, out s2);
affirm(x2, y2, a, b, c, d, ee, f,out s3, out s4);
affirm(x3, y3, a, b, c, d, ee, f,out s5, out s6);
textBox3.Text = s1.ToString() ;
textBox4.Text = s2.ToString();
textBox15.Text = s3.ToString();
textBox16.Text = s4.ToString();
textBox17.Text = s5.ToString();
textBox18.Text = s6.ToString();
}
else
{
Form1 frm=new Form1();
xx1=double.Parse(this.textBox3.Text) ;
yy1=double.Parse(this.textBox4.Text );
xx2=double.Parse(this.textBox15.Text) ;
yy2=double.Parse(this.textBox16.Text );
xx3=double.Parse(this.textBox17.Text) ;
yy3=double.Parse(this.textBox18.Text );
//frm.inatitate(x1,y1,x2,y2,x3,y3,xx1,xx2,xx3,out a,out b,out c);
//frm.inatitate(x1,y1,x2,y2,x3,y3,yy1,yy2,yy3,out d,out ee,out f);
frm.fcan(x1,y1,x2,y2,x3,y3,xx1,xx2,xx3,out a,out b,out c);
frm.fcan(x1,y1,x2,y2,x3,y3,yy1,yy2,yy3,out d,out ee,out f);
textBox5.Text = a.ToString() ;
textBox8.Text = b.ToString();
textBox7.Text = c.ToString();
textBox6.Text = d.ToString();
textBox9.Text = ee.ToString();
textBox10.Text = f.ToString();
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
isaffirm=false;
menuItem2.Checked =false;
menuItem3.Checked =true;
}
public void affirm(double x1,double y1,double a, double b,double c,double d,double e,double f,out double x2,out double y2)
{
double s,x22,y22;
s=a*e-b*d;
x22=y22=0;
if (s==0)
{
MessageBox.Show ("参数不合法!");
}
else
{
x22=x1*a+y1*b+c;
y22=x1*d+y1*e+f;
}
x2=x22;
y2=y22;
}
private void menuItem2_Click_1(object sender, System.EventArgs e)
{
isaffirm=true;
menuItem2.Checked=true;
menuItem3.Checked =false;
}
/*
private void inatitate(double x1,double y1,double x2, double y2,double x3,double y3,double xx1, double xx2, double xx3,out double xa,out double xb,out double xc)
{
int n=3;
double mx,tmp;
int mi;
a=new double[3,3];
b=new double[3];
x=new double[3];
//输入Ax=b的A矩阵
a[0,0]=x1;
a[0,1]=y1;
a[0,2]=a[1,2]=a[2,2]=1;
a[1,0]=x2;
a[1,1]=y2;
a[2,0]=x3;
a[2,1]=y3;
//输入b向量
b[0]=xx1;
b[1]=xx2;
b[2]=xx3;
for(int i=0;i<n; i++)
{
for(int j=i+1;j<n;j++) //找主元素
{
mi=i;
mx=System.Math.Abs(a[i,i]);
if(System.Math.Abs(a[j,i])>mx)
{
mi=j;
mx=System.Math.Abs(a[j,i]);
if(i<mi) //交换两行
{
tmp=b[i];
b[i]=b[mi];
b[mi]=tmp;
for(int k=i; k<n; k++)
{
tmp=a[i,k];
a[i,k]=a[mi,k];
a[mi,k]= tmp;
}
}
for(int f=i+1; f<n; f++) //高斯消元
{
tmp=-a[f,i]/a[i,i];
b[f]+=b[i]*tmp;
for(int kk=i; kk<n; kk++)
{
a[f,kk]=a[f,kk]+a[i,kk]*tmp;
}
}
}
}
}
x[n-1]=b[n-1]/a[n-1,n-1]; //求解方程
for(int ii=n-2; ii>=0; ii--)
{
x[ii]=b[ii];
for(int h=ii+1;h<n; h++)
{
x[ii] =x[ii]-a[ii,h]*x[h];
x[ii]=x[ii]/a[ii,ii];
}
}
xa=x[0];
xb=x[1];
xc=x[2];
}
*/
private void fcan(double x1,double y1,double x2, double y2,double x3,double y3,double xx1, double xx2, double xx3,out double xa,out double xb,out double xc)
{
a=new double[3,4];
double client,temp=0;
int n=3 ;
double h;
//输入Ax=b的A矩阵
a[0,0]=x1;
a[0,1]=y1;
a[0,2]=a[1,2]=a[2,2]=1;
a[1,0]=x2;
a[1,1]=y2;
a[2,0]=x3;
a[2,1]=y3;
//输入b向量
a[0,3]=xx1;
a[1,3]=xx2;
a[2,3]=xx3;
/*
//检查
a[0,0]=3;
a[0,1]=1;
a[0,2]=1;
a[0,3]=13;
a[1,0]=7;
a[1,1]=2;
a[1,2]=3;
a[1,3]=31;
a[2,0]=2;
a[2,1]=7;
a[2,2]=2;
a[2,3]=38;
*/
for(int k = 0; k < n - 1; k++)
{
for(int i = k + 1; i < n; i++)
{
client = a[i,k]/a[k,k];
for( int j = k + 1; j < n; j++)
{
a[i,j] = a[i,j] - client * a[k,j];
}
a[i,n] = a[i,n] - client * a[k,n];
}
}
a[n - 1,n] = a[n - 1,n]/a[n - 1,n - 1];
for(int i = n - 2; i >= 0; i--)
{
for (int j = i + 1; j < n; j++)
{
temp = temp + a[i,j] * a[j,n];
}
a[i,n] = (a[i,n] - temp) / a[i,i];
temp=0;
}
xa=a[0,3];
xb=a[1,3];
xc=a[2,3];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -