测绘程序设计基础 实验4 CSU

实验4 类的创建

(大地四边形类设计)

(工具:VS2010)

一、 实验目的

• 掌握面向对象编程基本思想
• 掌握VC++.net中创建类
• 掌握建立和使用对象
• 掌握运算符号重载
• 理解类的继承和多态性

二、实验内容与要求

设计一个大地四边形类,注意大地四边形的基本属性,功能上只要求能够设置和返回已知点坐标、8个观测角度、待定点近似坐标计算以及闭合差的计算。

三、设计与实现:

3.1 设计思路:

在这里插入图片描述

3.2 界面设计及属性:

在这里插入图片描述

3.3主要代码:

3.3.1文件:<Support.h> 
#pragma once
#include "Angle.h"
#include "math.h"
#include "matrix.h"

class Support
{
private:
	Angle Angles[8];
	Angle Results[8];
    double x1;
	double y1;
	double x2;
	double y2;
	double x3;
	double y3;
	double x4;
	double y4;
public:
	Support(void);
	~Support(void);
	void ForeIntersecPos(double Xa,double Ya, double Xb,double Yb, 
                     double Alfa,double Beta, double &Xp,double &Yp);

	int SplitStringArray(CString str, char split, CStringArray& aStr);
	//读取数据至数组

	void read(CString strdate,Support &p);
	//对数据进行处理
    void out(CString &strResult,Support &p,double Sigma);
	void pocess(CString strdate,CString &strResult);
	//输出
};


3.3.2文件:<Support.cpp>  
/***************************************************************************
*  文件名:<Support.cpp>                                                    *
*                                                                          *
*  描述:大地四边形                                                         *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年4月5日    代码格式修改        张                        *
*                                                                          *
*  外部过程:                                                              *
*                                                                          *
/**************************************************************************/


/***************************************************************************
*  名字:void ForeIntersecPos                                              *
*                                                                          *
*  描述:前方交会函数,利用引用赋值                                        *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年4月5日      引用该函数           张                     *
*  参数: 1.double Xa                                                      *
*         2.double Ya                                                      *
*         3.double Xb                                                      *
*         4.double Yb                                                      *
*         5.double Alfa                                                    *
*         6.double Beta                                                    *
*         7.double &Xp                                                     *
*         8.double &Yp                                                     *
*  返回值:无返回值                                                        *
*                                                                          *
*  注:                                                                    *
/**************************************************************************/
void Support::ForeIntersecPos(double Xa,double Ya, double Xb,double Yb, double Alfa,double Beta, double &Xp,double &Yp)
{
	
        double ctgA, ctgB;
//计算角a,b的反正切值
        ctgA = 1 / tan(Alfa);
        ctgB = 1 / tan(Beta);
        //计算前方交会定位值
        Xp = ((Xa * ctgB + Xb * ctgA) + (Yb - Ya)) / (ctgA + ctgB);
        Yp = ((Ya * ctgB + Yb * ctgA) + (Xa - Xb)) / (ctgA + ctgB);

}
	


/***************************************************************************
*  名字:double CSupport::SplitStringArray(CString str, char split, CStringArray& aStr)    *
*                                                                          *
*  描述:字符串分割函数                                                    *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年3月20日       创建该函数          张                    *
*  参数: 1.CString str                                                    *
*         2.char split                                                     *
*         3.CStringArray& aStr                                             *
*  返回值:int类型数据 返回n                                              *
*                                                                          *
*  注:                                                                    *
/**************************************************************************/
int Support::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();
}
/***************************************************************************
*  名字:void read(CString strdate,Support &p)                             *
*                                                                          *
*  描述:CString类型读取函数  调用了函数SplitStringArray                  *
*                           将点位坐标放入对象p,角度放入Angles            *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年4月4日       创建该函数          张                     *
*  参数: 1.CString strdate                                                *
*         2.Support &p                                                     *
*  返回值:无                                                              *
*                                                                          *
*  注:                                                                    *
/**************************************************************************/
void Support::read(CString strdate,Support &p)
{
	int iLine;
	CStringArray aStrLine;
	iLine=SplitStringArray(strdate,13,aStrLine);
	if(iLine=0)
	{
		AfxMessageBox(_T("请输入数据!"));
	}
	
	CStringArray aStrTmp;
	int n;

	n=SplitStringArray(aStrLine[0],',',aStrTmp);
	p.x1=_tstof(aStrTmp[1]);
	p.y1=_tstof(aStrTmp[2]);

	n=SplitStringArray(aStrLine[1],',',aStrTmp);
	p.x2=_tstof(aStrTmp[1]);
	p.y2=_tstof(aStrTmp[2]);
	
	for(int i=3;i<=10;i++)
	{
		n=SplitStringArray(aStrLine[i],',',aStrTmp);
		Angles[i-3]=Angle(_tstof(aStrTmp[1]),DMS);
	}
}
/***************************************************************************
*  名字:void out(CString &strResult,Support &p,double Sigma)              *
*                                                                          *
*  描述:CString类型输出函数                                               *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年4月4日       创建该函数          张                     *
*  参数: 1.CString &strResult                                             *
*         2.Support &p                                                     *
*         3.double Sigma //是单位权中误差                                  *
*  返回值:无                                                              *
*                                                                          *
*  注:                                                                    *
/**************************************************************************/
void Support::out(CString &strResult,Support &p,double Sigma)
{
	strResult.Format(_T("%s\t%s\t%s\t%s\t\r\n"),
		_T("点号"),
		_T("   X(m)  "),
		_T("Y(m)"),
		_T("")
		);
	
	CString strOutput;
	strOutput.Format(_T("%s\r\n %s%.4lf\t%.4lf\t%s\r\n %s%.4lf\t%.4lf\t%s\r\n %s%.4lf\t%.4lf\t%s\r\n %s%.4lf\t%.4lf\t%s\r\n %s\r\n%.4lf%s\r\n %s\r\n %s\r\n"),
		                _T("大地四边形条件平差结果"),
						_T("(已知点)A:"),p.x1,p.y1,_T(""),
						_T("(已知点)B:"),p.x2,p.y2,_T(""),
						_T("(未知点)C:"),p.x3,p.y3,_T(""),
						_T("(未知点)D:"),p.x4,p.y4,_T(""),
						_T("单位权中误差 "),
						Sigma,_T("(”)"),
						_T("观测值平差结果:"),
						_T("序号	平差后的角度(DMS)")
						);
	strResult=strResult+strOutput;
	for(int z=0;z<8;z++)
	{
		strOutput.Format(_T("%d\t%.4f\r\n"),z+1,Results[z](DMS));
		strResult=strResult+strOutput;
	}
}

