椭球面上任意梯形面积C#
publicpartialclass Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Read_datar_d = new Read_data();
privatevoid button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = " 文本文档(*.txt)|*.txt";
r_d.read_text =null ;
r_d.row = 0;
try { openFileDialog1.ShowDialog(); }
catch (Exception )
{
MessageBox .Show(" 打开错误" ); return ;
}
//读取数据
r_d.Read_text(openFileDialog1.FileName);
textBox1.Text = openFileDialog1.FileName;
textBox1.Enabled = true ;
}
Trapezoid tpz1;
Trapezoid tpz2;
privatevoid button2_Click(object sender, EventArgs e)
{
string [] s = r_d.read_text.Split(',' );
//初始化两个梯形
tpz1 = new Trapezoid ();
tpz2 = new Trapezoid ();
tpz1.X1=Convert .ToDouble( s[0]);
tpz1.Y1=Convert .ToDouble( s[1]);
tpz1.X2=Convert .ToDouble( s[2]);
tpz1.Y2=Convert .ToDouble( s[3]);
tpz2 .X1=Convert .ToDouble (s[4]);
tpz2 .Y1=Convert .ToDouble (s[5]);
tpz2 .X2=Convert .ToDouble (s[6]);
tpz2 .Y2=Convert .ToDouble (s[7]);
//获取梯形面积
tpz1.get_s();
tpz2.get_s();
button3.Enabled =true ;
MessageBox .Show(" 数据已处理!" );
}
privatevoid button3_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
if (folderBrowserDialog1.SelectedPath == null )
{
MessageBox .Show(" 输出路径不能为空" );
return ;
}
textBox2 .Text =folderBrowserDialog1 .SelectedPath;
F_out f1=new F_out ();
f1.out_text(tpz1,tpz2,folderBrowserDialog1 .SelectedPath);
button3.Enabled =false ;
textBox2.Enabled =true ;
MessageBox .Show(" 数据已导出!" );
}
}
class Read_data
{
publicstring read_text;
publicint row = 0;
publicvoid Read_text(string path)
{
StreamReader sr = new StreamReader (path);
read_text = null ;
string line = null ;
while ((line = sr.ReadLine()) != null )
{
read_text += line + "," ;
if (read_text.Contains(",," ))
{
read_text = read_text.Replace(",," , "," );
row--;
}
row++;
}
sr.Close();
read_text = read_text.Substring(0, read_text.Length - 1);
}
}
class Trapezoid
{
publicdouble X1 = 0;
publicdouble Y1 = 0;
publicdouble X2 = 0;
publicdouble Y2 = 0;
publicdouble L1 = 0;
publicdouble B1 = 0;
publicdouble L2 = 0;
publicdouble B2 = 0;
publicdouble s = 0;
double a = 6378140, b = 6356755;
publicvoid get_s()
{
double c = a * a / b, e_2, A, B, C, D, E;
e_2 = get_e_2(a, b, c);
A = get_A(e_2);
B = get_B(e_2);
C = get_C(e_2);
D = get_D(e_2);
E = get_E(e_2);
L2 = get_L(X2, Y2);
L1 = get_L(X1, Y1);
B2 = get_B(X2, Y2);
B1 = get_B(X1, Y1);
s = 2 * b * b * (L2 - L1) * (A * Math .Sin(0.5 * (B2 - B1)) * Math .Cos((B2 + B1) / 2) - B * Math .Sin(1.5 * (B2 - B1)) * Math .Cos(3 * (B2 + B1) / 2) + C * Math .Sin(2.5 * (B2 - B1)) * Math .Cos((B2 + B1) / 2) - D * Math .Sin(3.5 * (B2 - B1)) * Math .Cos(7 * (B2 + B1) /
2) + E * Math .Sin(4.5 * (B2 - B1)) * Math .Cos(9 * (B2 + B1) / 2));
}
privatedouble get_e_2(double a, double b, double c)
{
double e_2 = (a * a - b * b) / (a * a);
return e_2;
}
privatedouble get_A(double e_2)
{
double A = 1 + 3.0 / 6 * e_2 + 30.0 / 80 * e_2 * e_2 + 35.0 / 112 * Math .Pow(e_2, 3) + 630.0 / 2304 * Math .Pow(e_2, 4);
return A;
}
privatedouble get_B(double e_2)
{
double B = 1.0 / 6 * e_2 + 15.0 / 80 * Math .Pow(e_2, 2) + 21.0 / 112 * Math .Pow(e_2, 3) + 420.0 / 2304 * Math .Pow(e_2, 4);
return B;
}
privatedouble get_C(double e_2)
{
double C = 3.0 / 80 * Math .Pow(e_2, 2) + 7.0 / 112 * Math .Pow(e_2, 3) + 180.0 / 2304 * Math .Pow(e_2,
4);
return C;
}
privatedouble get_D(double e_2)
{
double D = 1.0 / 112 * Math .Pow(e_2, 3) + 45.0 / 2304 * Math .Pow(e_2, 4);
return D;
}
privatedouble get_E(double e_2)
{
double E = 5.0 / 2304 * Math .Pow(e_2, 4);
return E;
}
privatedouble get_L(double x, double y)
{
double Bf = get_Bf(x);
double n_2 = get_n_2((a * a - b * b) / (b * b), Bf);
double V = get_V(n_2);
double c = a * a / b;
double N = get_N(c, V);
double t = Math .Tan(Bf);
double y_ = get_Y_changed(y);
double L = (1 / Math .Cos(Bf)) * (y_ / N) - 1.0 / 6 * (1 + 2 * t * t + n_2) * (1 / Math .Cos(Bf)) * Math .Pow(y_ / N, 3) + 1.0 / 120 * (5 + 28 * t * t + 24 * t * t + 6 * n_2 + 8 * n_2 * t * t) * (1 / Math .Cos(Bf)) * Math .Pow(y_ / N, 5) + 2.[1**********]319;
return L;
}
privatedouble get_B(double x, double y)
{
double Bf = get_Bf(x);
double n_2 = get_n_2((a * a - b * b) / (b * b), Bf);
double c = a * a / b;
double V = get_V(n_2);
double t = Math .Tan(Bf);
double y_ = get_Y_changed(y);
double N = get_N(c, V);
double B = Bf - 0.5 * (V * V * t) * Math .Pow(y_ / N, 2) + 1.0 / 24 * (5 + 3 * t * t + n_2 - 9 * n_2 * t * t) * (V * V * t) * Math .Pow(y_ / N, 4) - 1.0 / 720 * (61 + 90 * t * t + 45 * Math .Pow(t,
4)) * (V * V * t) * Math .Pow(y_ / N, 6);
return B;
}
privatedouble get_Bf(double x)
{
double K0 = 1.[1**********]752E-07, K1 = 5.[1**********]393E-03, K2 = 2.[1**********]158E-05, K3 =
2.[1**********]336E-07, K4 = 2.[1**********]273E-09;
double E = K0 * x;
double Bf = E + Math .Cos(E) * (K1 * Math .Sin(E) - K2 * Math .Pow(Math .Sin(E), 3) + K3 * Math .Pow(Math .Sin(E), 5) - K4 * Math .Pow(Math .Sin(E), 7));
return Bf;
}
privatedouble get_n_2(double e_pow_2, double Bf)
{
double n_2 = e_pow_2 * Math .Pow(Math .Cos(Bf), 2);
return n_2;
}
privatedouble get_N(double c, double V)
{
double N = c / V;
return N;
}
privatedouble get_V(double n_2)
{
double V = Math .Sqrt(1 + n_2);
return V;
}
privatedouble get_Y_changed(double Y_Not_changed)
{
double Y_changed = Y_Not_changed - 500000;
return Y_changed;
}
}
class F_out
{
publicvoid out_text(Trapezoid tpz1,Trapezoid tpz2, string path) {
StreamWriter sw = new StreamWriter (path +"//result.txt");
sw.WriteLine(tpz1.B1.ToString() + "," + tpz1.L1.ToString()); sw.WriteLine(tpz1.B2.ToString() + "," + tpz1.L2.ToString()); sw.WriteLine(tpz1.s.ToString());
sw.WriteLine();
sw.WriteLine(tpz2.B1.ToString() + "," + tpz2.L1.ToString()); sw.WriteLine(tpz2.B2.ToString() + "," + tpz2.L2.ToString()); sw.WriteLine(tpz2.s.ToString());
sw.Close();
}
}