当前位置:文档之家› DLT 直接线性变换解法程序

DLT 直接线性变换解法程序

DLT 直接线性变换解法程序介绍一、程序综合介绍:DLT结算程序程序功能介绍:应用6个已知点计算左右片l 系数;然后应用已经求得的l系数求解物方空间坐标系坐标程序名:SuYGDLT程序界面:程序界面有四个按钮,分别为读取文件,左片l系数计算,右片系数计算,物放坐标解算程序界面有四个编辑框,分别用来输出文件信息,左片l系数、右片l系数、以及无妨坐标结果截图如下程序使用介绍:必须先点击导入文件按钮,导入文件方可进行正确的计算,如果未导入文件就点击左片平差或右片平差或无妨坐标解算就会弹出如下对话框:读取数据后点击其它按钮进行其它计算。

程序文件格式:数据文件分为两部分,KnownPoint,UNKnownPoint,分别代表已知点信息和待求点信息当文件读取程序读到“KnownPoint”时开始读取已知点信息,已知点信息格式如下GCP1,1214.0000,1032.0000,1046.5180,1071.6652,9.201742,-9.672384,-2.726064分别代表点名、左片相片X坐标、左片相片y坐标、右片相片x坐标、右片相片y坐标物方坐标X、Y、Z;当文件读取到“END KnownPoint”时结束已知坐标的读取待求点信息类似:文件格式截图如下:程序运行结果与评估:本程序区1-10号点作为已知点计算l近似值11-20号点作为未知点解求其物方三维坐标;程序运行结果与所给参考值相似,应该可以证明其运算是正确的,运行结果截图如下:二、程序编程思想及相关代码程序编程思想及相关函数:本程序设计DLTCalculation类作为l系数结算主程序,其成员变量及成员函数与作用介绍如下:CSuLMatrix LL;//左片L系数矩阵CSuLMatrix RL;//右片L系数矩阵int m_iKnownPointCount;//已知点个数CControlPoint *m_pKnownPoint;//已知点int m_iUnKnownPointCount;//未知点个数CControlPoint *m_pUnKnownPoint;//未知点public:CString LoadData(const CString& strFileName);//读取文件函数int ifLoda;//判断是否导入数据CString Datainfor;//文件信息存储CString *SplitString(CString str,char split, int& iSubStrs); //分割函数void LFormApproL(CSuLMatrix &LL);//计算左片L系数近似值void RFormApproL(CSuLMatrix &RL);//计算右片L系数近似值void FormLErrorEquations(CSuLMatrix LL,CMatrix &LM,CMatrix &LW);//组成左片系数矩阵和常数项矩阵void LAdjust();//左片平差主函数void FormRErrorEquations(CSuLMatrix RL,CMatrix &RM,CMatrix &RW);//组成右片系数矩阵和常数项矩阵void RAdjust();//右片平差主函数void Output(const CString& strFileName);//输出结果主程序void OutMatrixToFile(const CMatrix& mat,CStdioFile& SF);//输出矩阵总程序另外设计类qianfangjiaohui作为结算物放坐标解算主程序其成员变量与成员函数及其作用介绍如下:void FormApproCoor( DLTCalculation &R);//计算无妨坐标近似值void FormErrorEquations(DLTCalculation &R,CMatrix &N,CMatrix &Q);//解求系数矩阵void Adjust(DLTCalculation &R);//平差计算物放坐标程序详细代码粘贴如下:以下为类DLTCalculation.cpp文件详细内容:#include"StdAfx.h"#include"DLTCalculation.h"#include<locale>#include"SuLMatrix.h"DLTCalculation::DLTCalculation(void){ifLoda=0;}DLTCalculation::~DLTCalculation(void){}CString* DLTCalculation::SplitString(CString str,char split, int& iSubStrs){int iPos = 0; //分割符位置int iNums = 0; //分割符的总数CString strTemp = str;CString strRight;//先计算子字符串的数量while (iPos != -1){iPos = strTemp.Find(split);if (iPos == -1){break;}strRight = strTemp.Mid(iPos + 1, str.GetLength());strTemp = strRight;iNums++;}if (iNums == 0) //没有找到分割符{//子字符串数就是字符串本身iSubStrs = 1;return NULL;}//子字符串数组iSubStrs = iNums + 1; //子串的数量= 分割符数量+ 1CString* pStrSplit;pStrSplit = new CString[iSubStrs];strTemp = str;CString strLeft;for (int i = 0; i < iNums; i++){iPos = strTemp.Find(split);//左子串strLeft = strTemp.Left(iPos);//右子串strRight = strTemp.Mid(iPos + 1, strTemp.GetLength());strTemp = strRight;pStrSplit[i] = strLeft;}pStrSplit[iNums] = strTemp;return pStrSplit;}CString DLTCalculation::LoadData(const CString& strFileName){ifLoda=1;CString strputdata;//用于保存观测文件的字符串CStdioFile sf;//创建文件对象setlocale(LC_ALL,""); //设置语言环境if(!sf.Open(strFileName, CFile::modeRead)) return _T("文件打开失败");;//以读的形式打来文件,如果打开失败则返回CString strLine;int n;CString *strTmp=NULL;do{sf.ReadString (strLine);strputdata+=strLine;strputdata+=_T("\r\n");}while(strLine!="KnownPoint");Datainfor=strputdata;if(strLine=="KnownPoint")//读取已知数据while(strLine!=_T("END KnownPoint")){sf.ReadString (strLine);strputdata+=strLine;strputdata+=_T("\r\n");if(strLine!=_T("END KnownPoint")){strTmp = SplitString(strLine, ',',n);}elsebreak;if(strTmp[0]=="KnownPointCount"){m_iKnownPointCount=_ttoi(strTmp[1]);m_pKnownPoint=new CControlPoint[m_iKnownPointCount];if(strTmp!=NULL)//释放内存{delete[] strTmp;strTmp=NULL;}for(int i=0;i<m_iKnownPointCount;i++){sf.ReadString (strLine);strputdata+=strLine;strputdata+=_T("\r\n");strTmp = SplitString(strLine, ',',n);m_pKnownPoint[i].strName =strTmp[0];m_pKnownPoint[i].Lx =_tstof(strTmp[1]);m_pKnownPoint[i].Ly =_tstof(strTmp[2]);m_pKnownPoint[i].Rx =_tstof(strTmp[3]);m_pKnownPoint[i].Ry =_tstof(strTmp[4]);m_pKnownPoint[i].X =_tstof(strTmp[5]);m_pKnownPoint[i].Y =_tstof(strTmp[6]);m_pKnownPoint[i].Z =_tstof(strTmp[7]);if(strTmp!=NULL)//释放内存{delete[] strTmp;strTmp=NULL;}}}}sf.ReadString (strLine);strputdata+=strLine;strputdata+=_T("\r\n");if(strLine=="UnknownPoint")//读取未知数据{while(strLine!=_T("END UnknownPoint")){sf.ReadString (strLine);strputdata+=strLine;strputdata+=_T("\r\n");if(strLine!=_T("END UnknownPoint")){strTmp = SplitString(strLine, ',',n);}elsebreak;if(strTmp[0]=="UnknownPointCount"){m_iUnKnownPointCount=_ttoi(strTmp[1]);m_pUnKnownPoint=new CControlPoint[m_iUnKnownPointCount];if(strTmp!=NULL)//释放内存{delete[] strTmp;strTmp=NULL;}for(int i=0;i<m_iUnKnownPointCount;i++){sf.ReadString (strLine);strputdata+=strLine;strputdata+=_T("\r\n");strTmp = SplitString(strLine, ',',n);m_pUnKnownPoint[i].strName =strTmp[0];m_pUnKnownPoint[i].Lx =_tstof(strTmp[1]);m_pUnKnownPoint[i].Ly =_tstof(strTmp[2]);m_pUnKnownPoint[i].Rx =_tstof(strTmp[3]);m_pUnKnownPoint[i].Ry =_tstof(strTmp[4]);if(strTmp!=NULL)//释放内存{delete[] strTmp;strTmp=NULL;}}}}}sf.Close ();return strputdata;}void DLTCalculation::LFormApproL(CSuLMatrix &LL)//计算左片L系数近似值{CMatrix LX(11,1);CMatrix LB(11,11);CMatrix Lf(11,1);for(int i=0;i<5;i++){LB(2*i,0) = LB(2*i+1,4) = m_pKnownPoint[i].X*1000;LB(2*i,1) = LB(2*i+1,5) = m_pKnownPoint[i].Y*1000;LB(2*i,2) = LB(2*i+1,6) = m_pKnownPoint[i].Z*1000;LB(2*i,3) = LB(2*i+1,7) = 1;LB(2*i,4) = LB(2*i,5) = LB(2*i,6) = LB(2*i,7) = LB(2*i+1,0) = LB(2*i+1,1) = LB(2*i+1,2) = LB(2*i+1,3) = 0;LB(2*i,8) = m_pKnownPoint[i].Lx * m_pKnownPoint[i].X*1000;LB(2*i,9) = m_pKnownPoint[i].Lx * m_pKnownPoint[i].Y*1000;LB(2*i,10) = m_pKnownPoint[i].Lx * m_pKnownPoint[i].Z*1000;LB(2*i+1,8) = m_pKnownPoint[i].Ly * m_pKnownPoint[i].X*1000;LB(2*i+1,9) = m_pKnownPoint[i].Ly * m_pKnownPoint[i].Y*1000;LB(2*i+1,10) = m_pKnownPoint[i].Ly * m_pKnownPoint[i].Z*1000;}LB(10,0) = m_pKnownPoint[5].X*1000;LB(10,1) = m_pKnownPoint[5].Y*1000;LB(10,2) = m_pKnownPoint[5].Z*1000;LB(10,3) = 1;LB(10,4) = LB(10,5) = LB(10,6) = LB(10,7) = 0;LB(10,8) = m_pKnownPoint[5].Lx * m_pKnownPoint[5].X*1000;LB(10,9) = m_pKnownPoint[5].Lx * m_pKnownPoint[5].Y*1000;LB(10,10) = m_pKnownPoint[5].Lx * m_pKnownPoint[5].Z*1000;for(int i=0;i<5;i++){Lf(2*i,0) = m_pKnownPoint[i].Lx;Lf(2*i+1,0) = m_pKnownPoint[i].Ly;}Lf(10,0) = m_pKnownPoint[5].Lx;LX = (-1)*(LB.Inv())*Lf;LL.l1 = LX(0,0);LL.l2 = LX(1,0);LL.l3 = LX(2,0);LL.l4 = LX(3,0);LL.l5 = LX(4,0);LL.l6 = LX(5,0);LL.l7 = LX(6,0);LL.l8 = LX(7,0);LL.l9 = LX(8,0);LL.l10 = LX(9,0);LL.l11 = LX(10,0);}void DLTCalculation::RFormApproL(CSuLMatrix &RL)//计算右片L系数近似值{CMatrix RX(11,1);CMatrix RB(11,11);CMatrix Rf(11,1);for(int i=0;i<5;i++){RB(2*i,0) = RB(2*i+1,4) = m_pKnownPoint[i].X*1000;RB(2*i,1) = RB(2*i+1,5) = m_pKnownPoint[i].Y*1000;RB(2*i,2) = RB(2*i+1,6) = m_pKnownPoint[i].Z*1000;RB(2*i,3) = RB(2*i+1,7) = 1;RB(2*i,4) = RB(2*i,5) = RB(2*i,6) = RB(2*i,7) = RB(2*i,7) = RB(2*i+1,0) = RB(2*i+1,1) = RB(2*i+1,2) = RB(2*i+1,3) = 0;RB(2*i,8) = m_pKnownPoint[i].Rx * m_pKnownPoint[i].X*1000;RB(2*i,9) = m_pKnownPoint[i].Rx * m_pKnownPoint[i].Y*1000;RB(2*i,10) = m_pKnownPoint[i].Rx * m_pKnownPoint[i].Z*1000;RB(2*i+1,8) = m_pKnownPoint[i].Ry * m_pKnownPoint[i].X*1000;RB(2*i+1,9) = m_pKnownPoint[i].Ry * m_pKnownPoint[i].Y*1000;RB(2*i+1,10) = m_pKnownPoint[i].Ry * m_pKnownPoint[i].Z*1000;}RB(10,0) = m_pKnownPoint[5].X*1000;RB(10,1) = m_pKnownPoint[5].Y*1000;RB(10,2) = m_pKnownPoint[5].Z*1000;RB(10,3) = 1;RB(10,4) = RB(10,5) = RB(10,6) = RB(10,7) = 0;RB(10,8) = m_pKnownPoint[5].Rx * m_pKnownPoint[5].X*1000;RB(10,9) = m_pKnownPoint[5].Rx * m_pKnownPoint[5].Y*1000;RB(10,10) = m_pKnownPoint[5].Rx * m_pKnownPoint[5].Z*1000;for(int i=0;i<5;i++){Rf(2*i,0) = m_pKnownPoint[i].Rx;Rf(2*i+1,0) = m_pKnownPoint[i].Ry;}Rf(10,0) = m_pKnownPoint[5].Rx;RX = (-1)*(RB.Inv())*Rf;RL.l1 = RX(0,0);RL.l2 = RX(1,0);RL.l3 = RX(2,0);RL.l4 = RX(3,0);RL.l5 = RX(4,0);RL.l6 = RX(5,0);RL.l7 = RX(6,0);RL.l8 = RX(7,0);RL.l9 = RX(8,0);RL.l10 = RX(9,0);RL.l11 = RX(10,0);}void DLTCalculation::FormLErrorEquations(CSuLMatrix LL,CMatrix &LM,CMatrix &LW)//组成左片系数矩阵和常数项矩阵{LM.SetSize(2*m_iUnKnownPointCount,12);LW.SetSize(2*m_iUnKnownPointCount,1);//LFormApproL(LL);double A;double x0,y0;double r;for(int i=0;i<m_iKnownPointCount;i++){A = LL.l9 * m_pKnownPoint[i].X * 1000 + LL.l10 * m_pKnownPoint[i].Y * 1000 + LL.l1 *m_pKnownPoint[i].Z * 1000 + 1;x0 = (-1)*(LL.l1 * LL.l9 + LL.l2 * LL.l10 + LL.l3 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);y0 = (-1)*(LL.l5 * LL.l9 + LL.l6 * LL.l10 + LL.l7 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);r = sqrt((m_pKnownPoint[i].Lx-x0)*(m_pKnownPoint[i].Lx-x0) +(m_pKnownPoint[i].Ly-y0)*(m_pKnownPoint[i].Ly-y0));LM(2*i,0) = LM(2*i+1,4) = (-1)*m_pKnownPoint[i].X * 1000 /A;LM(2*i,1) = LM(2*i+1,5) = (-1)*m_pKnownPoint[i].Y * 1000 /A;LM(2*i,2) = LM(2*i+1,6) = (-1)*m_pKnownPoint[i].Z * 1000 /A;LM(2*i,3) = LM(2*i+1,7) = (-1)*1/A;LM(2*i,4) = LM(2*i,5) = LM(2*i,6) = LM(2*i,7) = LM(2*i+1,0) = LM(2*i+1,1) = LM(2*i+1,2) = LM(2*i+1,3) = 0;LM(2*i,8) = (-1)*m_pKnownPoint[i].Lx * m_pKnownPoint[i].X* 1000 /A;LM(2*i,9) = (-1)*m_pKnownPoint[i].Lx * m_pKnownPoint[i].Y* 1000 /A;LM(2*i,10) = (-1)*m_pKnownPoint[i].Lx * m_pKnownPoint[i].Z* 1000 /A;LM(2*i,11) = (-1)*(m_pKnownPoint[i].Lx - x0) * r * r;LM(2*i+1,8) = (-1)*m_pKnownPoint[i].Ly * m_pKnownPoint[i].X* 1000 /A;LM(2*i+1,9) = (-1)*m_pKnownPoint[i].Ly * m_pKnownPoint[i].Y* 1000 /A;LM(2*i+1,10) = (-1)*m_pKnownPoint[i].Ly * m_pKnownPoint[i].Z* 1000 /A;LM(2*i+1,11) = (-1)*(m_pKnownPoint[i].Ly - y0) * r * r;LW(2*i,0) = (-1)*m_pKnownPoint[i].Lx/A;LW(2*i+1,0) = (-1)*m_pKnownPoint[i].Ly/A;}}void DLTCalculation::OutMatrixToFile(const CMatrix& mat,CStdioFile& SF) {CString strLine,strTmp;for(int i=0;i<mat.Row();i++){strLine.Empty();for(int j=0;j<mat.Col();j++){strTmp.Format(_T("%.4f "),mat(i,j));strLine=strLine+strTmp;}SF.WriteString(strLine+_T("\r\n"));}}void DLTCalculation::LAdjust()//左片平差主函数{CMatrix LM(2*m_iUnKnownPointCount,12);CMatrix LW(2*m_iUnKnownPointCount,1);CMatrix LNbb(12,12);CMatrix LNvv(12,1);CMatrix LV(12,1);int Ln = 0;CString strputdata;double x0,y0;double A,B,C;double fx;double x00,y00;double A0,B0,C0;double fx0;double dfx;LFormApproL(LL);x00 = (-1)*(LL.l1 * LL.l9 + LL.l2 * LL.l10 + LL.l3 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);y00 = (-1)*(LL.l5 * LL.l9 + LL.l6 * LL.l10 + LL.l7 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);A0 = (LL.l1 * LL.l1 + LL.l2 * LL.l2 + LL.l3 * LL.l3)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 *LL.l11)-x00*x00;B0 = (LL.l5 * LL.l5 + LL.l6 * LL.l6 + LL.l7 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 *LL.l11)-y00*y00;C0 = (LL.l1 * LL.l5 + LL.l2 * LL.l6 + LL.l3 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 *LL.l11)-x00*y00;fx0 = sqrt((A0*B0-C0*C0)/B0);/*do{FormLErrorEquations(LL,LM,LW);LNbb=(~LM)*LM;LNvv=(~LM)*LW;LV=(LNbb.Inv())*LNvv;LL.l1=LV(0,0);LL.l2=LV(1,0);LL.l3=LV(2,0);LL.l4=LV(3,0);LL.l5=LV(4,0);LL.l6=LV(5,0);LL.l7=LV(6,0);LL.l8=LV(7,0);LL.l9=LV(8,0);LL.l10=LV(9,0);LL.l11=LV(10,0);x0 = (-1)*(LL.l1 * LL.l9 + LL.l2 * LL.l10 + LL.l3 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);y0 = (-1)*(LL.l5 * LL.l9 + LL.l6 * LL.l10 + LL.l7 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);A = (LL.l1 * LL.l1 + LL.l2 * LL.l2 + LL.l3 * LL.l3)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11)-x0*x0;B = (LL.l5 * LL.l5 + LL.l6 * LL.l6 + LL.l7 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11)-y0*y0;C = (LL.l1 * LL.l5 + LL.l2 * LL.l6 + LL.l3 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11)-x0*y0;fx = sqrt((A*B-C*C)/B);dfx = fx - fx0;fx0 = fx;Ln++;}while(fabs(dfx)>0.01);*/}void DLTCalculation::Output(const CString& strFileName){CStdioFile SF;CString strLine;setlocale(LC_ALL,"");if(!SF.Open(strFileName, CFile::modeCreate|CFile::modeWrite)) return;//开始写数据SF.WriteString(_T("结果输出:\n"));SF.WriteString(_T("---------空间后方交汇----------\n"));CMatrix LM(2*m_iKnownPointCount,12);CMatrix LW(2*m_iKnownPointCount,1);CMatrix LNbb(12,12);CMatrix LNvv(12,1);CMatrix LV(12,1);int Ln = 0;CString strputdata;double x0,y0;double A,B,C;double fx;double x00,y00;double A0,B0,C0;double fx0;double dfx;LFormApproL(LL);x00 = (-1)*(LL.l1 * LL.l9 + LL.l2 * LL.l10 + LL.l3 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);y00 = (-1)*(LL.l5 * LL.l9 + LL.l6 * LL.l10 + LL.l7 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);A0 = (LL.l1 * LL.l1 + LL.l2 * LL.l2 + LL.l3 * LL.l3)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 *LL.l11)-x00*x00;B0 = (LL.l5 * LL.l5 + LL.l6 * LL.l6 + LL.l7 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 *LL.l11)-y00*y00;C0 = (LL.l1 * LL.l5 + LL.l2 * LL.l6 + LL.l3 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 *LL.l11)-x00*y00;fx0 = sqrt((A0*B0-C0*C0)/B0);/*do{*/FormLErrorEquations(LL,LM,LW);LNbb=(~LM)*LM;LNvv=(~LM)*LW;OutMatrixToFile(LM,SF);/*LV=LNbb.Inv();*//*LV=(LNbb.Inv())*LNvv;*//*LL.l1+=LV(0,0);LL.l2+=LV(1,0);LL.l3+=LV(2,0);LL.l4+=LV(3,0);LL.l5+=LV(4,0);LL.l6+=LV(5,0);LL.l7+=LV(6,0);LL.l8+=LV(7,0);LL.l9+=LV(8,0);LL.l10+=LV(9,0);LL.l11+=LV(10,0);x0 = (-1)*(LL.l1 * LL.l9 + LL.l2 * LL.l10 + LL.l3 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);y0 = (-1)*(LL.l5 * LL.l9 + LL.l6 * LL.l10 + LL.l7 * LL.l11)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11);A = (LL.l1 * LL.l1 + LL.l2 * LL.l2 + LL.l3 * LL.l3)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11)-x0*x0;B = (LL.l5 * LL.l5 + LL.l6 * LL.l6 + LL.l7 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11)-y0*y0;C = (LL.l1 * LL.l5 + LL.l2 * LL.l6 + LL.l3 * LL.l7)/(LL.l9 * LL.l9 + LL.l10 * LL.l10 + LL.l11 * LL.l11)-x0*y0;fx = sqrt((A*B-C*C)/B);dfx = fx - fx0;fx0 = fx;Ln++;*/////}while(fabs(dfx)>0.01);CString putdata;putdata.Format(_T("%s\r\n"),_T("左片结果"));strputdata+=putdata;putdata.Format(_T("%s\r\n"),_T("L系数为:"));strputdata+=putdata;putdata.Format(_T("%s%.5f\r\n%s%.5f\r\n%s%.5f\r\n%s%.5f\r\n%s%.5f\r\n%s%.5f\r\n%s%.5f\r\n%s%.5f\r \n%s%.5f\r\n%s%.5f\r\n%s%.5f\r\n"),_T("l1 = "),LL.l1,_T("l2 = "),LL.l2,_T("l3 = "),LL.l3,_T("l4 = "),LL.l4,_T("l5 = "),LL.l5,_T("l6 = "),LL.l6,_T("l7 = "),LL.l7,_T("l8 = "),LL.l8,_T("l9 = "),LL.l9,_T("l10 = "),LL.l10,_T("l11 = "),LL.l11);strputdata+=putdata;SF.WriteString(strputdata);//putdata.Format(_T("%s%d\r\n"),_T("迭代次数为:"),Ln);///*strputdata+=putdata;*/}void DLTCalculation::RAdjust()//右片平差主函数{CMatrix RM(2*m_iKnownPointCount,12);CMatrix RW(2*m_iKnownPointCount,1);CMatrix RNbb(12,12);CMatrix RNvv(12,1);CMatrix RV(12,1);int Rn = 0;CString strputdata;double x0,y0;double A,B,C;double fx;double x00,y00;double A0,B0,C0;double fx0;double dfx;RFormApproL(RL);//x00 = (-1)*(RL.l1 * RL.l9 + RL.l2 * RL.l10 + RL.l3 * RL.l11)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11);//y00 = (-1)*(RL.l5 * RL.l9 + RL.l6 * RL.l10 + RL.l7 * RL.l11)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11);//A0 = (RL.l1 * RL.l1 + RL.l2 * RL.l2 + RL.l3 * RL.l3)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11)-x00*x00;//B0 = (RL.l5 * RL.l5 + RL.l6 * RL.l6 + RL.l7 * RL.l7)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11)-y00*y00;//C0 = (RL.l1 * RL.l5 + RL.l2 * RL.l6 + RL.l3 * RL.l7)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11)-x00*y00;//fx0 = sqrt((A0*B0-C0*C0)/B0);///*do*///{// FormRErrorEquations(RL,RM,RW);// RNbb = (~RM)*RM;// RNvv = (~RM)*RW;///* RV = (RNbb.Inv())*RNvv;*/// //RL.l1+=RV(0,0);RL.l2+=RV(1,0);RL.l3+=RV(2,0);RL.l4+=RV(3,0);// //RL.l5+=RV(4,0);RL.l6+=RV(5,0);RL.l7+=RV(6,0);RL.l8+=RV(7,0);// //RL.l9+=RV(8,0);RL.l10+=RV(9,0);RL.l11+=RV(10,0);x0 = (-1)*(RL.l1 * RL.l9 + RL.l2 * RL.l10 + RL.l3 * RL.l11)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11);y0 = (-1)*(RL.l5 * RL.l9 + RL.l6 * RL.l10 + RL.l7 * RL.l11)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11);A = (RL.l1 * RL.l1 + RL.l2 * RL.l2 + RL.l3 * RL.l3)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11)-x0*x0;B = (RL.l5 * RL.l5 + RL.l6 * RL.l6 + RL.l7 * RL.l7)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11)-y0*y0;C = (RL.l1 * RL.l5 + RL.l2 * RL.l6 + RL.l3 * RL.l7)/(RL.l9 * RL.l9 + RL.l10 * RL.l10 + RL.l11 * RL.l11)-x0*y0;/* fx = sqrt((A*B-C*C)/B);dfx = fx - fx0;fx0 = fx;Rn++;*///}/*while(abs(dfx)>0.01);*///}类qianfangjiaohui 的cpp文件代码粘贴如下:#include"StdAfx.h"#include"qianfangjiaohui.h"qianfangjiaohui::qianfangjiaohui(void){}qianfangjiaohui::~qianfangjiaohui(void){}void qianfangjiaohui::FormApproCoor(DLTCalculation &R){CMatrix A(3,3);CMatrix f(3,1);CMatrix X(3,1);for(int i=0;i<R.m_iUnKnownPointCount;i++){A(0,0) = R.LL.l1 + R.m_pUnKnownPoint[i].Lx * R.LL.l9;A(0,1) = R.LL.l2 + R.m_pUnKnownPoint[i].Lx * R.LL.l10;A(0,2) = R.LL.l3 + R.m_pUnKnownPoint[i].Lx * R.LL.l11;A(1,0) = R.LL.l5 + R.m_pUnKnownPoint[i].Ly * R.LL.l9;A(1,1) = R.LL.l6 + R.m_pUnKnownPoint[i].Ly * R.LL.l10;A(1,2) = R.LL.l7 + R.m_pUnKnownPoint[i].Ly * R.LL.l11;A(2,0) = R.RL.l1 + R.m_pUnKnownPoint[i].Rx * R.RL.l9;A(2,1) = R.RL.l2 + R.m_pUnKnownPoint[i].Rx * R.RL.l10;A(2,2) = R.RL.l3 + R.m_pUnKnownPoint[i].Rx * R.RL.l11;f(0,0) = R.LL.l4 + R.m_pUnKnownPoint[i].Lx;f(1,0) = R.LL.l8 + R.m_pUnKnownPoint[i].Ly;f(2,0) = R.RL.l4 + R.m_pUnKnownPoint[i].Rx;X = (-1)*(A.Inv())*f;R.m_pUnKnownPoint[i].X = X(0,0)/1000;R.m_pUnKnownPoint[i].Y = X(1,0)/1000;R.m_pUnKnownPoint[i].Z = X(2,0)/1000;}}void qianfangjiaohui::FormErrorEquations(DLTCalculation &R,CMatrix &N,CMatrix &Q){N.SetSize(4,3);Q.SetSize(4,1);double LA,RA;for(int i=0;i<R.m_iUnKnownPointCount;i++){LA=R.LL.l9*R.m_pUnKnownPoint[i].X+R.LL.l10*R.m_pUnKnownPoint[i].Y+R.LL.l11*R.m_pUnKnown Point[i].Z+1;RA=R.RL.l9*R.m_pUnKnownPoint[i].X+R.RL.l10*R.m_pUnKnownPoint[i].Y+R.RL.l11*R.m_pUnKnow nPoint[i].Z+1;N(0,0) = (-1) * (R.LL.l1 + R.LL.l9 * R.m_pUnKnownPoint[i].Lx) / LA;N(0,1) = (-1) * (R.LL.l2 + R.LL.l10 * R.m_pUnKnownPoint[i].Lx) / LA;N(0,2) = (-1) * (R.LL.l3 + R.LL.l11 * R.m_pUnKnownPoint[i].Lx) / LA;N(1,0) = (-1) * (R.LL.l5 + R.LL.l9 * R.m_pUnKnownPoint[i].Ly) / LA;N(1,1) = (-1) * (R.LL.l6 + R.LL.l10 * R.m_pUnKnownPoint[i].Ly) / LA;N(1,2) = (-1) * (R.LL.l7 + R.LL.l11 * R.m_pUnKnownPoint[i].Ly) / LA;N(2,0) = (-1) * (R.RL.l1 + R.RL.l9 * R.m_pUnKnownPoint[i].Rx) / RA;N(2,1) = (-1) * (R.RL.l2 + R.RL.l10 * R.m_pUnKnownPoint[i].Rx) / RA;N(2,2) = (-1) * (R.RL.l3 + R.RL.l11 * R.m_pUnKnownPoint[i].Rx) / RA;N(3,0) = (-1) * (R.RL.l5 + R.RL.l9 * R.m_pUnKnownPoint[i].Ry) / RA;N(3,1) = (-1) * (R.RL.l6 + R.RL.l10 * R.m_pUnKnownPoint[i].Ry) / RA;N(3,2) = (-1) * (R.RL.l7 + R.RL.l11 * R.m_pUnKnownPoint[i].Ry) / RA;Q(0,0) = (-1) * (R.LL.l4 + R.m_pUnKnownPoint[i].Lx);Q(1,0) = (-1) * (R.LL.l8 + R.m_pUnKnownPoint[i].Ly);Q(2,0) = (-1) * (R.RL.l4 + R.m_pUnKnownPoint[i].Rx);Q(3,0) = (-1) * (R.RL.l8 + R.m_pUnKnownPoint[i].Ry);}}void qianfangjiaohui::Adjust(DLTCalculation &R){double d1,d2,d3;double m;CMatrix N(4,3);CMatrix Q(4,1);CMatrix Nbb(3,3);CMatrix Nvv(3,1);CMatrix S(3,1);int n=0;FormApproCoor(R);for(int i=0;i<R.m_iUnKnownPointCount;i++){/* do*/{/*FormErrorEquations(R,N,Q);Nbb=(~N)*N;Nvv=(~N)*Q;S=(-1)*(Nbb.Inv())*Nvv;m=S(0,0);d1=S(0,0)-R.m_pUnKnownPoint[i].X;d2=S(1,0)-R.m_pUnKnownPoint[i].Y;d3=S(2,0)-R.m_pUnKnownPoint[i].Z;R.m_pUnKnownPoint[i].X=S(0,0);R.m_pUnKnownPoint[i].Y=S(1,0);R.m_pUnKnownPoint[i].Z=S(2,0);n++;*/}/*while(fabs(d1)>1||fabs(d2)>1||fabs(d3)>1);*/}}实验所需txt 文件粘贴如下:SuYongGang 010*******2015 05 01KnownPointKnownPointCount,10GCP1,1214.0000,1032.0000,1046.5180,1071.6652,9.201742,-9.672384,-2.726064 GCP2,1378.0000,508.0000,1167.8218,541.4734,8.653967,-8.226455,-5.483531 GCP3,605.0000,1527.0000,391.3034,1573.4119,6.175121,-11.003152,0.227490 GCP4,1468.0000,361.0000,1262.5994,388.2626,9.004163,-7.857839,-6.448011 GCP5,940.0000,1264.0000,719.0428,1310.4186,7.206690,-9.863228,-1.122442 GCP6,1204.0000,563.0000,990.1780,606.6536,7.986264,-8.928340,-5.054990 GCP7,554.0000,1158.0000,348.4338,1217.2070,5.888988,-11.267342,-1.584110 GCP8,1972.0000,1455.0000,1781.7030,1481.7072,10.951923,-5.749235,-0.276650 GCP9,1013.0000,739.0000,797.4695,790.9252,7.321597,-9.658292,-3.954598 GCP10,2814.0000,1057.0000,2745.6122,1035.4548,14.760180,-1.714839,-2.804178 END KnownPointUnknownPointUnknownPointCount,10ID,Lx,Ly,Lz,Rx,Ry,Rz1,1411.0000,319.0000,1209.0579,350.27772,1495.0000,297.0000,1296.0357,322.26193,1348.0000,475.0000,1140.2866,510.61094,2500.0000,717.0000,2380.9077,688.05625,342.0000,442.0000,165.1718,540.67196,2217.0000,954.0000,2059.9866,951.8440 7,1356.0000,578.0000,1147.8519,612.7434 8,1398.0000,574.0000,1190.8740,606.4662 9,1234.0000,1032.0000,1066.8420,1070.8535 10,1481.0000,577.0000, 1276.1857,604.2876 END UnknownPoint。

相关主题