⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gauss34dlg.cpp

📁 Gauss投影计算方法以及界面美化
💻 CPP
字号:
// Gauss34Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Gauss34.h"
#include "Gauss34Dlg.h"
#include "math.h"
#define PAI 3.14159265358979323846 
const double e = 0.00000000001;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGauss34Dlg dialog

CGauss34Dlg::CGauss34Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGauss34Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGauss34Dlg)
	m_Radio1 = 0;
	m_Radio2 = 0;
	m_zyzwx = 0.0;
	m_wd = 0.0;
	m_jd = 0.0;
	m_x = 0.0;
	m_y = 0.0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGauss34Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGauss34Dlg)
	DDX_Radio(pDX, IDC_RADIO1, m_Radio1);
	DDX_Radio(pDX, IDC_RADIO4, m_Radio2);
	DDX_Text(pDX, IDC_EDIT1, m_zyzwx);
	DDX_Text(pDX, IDC_EDIT2, m_wd);
	DDX_Text(pDX, IDC_EDIT3, m_jd);
	DDX_Text(pDX, IDC_EDIT4, m_x);
	DDX_Text(pDX, IDC_EDIT5, m_y);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGauss34Dlg, CDialog)
	//{{AFX_MSG_MAP(CGauss34Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDC_BUTTON1, OnOK)
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGauss34Dlg message handlers

BOOL CGauss34Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGauss34Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGauss34Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGauss34Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}




double CGauss34Dlg::jiaoduTOhudu(double a)
{
	double a1,a2,fsign,b;
	if( fabs(a) < e ) return(0.0);
	b=fabs(a);  fsign=a/b;
	a1=floor(b+e)+floor((b-floor(b+e))*100.+e)/60.;
	a2=(b*100.-floor(b*100.+e))/36.;
	a1+=a2; a1=fsign*a1*PAI/180.;
	return (a1);
}

double CGauss34Dlg::huduTOjiaodu(double a)
{
	double a_sign; 
	if(a>=0)
	{
		a_sign = 1;
	}else
	{
		a_sign = -1;
	}

	a = fabs(a);
	double a1=a*180./PAI+e;
	double a2=floor(a1+e)+floor((a1-floor(a1+e))*60+e)/100;
    double a3=(a1-jiaoduTODegree(a2))*0.36;
	a2+=a3;
	return (a_sign*a2);

}


void CGauss34Dlg::OnOK() 
{
	// TODO: Add your control notification handler code here
			UpdateData(true);
	if (m_Radio2 == 0)
	{

		if (m_Radio1 == 0)
		{
			double j = 6378245, k = 6356863.0188;
			BLTOxy(j,k);	
		}

		if (m_Radio1 == 1)
		{
			double j = 6378140, k= 6356755.2882;
			BLTOxy(j,k);	
		}

		if (m_Radio1 == 2)
		{
			double j = 6378137, k = 6356752.3142;
			BLTOxy(j,k);		
		}
	}
	if (m_Radio2 == 1)
	{

		if (m_Radio1 == 0)
		{
			double j = 6378245, k = 6356863.0188;
			xyTOBL(j,k);		
		}

		if (m_Radio1 == 1)
		{
			double j = 6378140,k = 6356755.2882;
			xyTOBL(j,k);	
		}

		if (m_Radio1 == 2)
		{
			double j = 6378137, k = 6356752.3142;
			xyTOBL(j,k);			
		}
	UpdateData(false);
}
}