/***************************************************************************
*  名字:void pocess(CString strdate,CString &strResult)                   *
*                                                                          *
*  描述:大地四边形主函数,调用了函数read()、out()两个主函数               *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年4月4日       创建该函数          张                    *
*  参数: 1.CString strdate                                                *
*         2.CString &strResult                                             *
*  返回值:无                                                              *
*                                                                          *
*  注:                                                                    *
/**************************************************************************/
void Support::pocess(CString strdate,CString &strResult)
{
	//建立一个对象
	Support p;
	read(strdate,p);
	//定权
	matrix P;
	P.SetSize(8,8);
	for(int i=0;i<8;i++)
	{
	P(i,i) = 1;
	}
	//条件方程
	matrix A;
	A.SetSize(4,8);
	for(int i=0;i<8;i++)
	{
		A(0,i)=1;
	}
	for(int i=0;i<4;i++)
	{
		A(1,i)=1;
	}

	A(2,0)=1;
	A(2,1)=1;
	A(2,6)=1;
	A(2,7)=1;
	A(3,0)=1/tan(Angles[0](RAD)+Angles[7](RAD))-1/tan(Angles[0](RAD));
	A(3,3)=1/tan(Angles[3](RAD))-1/tan(Angles[3](RAD)+Angles[4](RAD));
	

	matrix W;
	W.SetSize(4,1);
	W(0,0) = ( Angles[0](DEG) + Angles[1](DEG) + Angles[2](DEG) + Angles[3](DEG)+ Angles[4](DEG) + Angles[5](DEG) + Angles[6](DEG) + Angles[7](DEG) - 360 ) * 3600;
	W(1,0) = ( Angles[0](DEG) + Angles[1](DEG) + Angles[2](DEG) + Angles[3](DEG) - 180 ) * 3600;
    W(2,0) = ( Angles[0](DEG) + Angles[1](DEG) + Angles[6](DEG) + Angles[7](DEG) - 180 ) * 3600;
	W(3,0) = ( 1 - ( sin(Angles[0](RAD)) * sin(Angles[6](RAD)) * sin( Angles[3](RAD)+ Angles[4](RAD) ) )/ ( sin(Angles[3](RAD)) * sin( Angles[0](RAD)+ Angles[7](RAD) ) * sin(Angles[5](RAD)) ) ) * Ro;
	// N(Naa) K(K联系数矩阵) V(V改正数)
    matrix N,InvN;
	matrix K;
	matrix Zero(4,1);
	matrix V;
	N=A*P.Inv()*~A;
	InvN=N.Inv();
	
    //K=Zero-InvN*W;
	K = Zero-InvN * W;
	V=P.Inv()*~A*K;
	//L=L'+V    计算改正后的观测值
	for(int i=0;i<8;i++)
	{
		Results[i](DEG)=Angles[i](DEG)+V(i,0)/3600;
	}
	//前方交会计算待定点坐标
	double dCAB = Angles[1](RAD) + Angles[2](RAD);
	double dABC = Angles[0](RAD);
	double dDAB = Angles[1](RAD);
	double dABD = Angles[0](RAD) + Angles[7](RAD);
	
	ForeIntersecPos(p.x1,p.y1,p.x2,p.y2,dCAB,dABC,p.x3,p.y3);
	ForeIntersecPos(p.x1,p.y1,p.x2,p.y2,dDAB,dABD,p.x4,p.y4);

	matrix Omiga;
	Omiga =~V*P*V;
	double Sigma;
	Sigma=sqrt(Omiga(0,0)/4);
	
	out(strResult,p,Sigma);
}

3.3.3文件:< RS_110_zhang_SY4_01Dlg.cpp >  
/***************************************************************************
*  文件名:<RS_110_zhang_SY4_01Dlg.cpp>                             *
*                                                                          *
*  描述:大地四边形对话框文件                                               *
*                                                                          *
*  历史:**日期**         **理由**            **签名**                     *
*      2019年4月5日    代码格式修改           张                    *
*                                                                          *
*  外部过程:                                                              *
*                                                                          *
/**************************************************************************/
void CRS_110_zhang_SY4_01Dlg::OnBnClickedWork()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);
	Support k;
	k.pocess(strdate,strResult);
	UpdateData(false);
}


void CRS_110_zhang_SY4_01Dlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);
	strdate.Format(_T(""));
	strResult.Format(_T(""));
	UpdateData(false);
}

3.4运行结果

在这里插入图片描述

3.5设计技巧:

 通过类调用,调用了矩阵matrix、角度类,节省大量时间。

代码虽多,不要贪杯~

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值