空间后方交会前方交会 MFC实现 CSU 摄影测量学
空间后方交会前方交会 MFC 实现 CSU 摄影测量学
- 空间后方交会前方交会 MFC 实现 CSU 摄影测量学
- 摄影测量学基础
- 一、 实验目的
- 二、实验内容与要求
- 三、设计与实现:
- 3.1设计思路
- 3.1.1 基本框架:
- 3.1.2 成员关系:
- 3.2 界面设计及属性:
- 3.3 主要代码:
- 3.3.1 文件:Matrix.h
- 3.3.2文件:Math.cpp
- 3.3.3文件:Support.h
- 3.3.3文件:Support.cpp
- 3.3.5文件:RS_110_Z_SpaceIntersectionDlg.cpp (仅摘取部分)
- 3.4运行结果
- 3.5 设计技巧
- 代码虽多不要贪杯~
空间后方交会前方交会 MFC 实现 CSU 摄影测量学
摄影测量学基础
(工具:VS2010)
一、 实验目的
• 通过对数字影像空间后交前交的程序设计实验,要求我们进一步理解和掌握影像外方位元素的有关理论、原理和方法。掌握VC++.net中创建类
• 利用计算机程序设计语言编写摄影测量空间交会软件进行快速确定影像的外方位元素及其精度,然后通过求得的外方位元素求解未知点的地面摄影测量坐标,达到通过摄影测量量测地面地理数据的目的。
二、实验内容与要求
要求:用C、VB或者Matlab编写空间后方交会一前方交会计算机程序。
➢提交实验报告:程序框图,程序源代码、计算结果及体会。
➢计算结果:地面点坐标、外方位元素及精度。
实验数据:
三、设计与实现:
3.1设计思路
3.1.1 基本框架:
3.1.2 成员关系:
3.2 界面设计及属性:
3.3 主要代码:
3.3.1 文件:Matrix.h
/***************************************************************************
* 文件名:<Matrix.h> *
* *
* 描述:矩阵类 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月19日 引用 *** *
* *
* 外部过程: *
* *
/**************************************************************************/#pragma once
class CMatrix
{public:CMatrix(int row=3,int col=3);// copy constructorCMatrix (const CMatrix& m);~CMatrix(void);
private:double **dMatData;//保存矩阵元素数据的二维数组int iRow;//矩阵的行int iCol;//矩阵的列public:int Row() const {return iRow;}//返回行int Col() const {return iCol;}//返回列void SetSize (int row, int col);//调整数组的大小,原有数据不变(未测试)double& operator () (int row, int col);//获取矩阵元素double operator () (int row, int col) const;//重载获取矩阵元素函数,只有const对象能访问CMatrix& operator = (const CMatrix& m) ;//注意:友元函数并不是类自己的成员函数friend CMatrix operator + (const CMatrix& m1,const CMatrix& m2);friend CMatrix operator - (const CMatrix& m1,const CMatrix& m2);friend CMatrix operator * (const CMatrix& m1,const CMatrix& m2);friend CMatrix operator * (const double& num, const CMatrix& m1);friend CMatrix operator * (const CMatrix& m1,const double& num);friend CMatrix operator ~ (const CMatrix& m);//矩阵转置CMatrix Inv();//矩阵求逆void Unit();//生成单位矩阵
};
3.3.2文件:Math.cpp
#include "StdAfx.h"
#include "Matrix.h"
#include "math.h"CMatrix::CMatrix(int row,int col)
{iRow=row;iCol=col;dMatData = new double*[row];for (int i=0; i < row; i++){dMatData[i]= new double[col];for(int j=0;j<col;j++){dMatData[i][j]=0;}}
}// copy constructor,
//拷贝构造函数的作用:
//(1)以类对象作为函数参数传值调用时;
//(2)函数返回值为类对象;
//(3)用一个已定义的对象去初始化一个新对象时;CMatrix::CMatrix (const CMatrix& m)
{iRow=m.Row();iCol=m.Col();dMatData = new double*[iRow];for (int i=0; i < iRow; i++){dMatData[i]= new double[iCol];// for(int j=0;j<iCol;j++){memcpy(dMatData[i],m.dMatData[i],sizeof(double)*iCol);}}}CMatrix::~CMatrix(void)
{for (int i=0; i < iRow; i++){delete[] dMatData[i];}delete[] dMatData;
}//返回数组元素(引用返回)
double& CMatrix::operator () (int row, int col)
{if (row >= iRow || col >= iCol){throw( "CMatrix::operator(): Index out of range!");}return dMatData[row][col];
}返回数组元素(重载)
double CMatrix::operator () (int row, int col) const
{if (row >= iRow || col >= iCol){throw( "CMatrix::operator(): Index out of range!");}return dMatData[row][col];
}//重载预算符+
CMatrix operator + (const CMatrix& m1,const CMatrix& m2)
{if((m1.Col()!=m2.Col()) ||(m1.Row()!=m2.Row()) ){throw( "CMatrix::operator+: The two matrix have different size!");}CMatrix matTmp(m1.Row(),m1.Col());for(int i=0;i<m1.Row();i++){for(int j=0;j<m1.Col();j++){matTmp(i,j)=m1(i,j)+m2(i,j); }}return matTmp;
}//重载赋值运算符=,当左右两边矩阵的大小不相等时,
//以右边的大小为基准,调整左边矩阵的大小CMatrix &CMatrix::operator = (const CMatrix& m)
{//revised in 2011-4-1, by Daiwujiao// if(iRow!=m.Row()||iCol!=m.Col())//{// throw( "CMatrix::operator=: The two matrix have different size!");//}if(iRow!=m.Row()||iCol!=m.Col()){SetSize(m.Row(),m.Col());}for (int i=0; i < iRow; i++){for(int j=0;j<iCol;j++){dMatData[i][j]=m(i,j);}}return *this;
}//调整矩阵大小,原有值不变
void CMatrix::SetSize (int row, int col)
{if (row == iRow && col == iCol){return;}double **rsData = new double*[row];for (int i=0; i < row; i++){rsData[i]= new double[col];for(int j=0;j<col;j++){rsData[i][j]=0;}}int minRow=(iRow>row)?row:iRow;int minCol= (iCol>col)?col:iCol;int colSize = minCol * sizeof(double);for (int i=0; i < minRow; i++){memcpy( rsData[i], dMatData[i], colSize);}for (int i=0; i < minRow; i++){delete[] dMatData[i];}delete[] dMatData;dMatData=rsData;iRow=row;iCol=col;return;
}
//重载预算符-
CMatrix operator - (const CMatrix& m1,const CMatrix& m2)
{if((m1.Col()!=m2.Col()) ||(m1.Row()!=m2.Row()) ){throw( "CMatrix::operator-: The two matrix have different size!");}CMatrix matTmp(m1.Row(),m1.Col());for(int i=0;i<m1.Row();i++){for(int j=0;j<m1.Col();j++){matTmp(i,j)=m1(i,j)-m2(i,j); }}return matTmp;
}//重载预算符*,两个矩阵相乘,m1的列要等于m2的行
CMatrix operator * (const CMatrix& m1,const CMatrix& m2)
{if((m1.Col()!=m2.Row())){throw( "CMatrix::operator*: The col of matrix m1 doesn't equ to row of m2 !");}CMatrix matTmp(m1.Row(),m2.Col());for(int i=0;i<m1.Row();i++){for(int j=0;j<m2.Col();j++){for(int k=0;k<m2.Row();k++){matTmp(i,j)+=m1(i,k)*m2(k,j); }}}return matTmp;
}//重载预算符*,矩阵右乘一个数
CMatrix operator * (const CMatrix& m1,const double& num)
{CMatrix matTmp(m1.Row(),m1.Col());for(int i=0;i<m1.Row();i++){for(int j=0;j<m1.Col();j++){matTmp(i,j)=m1(i,j)*num; }}return matTmp;
}//重载预算符*,矩阵左乘一个数
CMatrix operator * (const double& num, const CMatrix& m1)
{CMatrix matTmp(m1.Row(),m1.Col());for(int i=0;i<m1.Row();i++){for(int j=0;j<m1.Col();j++){matTmp(i,j)=m1(i,j)*num; }}return matTmp;
}//矩阵转置
CMatrix operator ~ (const CMatrix& m)
{CMatrix matTmp(m.Col(),m.Row());for (int i=0; i < m.Row(); i++)for (int j=0; j < m.Col(); j++){matTmp(j,i) = m(i,j);}return matTmp;
}//矩阵求逆
//采用选全主元法
CMatrix CMatrix::Inv()
{if (iRow!=iCol){throw("待求逆的矩阵行列不相等!");}int i, j, k, vv;CMatrix InvMat(iRow,iRow);//复制矩阵InvMat=*this;int* MainRow=new int[iRow];int* MainCol=new int[iRow];//用于记录主元素的行和列double dMainCell;//主元元素的值double dTemp;//临时变量for(k = 0;k<iRow;k++){dMainCell = 0;//选全主元for( i = k;i<iRow ;i++){for( j = k;j<iRow;j++){dTemp = fabs(InvMat(i, j));if(dTemp > dMainCell){dMainCell = dTemp;MainRow[k] = i;MainCol[k] = j;}}}if( fabs(dMainCell) < 0.0000000000001)//矩阵秩亏,不能求逆{throw("矩阵秩亏");}if(MainRow[k] != k)//交换行{for( j = 0 ;j<iRow;j++){vv = MainRow[k];dTemp = InvMat(k, j);InvMat(k, j) = InvMat(vv, j);InvMat(vv, j) = dTemp;}}if(MainCol[k] != k)//交换列{for(i = 0;i<iRow;i++){vv = MainCol[k];dTemp = InvMat(i, k);InvMat(i, k) = InvMat(i, vv);InvMat(i, vv) = dTemp;}}InvMat(k, k) = 1.0 / InvMat(k, k);//计算乘数for( j = 0;j< iRow;j++) //计算主行{if(j != k){InvMat(k, j) = InvMat(k, j) * InvMat(k, k);}}for(i = 0;i<iRow;i++)//消元{if( i !=k){for(j = 0;j<iRow;j++){if(j != k){InvMat(i, j) -= InvMat(i, k) * InvMat(k, j);}}}}for( i = 0;i< iRow;i++ )//计算主列{if( i != k){InvMat(i, k) = -InvMat(i, k) * InvMat(k, k);}}}for( k = iRow - 1;k>=0;k--){if(MainCol[k] != k)// 交换行{for( j = 0;j<iRow;j++){vv = MainCol[k];dTemp = InvMat(k, j);InvMat(k, j) = InvMat(vv, j);InvMat(vv, j) = dTemp;}}if(MainRow[k] != k)//交换列{for( i = 0;i<iRow;i++){vv = MainRow[k];dTemp = InvMat(i, k);InvMat(i, k) = InvMat(i, vv);InvMat(i, vv) = dTemp;}}}delete[] MainRow;delete[] MainCol;return InvMat;
}
//单位化矩阵
void CMatrix::Unit()
{for(int i=0;i<iRow;i++){for(int j=0;j<iCol;j++){dMatData[i][j]=(i==j)?1:0;}}
}
3.3.3文件:Support.h
/***************************************************************************
* 文件名:<Support.h> *
* *
* 描述:封装所有函数的类、调用矩阵CMatrix类 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月19日 创建 *** *
* *
* 外部过程: *
* *
/**************************************************************************/#pragma once
#include"Matrix.h"class CSupport
{double dLx;double dLy;double dRx;double dRy;double X;double Y;double Z;
public:int SplitStringArray(CString str, char split, CStringArray& aStr);double length(double x1,double y1,double x2,double y2);CSupport(void);~CSupport(void);void R1(CMatrix &R,CMatrix X );void read(CString &strExample,CSupport *GCP);int SpaceBack(CSupport *GCP,int xx,int yy,CMatrix &Left,bool _L,double &Left_a0,CMatrix &LeftPhotoes_Pre);void SpaceFront(CMatrix &Left,CMatrix &Right,CMatrix &B,CMatrix &R_Left,CMatrix &R_Right,CSupport *GCP);void out(double Left_a0,double Right_a0,CMatrix LeftPhotoes,CMatrix LeftPhotoes_Pre,CMatrix RightPhotoes,CMatrix RightPhotoes_Pre,CSupport *GCP ,CString &strResult,int t1,int t2);void main(CString &strExample,CString &strResult);
};
3.3.3文件:Support.cpp
#include "StdAfx.h"
#include "math.h"
#include "Matrix.h"
#include "Support.h"/***************************************************************************
* 名字:double CSupport::SplitStringArray(CString str, char split, CStringArray& aStr) *
* *
* 描述:字符串分割函数 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年3月20日 引用 *** *
* 参数: 1.CString str *
* 2.char split *
* 3.CStringArray& aStr *
* 返回值:int类型数据 返回n *
* *
* 注: *
/**************************************************************************/
int CSupport::SplitStringArray(CString str, char split, CStringArray& aStr)
{int startIdx = 0;int idx = str.Find(split, startIdx);aStr.RemoveAll();//先清空while (-1 != idx){CString sTmp = str.Mid(startIdx, idx - startIdx);aStr.Add(sTmp);startIdx = idx + 1;idx = str.Find(split, startIdx);}CString sTmp = str.Right(str.GetLength() - startIdx);if (! sTmp.IsEmpty())aStr.Add(sTmp);return aStr.GetSize();
}
/***************************************************************************
* 名字:double length(double x1,double y1,double x2,double y2) *
* *
* 描述:由(x1,y1)和(x2,y2)计算两点之间距离 长度 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年3月20日 创建该函数 *** *
* 参数: 1.double x1 *
* 2.double y1 *
* 3.double x2 *
* 4.double y2 *
* 返回值:double类型数据 返回距离 *
* *
* 注: *
/**************************************************************************/
double CSupport::length(double x1,double y1,double x2,double y2)
{double tmp=((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));return sqrt(tmp);
}/***************************************************************************
* 名字:void CSupport::read(CString &strExample,CSupport *GCP) *
* *
* 描述:读取数据,将数据存至GCP开辟的动态数组中 *
* 调用函数SplitStringArray() *
* 历史:**日期** **理由** **签名** *
* 2019年4月20日 创建该函数 *** *
* 参数: 1.CString &strExample *
* 2.CSupport *GCP *
* 返回值:无 *
* *
* 注: *
/**************************************************************************/
void CSupport::read(CString &strExample,CSupport *GCP)
{//将dx dy dzint iLine;CStringArray aStrLine;iLine=SplitStringArray(strExample,13,aStrLine);if(iLine==0){AfxMessageBox(_T("请输入数据!"));}CStringArray aStrTmp;int n;n=SplitStringArray(aStrLine[0],',',aStrTmp);int temp1=_tstof(aStrTmp[0]);int temp2=_tstof(aStrTmp[1]);for(int i=0;i<temp1;i++){n=SplitStringArray(aStrLine[i+1],',',aStrTmp);GCP[i].dLx=_tstof(aStrTmp[0])/1000;GCP[i].dLy=_tstof(aStrTmp[1])/1000;GCP[i].dRx=_tstof(aStrTmp[2])/1000;GCP[i].dRy=_tstof(aStrTmp[3])/1000;GCP[i].X=_tstof(aStrTmp[4]);GCP[i].Y=_tstof(aStrTmp[5]);GCP[i].Z=_tstof(aStrTmp[6]);}for(int i=temp1;i<temp2+temp1;i++){n=SplitStringArray(aStrLine[i+1],',',aStrTmp);GCP[i].dLx=_tstof(aStrTmp[0])/1000;GCP[i].dLy=_tstof(aStrTmp[1])/1000;GCP[i].dRx=_tstof(aStrTmp[2])/1000;GCP[i].dRy=_tstof(aStrTmp[3])/1000;}
}/***************************************************************************
* 名字:int CSupport::SpaceBack() *
* *
* 描述:后方交会函数,调用函数length()、R1()两个函数 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月20日 创建该函数 *** *
* 参数: 1.CSupport *GCP //主要元素在这里 *
* 2.int xx *
* 3.int yy *
* 4.CMatrix &Left //外方位6个元素 *
* 5.bool _L //用来标识 *
* 6.double &Left_a0 //中误差 *
* 7.CMatrix &LeftPhotoes_Pre //精度 *
* 返回值:int t //返回迭代次数 *
* *
* 注: *
/**************************************************************************/
int CSupport::SpaceBack(CSupport *GCP,int xx,int yy,CMatrix &Left,bool _L,double &Left_a0,CMatrix &LeftPhotoes_Pre)
{int temp=1;int t=0;int n=4;//定义n个已知点double f=0.15;//需修改double m;if(_L){m=(length(GCP[xx].X,GCP[xx].Y,GCP[yy].X,GCP[yy].Y)/length(GCP[xx].dLx,GCP[xx].dLy,GCP[yy].dLx,GCP[yy].dLy));}else {m=(length(GCP[xx].X,GCP[xx].Y,GCP[yy].X,GCP[yy].Y)/length(GCP[xx].dRx,GCP[xx].dRy,GCP[yy].dRx,GCP[yy].dRy));}//m=10000;//m赋值double H=m*f;CMatrix A;A.SetSize(2*n,6);CMatrix X;X.SetSize(6,1);CMatrix L;L.SetSize(2*n,1);CMatrix _x;_x.SetSize(6,1);//矩阵X的值初始化X(0,0)=(GCP[xx].X+GCP[yy].X)/2;//XSX(1,0)=(GCP[xx].Y+GCP[yy].Y)/2;//YSX(2,0)=((GCP[xx].Z+GCP[yy].Z)/2+m*f);//ZS/*X(0,0)=(GCP[1].X+GCP[2].X+GCP[3].X+GCP[4].X)/4;//XSX(1,0)=(GCP[1].Y+GCP[2].Y+GCP[3].Y+GCP[4].Y)/4;;//YSX(2,0)=((GCP[1].Z+GCP[2].Z+GCP[3].Z+GCP[4].Z)/4+m*f);//ZS*/for (int i=3;i<6;i++){X(i,0)=0;}CMatrix R;R.SetSize(3,3);CMatrix Lz;Lz.SetSize(4,1);do{R1(R,X);for(int k=0;k<n;k++){ Lz(k,0)=R(0,2)*(GCP[k].X-X(0,0))+R(1,2)*(GCP[k].Y-X(1,0))+R(2,2)*(GCP[k].Z-X(2,0));if(_L==1){A(2*k,0)=(R(0,0)*f+R(0,2)*GCP[k].dLx)/Lz(k,0);A(2*k,1)=(R(1,0)*f+R(1,2)*GCP[k].dLx)/Lz(k,0);A(2*k,2)=(R(2,0)*f+R(2,2)*GCP[k].dLx)/Lz(k,0);A(2*k,3)=GCP[k].dLy*sin(X(4,0))-(GCP[k].dLx*(GCP[k].dLx*cos(X(5,0))/f-GCP[k].dLy*sin(X(5,0)))+f*cos(X(5,0)))*cos(X(4,0));A(2*k,4)=-f*sin(X(5,0))-GCP[k].dLx*(GCP[k].dLx*sin(X(5,0))+GCP[k].dLy*cos(X(5,0)))/f;A(2*k,5)=GCP[k].dLy;A(2*k+1,0)=(R(0,1)*f+R(0,2)*GCP[k].dLy)/Lz(k,0);A(2*k+1,1)=(R(1,1)*f+R(1,2)*GCP[k].dLy)/Lz(k,0);A(2*k+1,2)=(R(2,1)*f+R(2,2)*GCP[k].dLy)/Lz(k,0);A(2*k+1,3)=-GCP[k].dLx*sin(X(4,0))-(GCP[k].dLy*(GCP[k].dLx*cos(X(5,0))/f+GCP[k].dLy*sin(X(5,0)))-f*sin(X(5,0)))*cos(X(4,0));A(2*k+1,4)=-f*cos(X(5,0))-GCP[k].dLy*(GCP[k].dLx*sin(X(5,0))+GCP[k].dLy*cos(X(5,0)))/f;A(2*k+1,5)=-GCP[k].dLx; double _1=R(0,0)*(GCP[k].X-X(0,0))+R(1,0)*(GCP[k].Y-X(1,0))+R(2,0)*(GCP[k].Z-X(2,0));double _2=R(0,1)*(GCP[k].X-X(0,0))+R(1,1)*(GCP[k].Y-X(1,0))+R(2,1)*(GCP[k].Z-X(2,0));double _3=R(0,2)*(GCP[k].X-X(0,0))+R(1,2)*(GCP[k].Y-X(1,0))+R(2,2)*(GCP[k].Z-X(2,0));L(2*k,0)=GCP[k].dLx+(f*_1)/_3;L(2*k+1,0)=GCP[k].dLy+(f*_2)/_3;}else{A(2*k,0)=(R(0,0)*f+R(0,2)*GCP[k].dRx)/Lz(k,0);A(2*k,1)=(R(1,0)*f+R(1,2)*GCP[k].dRx)/Lz(k,0);A(2*k,2)=(R(2,0)*f+R(2,2)*GCP[k].dRx)/Lz(k,0);A(2*k,3)=GCP[k].dRy*sin(X(4,0))-(GCP[k].dRx*(GCP[k].dRx*cos(X(5,0))/f-GCP[k].dRy*sin(X(5,0)))+f*cos(X(5,0)))*cos(X(4,0));A(2*k,4)=-f*sin(X(5,0))-GCP[k].dRx*(GCP[k].dRx*sin(X(5,0))+GCP[k].dRy*cos(X(5,0)))/f;A(2*k,5)=GCP[k].dRy;A(2*k+1,0)=(R(0,1)*f+R(0,2)*GCP[k].dRy)/Lz(k,0);A(2*k+1,1)=(R(1,1)*f+R(1,2)*GCP[k].dRy)/Lz(k,0);A(2*k+1,2)=(R(2,1)*f+R(2,2)*GCP[k].dRy)/Lz(k,0);A(2*k+1,3)=-GCP[k].dRx*sin(X(4,0))-(GCP[k].dRy*(GCP[k].dRx*cos(X(5,0))/f+GCP[k].dRy*sin(X(5,0)))-f*sin(X(5,0)))*cos(X(4,0));A(2*k+1,4)=-f*cos(X(5,0))-GCP[k].dRy*(GCP[k].dRx*sin(X(5,0))+GCP[k].dRy*cos(X(5,0)))/f;A(2*k+1,5)=-GCP[k].dRx; double _1=R(0,0)*(GCP[k].X-X(0,0))+R(1,0)*(GCP[k].Y-X(1,0))+R(2,0)*(GCP[k].Z-X(2,0));double _2=R(0,1)*(GCP[k].X-X(0,0))+R(1,1)*(GCP[k].Y-X(1,0))+R(2,1)*(GCP[k].Z-X(2,0));double _3=R(0,2)*(GCP[k].X-X(0,0))+R(1,2)*(GCP[k].Y-X(1,0))+R(2,2)*(GCP[k].Z-X(2,0));L(2*k,0)=GCP[k].dRx+(f*_1)/_3;L(2*k+1,0)=GCP[k].dRy+(f*_2)/_3;}}_x=(~A*A).Inv()*~A*L;X=X+_x;++t;}while(fabs(_x(0,0))>1e-4||fabs(_x(1,0))>1e-4||fabs(-_x(2,0))>1e-4||fabs(_x(3,0))>4.481e-6||fabs(_x(4,0))>4.481e-6||fabs(_x(5,0))>4.481e-6);//平定精度CMatrix Temp;Temp=~(_x)*(_x);double temp1;temp1=Temp(0,0);Left_a0=temp1/(2*n-6);Left_a0=sqrt(Left_a0);CMatrix Qxx;Qxx.SetSize(6,6);Qxx=(~A*A).Inv();for(int i=0;i<6;i++){LeftPhotoes_Pre(i,0)=Left_a0*sqrt(Qxx(i,i));}Left=X;return t;
}/***************************************************************************
* 名字:void CSupport::R1(CMatrix &R,CMatrix X ) *
* *
* 描述:R矩阵赋值 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月20日 创建该函数 *** *
* 参数: 1.CMatrix &R //R矩阵 (3,3) *
* 2.CMatrix X // X矩阵(6,1) *
* 返回值:无 *
* *
* 注: *
/**************************************************************************/
void CSupport::R1(CMatrix &R,CMatrix X )
{R(0,0)=cos(X(3,0))*cos(X(5,0))-sin(X(3,0))*sin(X(4,0))*sin(X(5,0));R(0,1)=-cos(X(3,0))*sin(X(5,0))-sin(X(3,0))*sin(X(4,0))*cos(X(5,0));R(0,2)=-sin(X(3,0))*cos(X(4,0));R(1,0)=cos(X(4,0))*sin(X(5,0));R(1,1)=cos(X(4,0))*cos(X(5,0));R(1,2)=-sin(X(4,0));R(2,0)=sin(X(3,0))*cos(X(5,0))+cos(X(3,0))*sin(X(4,0))*sin(X(5,0));R(2,1)=-sin(X(3,0))*sin(X(5,0))+cos(X(3,0))*sin(X(4,0))*cos(X(5,0));R(2,2)=cos(X(3,0))*cos(X(4,0));
}/***************************************************************************
* 名字:void CSupport::SpaceFront() *
* *
* 描述:前方交会函数 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月20日 创建该函数 *** *
* 参数: 1.CMatrix &Left //左片6个外方位元素 *
* 2.CMatrix &Right //右片6个外方位元素 *
* 3.CMatrix &B //摄影基线3个元素 *
* 4.CMatrix &R_Left //左片旋转矩阵(3,3) *
* 5.CMatrix &R_Right //右片旋转矩阵(3,3) *
* 6.CSupport *GCP //主要元素 *
* 返回值:无 *
* *
* 注: *
/**************************************************************************/
void CSupport::SpaceFront(CMatrix &Left,CMatrix &Right,CMatrix &B,CMatrix &R_Left,CMatrix &R_Right,CSupport *GCP)
{double f=0.15;//需修改int n=4;//从第五行起开始为计算值int m=9;//5--9行为数据B(0,0)=Right(0,0)-Left(0,0);B(1,0)=Right(1,0)-Left(1,0);B(2,0)=Right(2,0)-Left(2,0);R1(R_Left,Left);R1(R_Right,Right);//开辟一个数组for(int i=n;i<m;i++){CMatrix L_xyf;L_xyf.SetSize(3,1);L_xyf(0,0)=GCP[i].dLx;L_xyf(1,0)=GCP[i].dLy;L_xyf(2,0)=-f;CMatrix R_xyf;R_xyf.SetSize(3,1);R_xyf(0,0)=GCP[i].dRx;R_xyf(1,0)=GCP[i].dRy;R_xyf(2,0)=-f;CMatrix L;L.SetSize(3,1);CMatrix R;R.SetSize(3,1);L=R_Left*L_xyf;R=R_Right*R_xyf;double N1,N2;N1=((B(0,0)*R(2,0)-B(2,0)*R(0,0))/(L(0,0)*R(2,0)-R(0,0)*L(2,0)));N2=((B(0,0)*L(2,0)-B(2,0)*L(0,0))/(L(0,0)*R(2,0)-R(0,0)*L(2,0)));GCP[i].X=Right(0,0)+N2*R(0,0);GCP[i].Y=(Left(1,0)+Right(1,0)+N1*L(1,0)+N2*R(1,0))/2;GCP[i].Z=Right(2,0)+N2*R(2,0);}
}
/***************************************************************************
* 名字:void CSupport::out() *
* *
* 描述:输出函数 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月20日 创建该函数 *** *
* 参数: 1.double Left_a0 //左片单位权中误差 *
* 2.double Right_a0 //左片单位权中误差 *
* 3.CMatrix LeftPhotoes //左片外方位元素 *
* 4.CMatrix LeftPhotoes_Pre //左片外方位元素精度 *
* 5.CMatrix RightPhotoes //右片外方位元素 *
* 6.CMatrix RightPhotoes_Pre //右片外方位元素精度 *
* 7.CSupport *GCP //主要元素 *
* 8.CString &strResult //输出结果CString *
* 9.int t1 //左片迭代次数 *
* 10.int t2 //右片迭代次数 *
* 返回值:无 *
* *
* 注: *
/**************************************************************************/
void CSupport::out(double Left_a0,double Right_a0,CMatrix LeftPhotoes,CMatrix LeftPhotoes_Pre,CMatrix RightPhotoes,CMatrix RightPhotoes_Pre,CSupport *GCP ,CString &strResult,int t1,int t2)
{strResult.Format(_T("%s\t%s\t%s\t\r\n"),_T("-------------------------------------------------------- 摄影外方位元素 -------------------------------------------------------- "),_T(""),_T(""));CString strOutput;strResult=strResult+strOutput;strOutput.Format(_T("%s%f%s%d\r\n%s\r\n"),_T("左片单位权中误差:"),Left_a0,_T(" 迭代次数:"),t1,_T("左片元素:依次是 Xs Ys Zs Alfa w k: 精度:"));strResult=strResult+strOutput;for(int z=0;z<6;z++){if(z<3){strOutput.Format(_T("%f\t\t\t\t\t\t%f\r\n"),LeftPhotoes(z,0),LeftPhotoes_Pre(z,0));}else{strOutput.Format(_T("%f\t\t\t\t\t\t\t%f\r\n"),LeftPhotoes(z,0),LeftPhotoes_Pre(z,0));}strResult=strResult+strOutput;}strOutput.Format(_T("%s%f%s%d\r\n%s\r\n"),_T("右片单位权中误差:"),Right_a0,_T(" 迭代次数:"),t2,_T("右片元素:依次是 Xs Ys Zs Alfa w k: 精度:"));strResult=strResult+strOutput;for(int z=0;z<6;z++){if(z<3){strOutput.Format(_T("%f\t\t\t\t\t\t%f\r\n"),RightPhotoes(z,0),RightPhotoes_Pre(z,0));}else{strOutput.Format(_T("%f\t\t\t\t\t\t\t%f\r\n"),RightPhotoes(z,0),RightPhotoes_Pre(z,0));}strResult=strResult+strOutput;}strOutput.Format(_T("%s\r\n%s\r\n"),_T("全部元素:"),_T("左片x 左片y 右片x 右片y X Y Z "));strResult=strResult+strOutput; for(int i=0;i<9;i++){strOutput.Format(_T("%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t\r\n"),GCP[i].dLx*1000,GCP[i].dLy*1000,GCP[i].dRx*1000,GCP[i].dRy*1000,GCP[i].X,GCP[i].Y,GCP[i].Z);strResult=strResult+strOutput;}}/***************************************************************************
* 名字:void CSupport::main(CString &strExample,CString &strResult) *
* *
* 描述:主要函数 ,调用函数read()、SpqceBack()、SpaceFront()、out()等函数 *
* 等4个函数 *
* 历史:**日期** **理由** **签名** *
* 2019年4月20日 创建该函数 *** *
* 参数: 1.CString &strExample //读入数据 *
* 2.CString &strResult //输出数据 *
* 返回值:无 *
* *
* 注: *
/**************************************************************************/
void CSupport::main(CString &strExample,CString &strResult)
{CSupport GCP[9];//每一行数据各个元素提取read(strExample,GCP);//读取函数CMatrix LeftPhotoes;//左片外方位元素LeftPhotoes.SetSize(6,1);double Left_a0;//中误差CMatrix LeftPhotoes_Pre;//左片外方位元素LeftPhotoes_Pre.SetSize(6,1);CMatrix RightPhotoes;//右片外方位元素RightPhotoes.SetSize(6,1);double Right_a0;//中误差CMatrix RightPhotoes_Pre;//左片外方位元素RightPhotoes_Pre.SetSize(6,1);double LeftPhotoes_t1=SpaceBack(GCP,0,2,LeftPhotoes,1,Left_a0,LeftPhotoes_Pre);//左片后方交会double RightPhotoes_t2=SpaceBack(GCP,1,3,RightPhotoes,0,Right_a0,RightPhotoes_Pre);//右片后方交会CMatrix B;B.SetSize(3,1);//Bx By BzCMatrix R_Left;R_Left.SetSize(3,3);//左片旋转矩阵RCMatrix R_Right; R_Right.SetSize(3,3);//右片旋转矩阵RSpaceFront(LeftPhotoes,RightPhotoes,B,R_Left,R_Right,GCP);out(Left_a0,Right_a0,LeftPhotoes,LeftPhotoes_Pre,RightPhotoes,RightPhotoes_Pre,GCP,strResult,LeftPhotoes_t1,RightPhotoes_t2);
}CSupport::CSupport(void)
{}CSupport::~CSupport(void)
{}
3.3.5文件:RS_110_Z_SpaceIntersectionDlg.cpp (仅摘取部分)
/***************************************************************************
* 文件名:<RS_110_Z_SpaceIntersectionDlg.cpp> *
* *
* 描述: Dialog对话框使用 *
* *
* 历史:**日期** **理由** **签名** *
* 2019年4月19日 创建 *** *
* *
* 外部过程: *
* *
/**************************************************************************/
//计算按钮
void CRS_110_Z_SpaceIntersectionDlg::OnBnClickedOk()
{// TODO: 在此添加控件通知处理程序代码//CDialogEx::OnOK();UpdateData(true);CSupport k;k.main(strExample,strResult);UpdateData(false);
}//取消按钮
void CRS_110_Z_SpaceIntersectionDlg::OnBnClickedCancel()
{// TODO: 在此添加控件通知处理程序代码CDialogEx::OnCancel();
}
3.4运行结果
3.5 设计技巧
创建多个类,层次分明。调用了Cmatrix矩阵类,省了好多力气。
使用指针动态开辟数组,较为方便。
提前做好函数模块,结构化,有助于专注于编程。
代码虽多不要贪杯~
空间后方交会前方交会 MFC实现 CSU 摄影测量学相关推荐
- 空间后方交会c++程序和matlab(可直接运行)
本文不详细说明空间后方交会的原理,只着重说明空间后方交会的程序,并附带一个样例. 样例来源:<摄影测量学>(第二版)武汉大学出版社,张剑清,潘励,王树根. 空间后方交会的误差方程式: 可以 ...
- 单向空间后方交会C++代码实现
摄影测量作业 空间后方交会的代码 各位小伙伴要用的话 只需修改main函数里边的像点地面点坐标,摄影比例尺分母,焦距等这些已知元素就行. #include<iostream> #inclu ...
- 单片空间后方交会程序设计(代码共享)
单片空间后方交会程序设计 1 目的 用程序设计语言(VC或者VB)编写一个完整的单片空间后方交会程序,通过对提供的试验数据进行计算,输出像片的外方位元素并评定精度.本实验的目的在于让学生深入理解单片空 ...
- 摄影测量学空间后方交会
本书是根据武汉大学出版社出版的第三版<摄影测量学>进行编写的单像空间后方交会程序 from numpy import * data_list=[[1,-86.15,-68.99,36589 ...
- Matlab解算空间后方交会外方位元素
目录 1 问题描述 2 实现部分 参考文献 本问题为武汉大学摄影测量学教材课后习题,现在用MATLAB实现,供大家学习参考. 1 问题描述 已知摄像机主距f=153.24mm,四对点的像点坐标 ...
- 摄影测量后方交会-前方交会(C#)
双像解析摄影测量中的后交-前交解法,常用于已知像片的外方位元素.需确定少量待定点坐标的情况.解算过程分为两个阶段:后方交会.前方交会. 思路为利用后方交会计算外方位元素,利用前方交会解算待定地面点坐标 ...
- 摄影测量学-学习笔记整理
第一章 绪论 1.摄影测量学的定义(P1) 传统的摄影测量学是利用光学摄影机摄取像片,通过像片来研究和确定被摄物体的形状,大小,位置和相互关系的一门科学技术,通俗的讲,摄影测量学是信息的获取及对信息加 ...
- c语言摄影测量共线方程,摄影测量中的共线条件方程
<摄影测量中的共线条件方程>由会员分享,可在线阅读,更多相关<摄影测量中的共线条件方程(42页珍藏版)>请在人人文库网上搜索. 1.2-5 共线条件方程,共线条件方程,已知不同 ...
- 双象空间前方交会代码_单像空间后方交会和双像解析空间后方-前方交会的算法程序实现...
单像空间后方交会和双像解析空间后方 - 前 方交会的算法程序实现 遥感科学与技术 摘要:如果已知每张像片的 6 个外方位元素,就能确定被摄物体与航摄像片的关系.因此, 利用单像空间后方交会的方法,可以 ...
最新文章
- 放张载玻片就能放大一万倍,普通光学显微镜都馋哭了 | Nature子刊
- 悲观锁和乐观锁_乐观锁和悲观锁 以及 乐观锁的一种实现方式-CAS
- Android中获取WebView加载的html中console.log输出的内容
- 王陆C语言,王陆和王舞的关系
- C++使用二个栈实现queue(附完整源码)
- ACM学习历程—51NOD 1685 第K大区间2(二分 树状数组 中位数)
- 低代码/无代码,在国内还有多长的路要走?
- Kotlin中正则表达式分析
- 为什么说c语言是关键字,为什么说C语言既有高级语言又有低级语言的特点
- 华为服务器批量系统软件,华为云ECS批量管理工具
- java 对象查找_Java如何从数组中查找对象元素?
- 项目风险管理十大黄金法则!高质量项目管理必杀技!
- java 前端模板_前端模板引擎入门
- 实验研究脂质体表面修饰多肽、氨基酸和蛋白
- 体检报告分析与饮食起居注意事项
- 【已开源】Qt 艾宾浩斯(Ebbinghaus)记忆 软件
- ORACLE匹配手机号,Oracle正则表达式语法介绍及实现手机号码匹配方法
- Django 权限Permissions python
- Spring Cloud Gateway网关实战
- JBOSS整套开发组件整合和配置方法
热门文章
- Notify与notifyall的区别
- node 无法将“node”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正 确,然后再试一次 的解决方案
- 什么是标准作业及ECRS标准工时软件的作用?如何定义标准作业及使用ECRS标准工时软件来设置作业标准?
- 程序员的财务自由之路
- Java利用while求一等比数列_UPC-6760 Problem H 九连环 【重庆OI2018】等比数列求和JAVA高精度...
- R语言使用lm函数拟合多项式回归模型:使用predict函数和训练好的模型进行预测推理、plot函数和lines函数可视化多个多项式曲线图
- 2020考研数学一大纲之完全解析(五)
- 【转】二十几岁必须思考的事
- 证券公司需在主办存管银行开立法人资金交收过渡账户用
- Thinking in java 第13章 字符串 笔记+习题