“System.NullReferenceException”类型的未经处理的异常在 CH.exe 中发生 其他信息: 未将对象引用设置到对象的实例。

樱宁宁 2018-05-11 09:28:25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace CH
{
class Project:Form1
{
public List<SurveyStation> sss;
public string prjName;
public int Meamemode;
public int Edmode;
public int Level;
public double fb;
public double fr;
public double fb_angle;
public double L;
public double fx;
public double fy;
public double fs;
public double K;
public string jisuanzhe;
public string jianchezhe;

private int[] sorted_sss_idx;

public int computeResult()
{
for (int i = 0; i < sss.Count; ++i)
{
int m = sss.Count;
double a = Math.Atan(sss[1].Y - sss[0].Y) / (sss[1].X - sss[0].X);
double startAzi = computeAzi(sss[1].X, sss[1].Y, sss[0].X, sss[0].Y);

double b = Math.Atan(sss[m - 2].Y - sss[m - 1].Y) / (sss[m - 2].X - sss[m - 1].X);
double endAzi = computeAzi(sss[m - 1].X, sss[m - 1].Y, sss[m - 2].X, sss[m - 2].Y);

int endAzi_in_second = 0, startAzi_in_second = 0;
startAzi_in_second = Common.rad2sec(startAzi);
endAzi_in_second = Common.rad2sec(endAzi);
int sum_angle_in_theory = 0;
if (Meamemode == 0)
{
sum_angle_in_theory = endAzi_in_second - startAzi_in_second + (m-2)*180*3600;
}
else
{
sum_angle_in_theory = startAzi_in_second - endAzi_in_second + (m-2)*180*3600;
}
int sum_angle_in_pratice = 0;
for (int j = 0; j < sss.Count; ++j)
{
sum_angle_in_pratice += sss[j].Angle_in_sec;
}
int closing_angle_in_second_in_theory = sum_angle_in_pratice - sum_angle_in_theory;//

int compensate_angle_in_second = closing_angle_in_second_in_theory / (m - 2);
int residual_angle_in_sec = closing_angle_in_second_in_theory - compensate_angle_in_second * (m - 2);

for (int k=1; k<sss.Count-1;k++ )
{
sss[k].Angle_in_sec -= compensate_angle_in_second;
}
for (int j = 0; j < residual_angle_in_sec;++j )
{
sss[j].Corrected_angle_in_sec = sss[sorted_sss_idx[j]].Angle_in_sec - 1;
}
if (Meamemode == 0)
{
for (int l = 0; l < sss.Count - 1;l++ )
{
sss[l].Azimuth = startAzi_in_second + sss[l].Corrected_angle_in_sec - 180 * 3600;
if (sss[l].Azimuth > 360 * 3600)
{
sss[l].Azimuth = sss[l].Azimuth - 360 * 3600;
}
else if (sss[l].Azimuth < 0 )
{
sss[l].Azimuth = sss[l].Azimuth + 360 * 3600;
}
}
}
else
{
for (int l = 0; l < sss.Count - 1;l++ )
{
sss[l].Azimuth = startAzi_in_second - sss[l].Corrected_angle_in_sec + 180 * 3600;
if (sss[l].Azimuth > 360 * 3600)
{
sss[l].Azimuth = sss[l].Azimuth - 360 * 3600;
}
else if (sss[l].Azimuth < 0)
{
sss[l].Azimuth = sss[l].Azimuth + 360 * 3600;
}
}
}
fs = Math.Sqrt(Math.Pow(fx, 2) + Math.Pow(fy, 2));

for (int p = 1; p < sss.Count - 2; p++)
{
L += sss[p].Sidelength;
}

for (int n = 0; n < sss.Count-1;n ++)
{
sss[n].Delta_X = sss[n].Sidelength * Math.Cos(sss[n].Azimuth);
sss[n].Delta_Y = sss[n].Sidelength * Math.Sin(sss[n].Azimuth);
}
double fx_in_theory = 0;
double fy_in_theory = 0;
fx_in_theory = sss[m - 1].X - sss[1].X;
fy_in_theory = sss[m - 1].Y - sss[1].Y;
double fx_in_practice = 0;
double fy_in_practice = 0;
for (int o = 1; o < sss.Count - 2;o++ )
{
fx_in_practice += sss[o].Delta_X;
fy_in_practice += sss[o].Delta_Y;
}
fx = fx_in_practice - fx_in_theory;
fy = fy_in_practice - fy_in_theory;

for (int q = 1; q < sss.Count - 2;q++ )
{
sss[q].Corrected_Delta_X = sss[q].Delta_X - fx * sss[q].Sidelength / L;
sss[q].Corrected_Delta_Y = sss[q].Delta_Y - fy * sss[q].Sidelength / L;
}

for (int r = 1; r < sss.Count - 2;r++ )
{
sss[r + 1].X = sss[r].X + sss[r].Corrected_Delta_X;
sss[r + 1].Y = sss[r].Y + sss[r].Corrected_Delta_Y;
}
}

return 0;
}

private void Sort_SSS_by_angle()
{
List<SurveyStation> t_sss = new List<SurveyStation>();
t_sss.AddRange(sss);
t_sss.Sort(Angle_sort);
int nCount = sss.Count;
sorted_sss_idx = new int[nCount];
for (int i = 0; i < nCount;++i )
{
sorted_sss_idx[i] = t_sss[i].ID;
}
}


private int Angle_sort(SurveyStation ss1, SurveyStation ss2)
{
if (ss1.Angle_in_sec > ss2.Angle_in_sec)
return 1;
else if (ss1.Angle_in_sec < ss2.Angle_in_sec)
return 0;
else
return -1;
}

private double computeAzi(double x1,double y1, double x2, double y2)
{
int n = sss.Count;
double Azimuth = 0;
int m = (n - 1) / 13;
for (int i = 0; i < m;i++ )
{
Azimuth = sss[i].Azimuth;
}
if ((x2-x1>0)&&(y2-y1>0))
{
Azimuth = Azimuth + 0;
}
else if((x2-x1>0)&&(y2-y1<0))
{
Azimuth = 360.0000 - Azimuth;
}
else if((x2-x1<0)&&(y2-y1>0))
{
Azimuth = 180.0000 - Azimuth;
}
else
{
if ((x2 - x1 < 0) && (y2 - y1 < 0))
{
Azimuth = 180.0000 + Azimuth;
}
}
return 0;
}
}
}
在线等,这个代码哪里出错了。
...全文
728 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,423

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