c#大地测量学各坐标系坐标转换(窗体应用程序)

大地坐标系

空间直角坐标系

子午面直角坐标系

c#大地测量学各坐标系坐标转换(窗体应用程序)_第1张图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double L, B, H, X, Y, Z, x, y;
            double a = 6378137;//椭圆长半轴
            double b = 6356752.3141;//椭圆短半轴
            double e_2 = 0.00669438002290;//椭圆第一偏心率e^2
            double e_dot_2 = 0.00673949677548;//椭圆第二偏心率e'^2  
            double c = a * a / b;
            double k = 1 + e_dot_2;
            double p = Math.PI / 180;//角度值转弧度制系数
            //如果需要更严谨的代码,可以更换为三个textbox是否为空的判断,并自行添加参数错误提示的信息
            if (textBox5.Text != string.Empty&& textBox4.Text != string.Empty)//已知大地坐标系
            {
                L = Convert.ToDouble(textBox1.Text);
                B= Convert.ToDouble(textBox4.Text);
                H= Convert.ToDouble(textBox5.Text);
                double W = Math.Sqrt(1 - e_2 * Math.Sin(B*p) * Math.Sin(B * p));
                double V = Math.Sqrt(1 + e_dot_2 * Math.Cos(B * p) * Math.Cos(B * p));
                double N = a / W;
                //计算空间直角坐标系
                X = (N+H)*Math.Cos(B * p) * Math.Cos(L * p);
                Y = (N + H) * Math.Cos(B * p) * Math.Sin(L * p);
                Z = (N*(1-e_2)+H)*Math.Sin(B * p);
                textBox3.Text = Convert.ToString(X);
                textBox8.Text = Convert.ToString(Y);
                textBox9.Text = Convert.ToString(Z);
                //计算子午面直角坐标系
                x =X/Math.Cos(L*p);
                y = Z;
                textBox2.Text = Convert.ToString(L);
                textBox6.Text = Convert.ToString(x);
                textBox7.Text = Convert.ToString(y);
            }
            else if (textBox7.Text != string.Empty&& textBox6.Text != string.Empty)//已知子午面直角坐标系
            {
                L = Convert.ToDouble(textBox2.Text);  
                x= Convert.ToDouble(textBox6.Text);
                y= Convert.ToDouble(textBox7.Text);
                //计算空间直角坐标系
                X = x * Math.Cos(L * p);
                Y = x * Math.Sin(L * p);
                Z = y;
                textBox3.Text = Convert.ToString(X);
                textBox8.Text = Convert.ToString(Y);
                textBox9.Text = Convert.ToString(Z);
                //计算大地坐标系
                double tan0 = Z / Math.Sqrt(X *X + Y *Y);
                double P = c * e_2 / Math.Sqrt(X * X + Y * Y);
                double tanB=tan0,cha;//循环迭代
                do
                {
                    cha = tanB;
                    tanB = tan0 + P * cha / Math.Sqrt(k + cha * cha);
                } while (Math.Abs(cha-tanB) > Math.Pow(10, -10));
                B = Math.Atan(tanB );
                double W = Math.Sqrt(1 - e_2 * Math.Sin(B ) * Math.Sin(B ));
                double V = Math.Sqrt(1 + e_dot_2 * Math.Cos(B ) * Math.Cos(B ));
                double N = a / W;
                H = Math.Sqrt(X * X + Y * Y) / Math.Cos(B ) - N;
                textBox1.Text = Convert.ToString(L);
                textBox4.Text = Convert.ToString(B * 180 / Math.PI);
                textBox5.Text = Convert.ToString(H);
            }
            else if (textBox9.Text != string.Empty&& textBox8.Text != string.Empty)//已知空间直角坐标系
            {
                X = Convert.ToDouble(textBox3.Text);
                Y = Convert.ToDouble(textBox8.Text);
                Z = Convert.ToDouble(textBox9.Text);
                //计算大地坐标系
                L = Math.Atan(Y / X );
                double tan0 = Z / Math.Sqrt(X * X + Y * Y);
                double P = c * e_2 / Math.Sqrt(X * X + Y * Y);
                double tanB = tan0, cha;//循环迭代
                do
                {
                    cha = tanB;
                    tanB = tan0 + P * cha / Math.Sqrt(k + cha * cha);
                } while (Math.Abs(cha - tanB) > Math.Pow(10, -10));
                B = Math.Atan(tanB );
                double W = Math.Sqrt(1 - e_2 * Math.Sin(B ) * Math.Sin(B ));
                double V = Math.Sqrt(1 + e_dot_2 * Math.Cos(B ) * Math.Cos(B));
                double N = a / W;
                H = Math.Sqrt(X * X + Y * Y) /Math.Cos(B ) - N;
                textBox1.Text = Convert.ToString(L*180/Math.PI);
                textBox4.Text = Convert.ToString(B *180/ Math.PI);
                textBox5.Text = Convert.ToString(H);
                //计算子午面直角坐标系
                x = X / Math.Cos(L);
                y = Z;
                textBox2.Text = Convert.ToString(L*180/Math.PI);
                textBox6.Text = Convert.ToString(x);
                textBox7.Text = Convert.ToString(y);
            }
        }

    }
}

你可能感兴趣的:(大地测量学,c#,开发语言,ui,几何学)