椭球面上任意梯形面积C#
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
publicpartialclass Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Read_data r_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;