如何从我的文本文件中读取值并存储在变量中进行数学计算?

时间:2016-08-16 05:04:43

标签: c# c#-4.0 c#-3.0 c#-2.0

       int a=6378137;
       int A0=6367449;
       double B0=16038.43;
       double C0=16.83261;
       double D0=0.021984;
       double E0= 0.000313;
       double k0=0.9996; 
       double e1=0.081819;
       double e1sq = 0.006739497;
       double m = -120;
       double l = 60;
       int n = 11;
       int o = 6 *n- 183;
       double p = ((m - o) * 0.01744444);
       double q = l * 0.0174444;
       double r = m * 0.0174444;
       double s = a * (1 - e1 * e1) / (1 - ((e1 * Math.Sin(q)) * (e1 * Math.Sin(q))*(e1 * Math.Sin(q))));
       double t = a / ((1 - (e1 * Math.Sin(q))));
       double v = A0 * q - B0 * Math.Sin(2 * q) + C0 * Math.Sin(4 * q) - D0 * Math.Sin(6 * q) + E0 * Math.Sin(8 * q);
       double x = v * k0;
       double y = t * Math.Sin(q) * Math.Cos(q) / 2;
       double z = (t * Math.Sin(q) * (Math.Cos(q)* Math.Cos(q)*Math.Cos(q)) / 24) * (5 - (Math.Tan(q)* Math.Tan(q)) + 9 * e1sq * (Math.Cos(q) *Math.Cos(q)) + 4 * e1sq *e1sq * (Math.Cos(q)*Math.Cos(q)*Math.Cos(q)*Math.Cos(q)) ) * k0;
       double AA = t * Math.Cos(q) * k0;
       double AB = (Math.Cos(q)*Math.Cos(q)*Math.Cos(q)) * (t / 6) * (1 - (Math.Tan(q) *Math.Tan(q)) + e1sq * (Math.Cos(q) *Math.Cos(q))) * k0;
       double AC = ((p * p * p * p * p * p) * t * Math.Sin(q) * (Math.Cos(q) * Math.Cos(q) * Math.Cos(q) * Math.Cos(q) * Math.Cos(q)) / 720) * (61 - 58 * (Math.Tan(q) * Math.Tan(q)) + (Math.Tan(q) * Math.Tan(q) * Math.Tan(q) * Math.Tan(q)) + 270 * e1sq * (Math.Cos(q) * Math.Cos(q)) - 330 * e1sq * (Math.Sin(q) * Math.Sin(q))) * k0;
       double AD = (x+y*p*p+z*(p*p*p*p));
       double AE;
       double AF;
       if (AD < 0)
        {
           AE = (10000000 + AD);
        }
       else            {
           AE = AD;
       }
       AF = 500000 + (AA * p + AB * (p * p * p));

       using (StreamWriter writer = new StreamWriter(@"C:\Users\dcf\Desktop\out.txt"))
        {
            writer.WriteLine("north:{0}",AE);
            writer.WriteLine("east:{0}",AF);
        }

这是我的代码,其中m和l值应该具有文本文件中的值。我的文本文件看起来像

  

M,L

     

56536716.534,43843327.880

     

56584832.507,43501825.240

     

56669161.226,43199470.844

     

56715913.464,42856275.950

     

56782842.247,42435886.070

     

56810019.308,42071222.859

     

56836462.600,41706208.191

     

56900872.591,41282609.754

我需要直接从我的文本文件中读取m和l值来进行计算。

0 个答案:

没有答案