http://blog.csdn.net/lightsoure/archive/2010/08/22/5830269.aspx这篇文章中我记录了校准的笨方法,现在稍微完善下这个笨方法,写个线性方程计算器,计算这个公式:
ts->xp=(long) ((a2+(a0*x)+(a1*y))/a6); ts->yp=(long) ((a5+(a3*x)+(a4*y))/a6); //printk("x=%d, y=%d/n",(int) ts->xp,(int) ts->yp);
方法前面也说了,大学也学过了 很简单,列出代码:
//修改方程系数 void CTouchDlg::calculate() { //UpdateData(TRUE); int a2=atoi(cs6);//左上 int b2=atoi(cs7); int c2=atoi(cs10);//左下 int d2=atoi(cs11); int a1=atoi(cs8);//右上 int b1=atoi(cs9); int c1=atoi(cs12);//右下 int d1=atoi(cs13); int e=1;//第1个系数 //开始 int hang=3;//初始化行列 int lie=4; long double a[100][101];//注意类型 long double b[100][101]; //初始化 for(int i=0;i<100;i++) { for(int j=0;j<101;j++) { a[i][j]=0; } } a[0][0]=1; //第1组 a[0][1]=a2; a[0][2]=b2; a[0][3]=0; a[1][0]=1; //第2组 a[1][1]=a1; a[1][2]=b1; a[1][3]=e0; a[2][0]=1; //第3组 a[2][1]=c2; a[2][2]=d2; a[2][3]=0; int z=3; //jisuan { for(int k3=0;k3<100;k3++) { for(int h=0;h<101;h++) { b[k3][h]=a[k3][h]; } } for(int zi=0;zi<z;zi++) { //换列(zi+1);i=zi+1!!!!!!!!!!!!!!!!!!!!!!!111 //....................换列...................... int jilu=-1; for(int v=0;v<(hang-zi);v++)//change!!!!!!!!! { if(b[zi+v][zi]!=0)//changge!!!!!! { jilu=zi+1+v; break; } } if(jilu==-1) { } else { long double kkk=1; //exchange(i,jilu); // int j=jilu;///记录 //.......................交换..............................11111111111111111111 { long double temp=0; for(int t3=0;t3<lie;t3++) { temp=b[zi][t3]; b[zi][t3]=b[jilu-1][t3]; b[jilu-1][t3]=temp; } } //.......................end 交换..............................11111111111111111111 //chengk(i,(1.0/b[i-1][i-1])); //...........................检查.......................................11111111111111 { long double k=(1.0/b[zi][zi]);//注意!!!!!!!!范围 for(int c=0;c<lie;c++) { b[zi][c]=b[zi][c]*k; } } //........................... end 检查....................................... { for(int w=0;w<(hang-zi-1);w++) { if(b[zi][zi]!=0) { kkk=0.0-(b[zi+1+w][zi]/b[zi][zi]); //chengplus(zi+1,kkk,zi+1+1+w); //...........................相乘............................................. for(int t=0;t<lie;t++) { b[zi+1+w][t]+=b[zi][t]*kkk; } //........................... end 相乘........................................ } } }//555555 } //........................end 换列.................................11111111111111111 } for(int zii=0;zii<z;zii++) { //Uhualie(z-zii);i=z-zii;!!!!!!!!!!!!!!!!!!!!!!! //..................................................................22222222222222222 if(b[z-zii-1][z-zii-1]!=0) { long double kkk1=1; for(int w=0;w<(z-zii-1);w++) { if(b[z-zii-1][z-zii-1]!=0) { kkk1=0.0-(b[z-zii-2-w][z-zii-1]/b[z-zii-1][z-zii-1]); // chengplus(i,kkk1,z-zii-1-w); //........................................................................55 for(int t=0;t<lie;t++) { b[z-zii-1-w-1][t]+=b[z-zii-1][t]*kkk1; } //........................... end 55 ........................................ } } } //...........................end 5....................................... }//end 2222222222222222222 //........................... 6666.......................................3333333333333333 for(int zck=0;zck<z;zck++) { if(b[zck][zck]!=0) { //chengk(zck+1,(1.0/b[zck][zck])); long double k2=(1.0/b[zck][zck]); //........................... ....................................... for(int c1=0;c1<lie;c1++) { b[zck][c1]=b[zck][c1]*k2; } //........................... end ....................................... } } //...........................end .......................................333333333333 }//end jisuan { //........................... 打印..................................4444444444444444 int testa=0; int testb=0; for(int m=0;m<hang;m++) { for(int n=0;n<hang;n++) { if(b[m][n]!=0){testb+=1;} } if(testb==0&&b[m][lie-1]!=0){testa+=1;} testb=0; } if(testa!=0) { //wujie } else { //UpdateData(TRUE); //cout <<"x" <<n+1 <<"=" <<b[n][lie-1] <<" "; //m_edt3.Format("%d",atoi(m_edt2) + atoi(m_edt1));xianshi long double d1=b[0][3]; long double d2=b[1][3]; long double d3=b[2][3]; long double d4=b[2][3]; cs0.Format("%lf",d1); cs1.Format("%lf",d2); cs2.Format("%lf",d3); UpdateData(FALSE); } //...........................end printb.................................4444444444444444 } }
好了,这里仅做这1步记录,下篇分享在android写校准程序,开机自动校准。