// DEMO6Dlg.cpp: 实现文件
//
#include "stdafx.h"
#include "DEMO6.h"
#include "DEMO6Dlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// CDEMO6Dlg 对话框
CDEMO6Dlg::CDEMO6Dlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DEMO6_DIALOG, pParent)
, n(0)
, m(0)
, L(0)
, x(0)
, y(0)
, dDegB(0)
, dDegL(0)
, iMinB(0)
, iMinL(0)
, dSecondB(0)
, dSecondL(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDEMO6Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, n);
DDX_Text(pDX, IDC_EDIT2, m);
DDX_Text(pDX, IDC_EDIT9, L);
DDX_Text(pDX, IDC_EDIT10, x);
DDX_Text(pDX, IDC_EDIT11, y);
DDX_Text(pDX, IDC_EDIT3, dDegB);
DDX_Text(pDX, IDC_EDIT6, dDegL);
DDX_Text(pDX, IDC_EDIT4, iMinB);
DDX_Text(pDX, IDC_EDIT7, iMinL);
DDX_Text(pDX, IDC_EDIT5, dSecondB);
DDX_Text(pDX, IDC_EDIT8, dSecondL);
}
BEGIN_MESSAGE_MAP(CDEMO6Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDCANCEL, &CDEMO6Dlg::OnBnClickedCancel)
ON_BN_CLICKED(IDOK, &CDEMO6Dlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON1, &CDEMO6Dlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CDEMO6Dlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CDEMO6Dlg 消息处理程序
const double PI = 4 * atan(1.0);
//获得分带方式返回中央子午线经度
int CDEMO6Dlg::SetProjectType(int n)
{
UpdateData(TRUE);
int k; //记录分带带号
double L0; //经度
L0 = dDegL + iMinL / 60 + dSecondL / 3600;
if (n == 1) //6度带
{
k = int(L0 / 6) + 1;
L = 6 * k - 3;
}
else if (n == 2) //3度带
{
k = int((L0 + 1.5) / 3);
L = 3 * k;
}
else if (n == 3) //自主分带
L = L0;
return L;
}
//获取椭球参数
void CDEMO6Dlg::SetParameter(int m, double &a, double &b)
{
if (m == 1) //克拉索夫斯基椭球
{
a = 6378245.0;
b = 6356863.0187730473;
//e=sqrt(0.006693421622966);
}
else if (m == 2) //1975国际协议椭球
{
a = 6378140.0;
b = 6356755.2881575287;
//e=sqrt(0.006694384999588);
}
else if (m == 3) //WGS-84椭球
{
a = 6378137.0;
b = 6356752.3142;
//e=sqrt(0.0066943799013);
}
}
BOOL CDEMO6Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != nullptr)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CDEMO6Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CDEMO6Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CDEMO6Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CDEMO6Dlg::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
CDialogEx::OnCancel();
}
void CDEMO6Dlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
double N;
double t;
double Eta;
double X;
double A0, A2, A4, A6, A8;
double RadB;
double Rou;
Rou = 180 * 3600 / PI;
double a, b, e1, e2; //椭球参数
SetParameter(m, a, b);
e1 = sqrt(a*a - b * b) / a;
e2 = sqrt(a*a - b * b) / b;
double l;
L = SetProjectType(n);
double L0;
L0 = dDegL + double(iMinL) / 60 + dSecondL / 3600;
l = abs(L0 - L) * 3600;
RadB = (dDegB + double(iMinB) / 60 + dSecondB / 3600)*PI / 180;
N = a / sqrt(1 - e1 * e1*sin(RadB)*sin(RadB));
t = tan(RadB);
Eta = e2 * cos(RadB);
A0 = 1 + 3.0 / 4 * e1*e1 + 45.0 / 64 * pow(e1, 4) + 350.0 / 512 * pow(e1, 6) + 11025.0 / 16384 * pow(e1, 8);
A2 = -1.0 / 2 * (3.0 / 4 * e1*e1 + 60.0 / 64 * pow(e1, 4) + 525.0 / 512 * pow(e1, 6) + 17640.0 / 16384 * pow(e1, 8));
A4 = 1.0 / 4 * (15.0 / 64 * pow(e1, 4) + 210.0 / 512 * pow(e1, 6) + 8820.0 / 16384 * pow(e1, 8));
A6 = -1.0 / 6 * (35.0 / 512 * pow(e1, 6) + 2520.0 / 16384 * pow(e1, 8));
A8 = 1.0 / 8 * (315.0 / 16384 * pow(e1, 8));
X = a * (1 - e1 * e1)*(A0*RadB + A2 * sin(2 * RadB) + A4 * sin(4 * RadB) + A6 * sin(6 * RadB) + A8 * sin(8 * RadB));
x = X + N / (2 * Rou*Rou)*sin(RadB)*cos(RadB)*l*l +
N / (24 * pow(Rou, 4))*sin(RadB)*pow(cos(RadB), 3)*(5 - t * t + 9 * Eta*Eta + 4 * pow(Eta, 4))*pow(l, 4) +
N / (720 * pow(Rou, 6))*sin(RadB)*pow(cos(RadB), 5)*(61 - 58 * t*t + pow(t, 4))*pow(l, 6);
y = N / Rou * cos(RadB)*l +
N / (6 * pow(Rou, 3))*pow(cos(RadB), 3)*(1 - t * t + Eta * Eta)*pow(l, 3) +
N / (120 * pow(Rou, 5))*pow(cos(RadB), 5)*(5 - 18 * t*t + pow(t, 4) + 14 * Eta*Eta - 58 * Eta*Eta*t*t)*pow(l, 5);
UpdateData(FALSE);
//CDialogEx::OnOK();
}
void CDEMO6Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
double t_f;
double Eta_f;
double B_f;
double N_f;
double M_f;
double X = x;
double B0;
double K0, K2, K4, K6;
double a, b, e1, e2; //椭球参数
SetParameter(m, a, b);
e1 = sqrt(a*a - b * b) / a;
e2 = sqrt(a*a - b * b) / b;
double A0;
A0 = 1 + 3.0 / 4 * e1*e1 + 45.0 / 64 * pow(e1, 4) + 350.0 / 512 * pow(e1, 6) + 11025.0 / 16384 * pow(e1, 8);
B0 = X / (a*(1 - e1 * e1)*A0);
K0 = 1.0 / 2 * (3.0 / 4 * e1*e1 + 45.0 / 64 * pow(e1, 4) + 350.0 / 512 * pow(e1, 6) + 11025.0 / 16384 * pow(e1, 8));
K2 = -1.0 / 3 * (63.0 / 64 * pow(e1, 4) + 1108.0 / 512 * pow(e1, 6) + 58239.0 / 16384 * pow(e1, 8));
K4 = 1.0 / 3 * (604.0 / 512 * pow(e1, 6) + 68484.0 / 16384 * pow(e1, 8));
K6 = -1.0 / 3 * (26328.0 / 16384 * pow(e1, 8));
B_f = B0 + sin(2 * B0)*(K0 + sin(B0)*sin(B0)*(K4 + K6 * sin(B0)*sin(B0)));
t_f = tan(B_f);
Eta_f = e2 * cos(B_f);
N_f = a / sqrt(1 - e1 * e1*sin(B_f)*sin(B_f));
M_f = N_f / (1 + e2 * e2*cos(B_f)*cos(B_f));
double B;
B = B_f - t_f / (2 * M_f*N_f)*y*y +
t_f / (24
评论0