【发布时间】:2017-08-07 18:02:40
【问题描述】:
我正在编写一个计算开普勒元素的程序。主函数获取2行tle,返回对象kep,其属性为卫星轨道参数。我必须在文本框中显示这些参数,但我不明白我应该怎么做。 任何帮助都会得到帮助:) form1.cs:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void inputtext_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void retrieveInput_Click(object sender, EventArgs e)
{
String line1 = line1String.Text;
String line2 = line2String.Text;
//what happens after the recieving of the strings is the calculation and displating the kep properties in textbox "ShowBox"
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
}
我的kepelments课:
class KepElements
{
public double raan { get; set; }
public double argperi { get; set; }
public double meanan { get; set; }
public double meanmotion { get; set; }
public double eccentricity { get; set; }
public double bstar { get; set; }
public double epochYear { get; set; }
public double inclination { get; set; }
public double epochDay { get; set; }
}
和主程序:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
//function that gets 2 strings and calculates all elemnts
public static KepElements calculating(String line1, String line2)
{
double raan, argperi, meanan, meanmotion, eccentricity, bstar, epochYear, inclination, SepochDay, sec, epochDay;
int CurrentSec, sec2, sec3;
KepElements kep = new KepElements();
//setting eccentricity
eccentricity = Convert.ToDouble(line2.Substring(28, 7));
kep.eccentricity = eccentricity;
//setting the bstar
bstar = Convert.ToDouble(line2.Substring(55, 8));
kep.bstar = bstar;
//setting the epochYear
epochYear = Convert.ToDouble(line2.Substring(20, 2));
kep.epochYear = epochYear;
//calculating the EpochDay
SepochDay = Convert.ToDouble(line2.Substring(22, 12));
sec = ((SepochDay - Math.Truncate(SepochDay)) * 100000000); //the time of seconds (after the decimal point)
sec3 = (int)sec;
sec2 = (int)SepochDay;
sec2 = sec2 * 86400;//sec2 is now the number of sec in a day*number of days since beggining of the current year
CurrentSec = (DateTime.Now.Year - 1970) * 31556926;
epochDay = CurrentSec + sec + sec2;
kep.epochDay = epochDay;
//calculating the inclination
inclination = Convert.ToDouble(line2.Substring(10, 8));
inclination = (inclination / 180) * Math.PI;
kep.inclination = inclination;
//calculating the meananomaly
meanan = Convert.ToDouble(line2.Substring(45, 8));
meanan = (meanan / 180) * Math.PI;
kep.meanan = meanan;
//calculating the argue of perigee
argperi = Convert.ToDouble(line2.Substring(36, 8));
argperi = (argperi / 180) * Math.PI;
kep.argperi = argperi;
//calculating the mean motion
meanmotion = Convert.ToDouble(line2.Substring(54, 11));
meanmotion = (meanmotion / 1440) * Math.PI * 2;
kep.meanmotion = meanmotion;
//calculating the raan
raan = Convert.ToDouble(line2.Substring(19, 8));
raan = (raan / 180) * Math.PI;
kep.raan = raan;
return kep;
}
}
【问题讨论】:
-
添加代码将帮助我们了解您在做什么,并让我们进一步帮助您。
-
应该如何创建kep对象?当用户点击一个按钮?您的表单至少必须在某处声明 kep 对象,以便您可以引用它。
-
@LarsTech 好的,我更正了我的代码。现在该函数是无效的,并且该对象在主函数中声明。但我仍然无法从 Form1.cs 中引用它。
-
如果您更正了您的代码,您并未与我们分享。