void CGauss34Dlg::BLTOxy(double j, double k)
{
	double m_jd1,m_wd1,m_jd01;
		m_jd1 = jiaoduTOhudu(m_jd);
		m_jd01 = jiaoduTOhudu(m_zyzwx);
		m_wd1= jiaoduTOhudu(m_wd);


		double A1,A2,A3,A4,A5,e2,e4,e6,e8;
		double X,sinB,cosB,t,t2,N,p,p2,ng2,x,y,e,e1;
		e = sqrt(1 - pow(k/j,2));
		e1 = sqrt(pow(j/k,2) -1);
		e2 = e * e;
		e4 = e * e * e * e;
		e6 = e * e * e * e * e * e;
		e8 = e * e * e * e * e * e * e * e;
		A1 = j * (1 - e2) * (1 + 3*e2/4 + 45*e4/64 + 350*e6/512 + 11025*e8/16384);
		A2 = -j * (1 - e2) * (3*e2/4 + 60*e4/64 + 525*e6/512 + 17640*e8/16384) / 2;
		A3 = j * (1 - e2) * (15*e4/64 + 210*e6/512 + 8820*e8/16384) / 4;
		A4 = -j * (1 - e2) * (35*e6/512 + 2520*e8/16384) / 6;
		A5 = j * (1 - e2) * (315*e8/16384) / 8;
		
		X = A1 * m_wd1 + A2 * sin(2 * m_wd1) + A3 * sin(4 * m_wd1) + A4 * sin(6 * m_wd1) + A5 * sin(8 * m_wd1);
		sinB = sin(m_wd1); 
		cosB = cos(m_wd1); 
		t = tan(m_wd1); 
		t2 = t * t; 		 
		p = cosB * (m_jd1 - m_jd01); 
		p2 = p * p; 
		ng2 = cosB * cosB * e1 * e1; 
		N = j/ sqrt(1 - e * e) / sqrt(1 + ng2);
		x = X + N * t * (1 + ((5 - t2 + (9 + 4 * ng2) * ng2) + (61 + (t2 - 58) * t2) * p2 / 30.0) * p2 / 12) * p2 / 2; 
		y = N * ( 1 + ((1 - t2 + ng2) + ( 5 + t2 * (t2 - 18 - 58 * ng2) + 14 * ng2) * p2 / 20) * p2 / 6) * p; 
		y += 500000;
		
		m_x = x;
		m_y = y;
		UpdateData(false);



}

void CGauss34Dlg::xyTOBL(double j, double k)
{
	double e1 = sqrt(1 - pow(k/j,2));
	double e2 = sqrt(pow(j/k,2) - 1);
	double Bf,jd; 


	double E=e1*e1;
	double A0=1.0+3./4*E+45./64*E*E+350./512*E*E*E+11025./16384*E*E*E*E+43659./65536*E*E*E*E*E;
	double B0=m_wd/(j*(1-E)*A0);
	double K0=(3./4*E+45./64*E*E+350./512*E*E*E+11025./16384*pow(e1,8.))/2;
	double K2=-(63./64*E*E+1108./512*pow(e1,6.)+58239./16384*pow(e1,8.))/3;
	double K4=(604./512*E*E*E+68484./16384*E*E*E*E)/3;
	double K6=-(26328./16384*pow(e1,8))/3;

    double si=sin(B0)*sin(B0);
	Bf=B0+sin(2.*B0)*(K0+si*(K2+si*(K4+K6*si)));

	double tf=tan(Bf);
	double ankef=e2*cos(Bf);

	double c=j/sqrt(1-E);
	double Vf=sqrt(1+ankef*ankef);
    double Nf=c/Vf;

	double Mf=j*(1.-E)/pow((1.-E*sin(Bf)),1.5);
	jd=m_jd-500000.;
	double T=tf*tf, an=ankef*ankef, y2=jd*jd, MN=Mf*Nf;
	double q=jd/Nf;

	m_x=Bf-pow(Vf,2.0)*tf*(1.0+(-(5+3.0*T+an*(1-9.0*T))+(61+45.0*T*(2+T))*pow(q,2.0)/30.0)*pow(q,2.0)/12.0)*pow(q,2.0)/2.0;
	
    double l;
	l=jd/(Nf*cos(Bf))-(1.+2.*T+an)*jd*y2/(6.*pow(Nf,3.)*cos(Bf))+(5.+28.*T+24.*T*T+6.*an+8.*an*T)*y2*y2*jd/(120.*pow(Nf,5.)*cos(Bf));

	m_y=jiaoduTOhudu(m_zyzwx)+l;

	m_x=huduTOjiaodu(m_x);
	m_y=huduTOjiaodu(m_y);
}



void CGauss34Dlg::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_STATIC1,"B");
	SetDlgItemText(IDC_STATIC2,"L");
	SetDlgItemText(IDC_STATIC3,"x");
	SetDlgItemText(IDC_STATIC4,"y");
}

void CGauss34Dlg::OnRadio5() 
{
	// TODO: Add your control notification handler code here
	SetDlgItemText(IDC_STATIC1,"x");
	SetDlgItemText(IDC_STATIC2,"y");
	SetDlgItemText(IDC_STATIC3,"B");
	SetDlgItemText(IDC_STATIC4,"L");
}



double CGauss34Dlg::jiaoduTODegree(double a)
{
		double a_sign; 
	if(a>=0)
	{
		a_sign = 1;
	}else
	{
		a_sign = -1;
	}

	a = fabs(a);
    
	double a1,a2;

	double A = floor(a+e);
	double B = floor((a-A)*100+e);
	a1 = A+B/60;
	a2=(a*100.-floor(a*100.+e))/36.;
	a1+=a2;
	return (a_sign*a1);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -