题目要求
下面给出的是GPS号卫星在某年某月某日某时的广播星历数据,请根据该广播星历数据计算出某年某月某日某时某分时刻的卫星在地固系中的位置。
注意事项
- 根据大家的私信和反馈,大多数人拿到代码之后直接打开星历文件打不开,可能是不太懂C#代码,在此说明,这里要用的广播星历数据只能是某一卫星某一时刻的一份数据,要单独从星历文件中复制到一个text文本中,并且保证每两个数据间有空格或Tab,并把所有的D通过text文本的替换功能换成e。具体格式如上图。
- 很多同学在评论区问我要百度网盘链接,根据CSDN的要求,我在评论区没法发链接,发了过不了审核,可以关注收藏点赞私信我,我会在私信发链接。
代码演示
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 广播星历计算卫星位置
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double[] M = new double[40];
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.Title = "Selete a File";
pOpenFileDialog.FileName = "";
pOpenFileDialog.Filter = "Text File(*.txt)|*.txt";
if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
{
StreamReader read = new StreamReader(pOpenFileDialog.FileName);
string infor1 = read.ReadToEnd();
read.Close();
string mystring = infor1;
string infor = mystring;
string[] split = new string[] { " " };
string[] arrs = infor.Split(split, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < arrs.Length; i++)
{
M[i] = double.Parse(arrs[i]);
textBox1.Text += arrs[i] + " ";
}
}
}
private void button2_Click(object sender, EventArgs e)
{
//计算时间
double t, ty, tmon, td, th, tmin, ts;
ty = (double.Parse(textBox2.Text) - M[1]) * 86400 * 30.6001 * 365.25;
tmon = (double.Parse(textBox3.Text) - M[2]) * 86400 * 30.6001;
td = (double.Parse(textBox4.Text) - M[3]) * 86400;
th = (double.Parse(textBox5.Text) - M[4]) * 3600;
tmin = (double.Parse(textBox6.Text) - M[5]) * 60;
ts = (double.Parse(textBox7.Text) - M[6]);
t = M[18] + ty + tmon + td + th + tmin + ts;
//计算卫星平均角速度
double n, n0;
double GM = 3986004.418e008, a;
a = Math.Pow(M[17], 2);
n0 = Math.Sqrt(GM / (a * a * a));
n = n0 + M[12];
//计算平近点角
double Mk;
Mk = M[13] + n * (t - M[18]);
//计算偏近点角
double Ek, Ek1;
Ek = Mk;
Ek1 = Ek + M[15] * Math.Sin(Ek);
do
{
Ek = Ek1;
Ek1 = Mk + M[15] * Math.Sin(Ek);
}
while (Math.Abs(Ek1 - Ek) > 1.0e-12);
//计算真近点角
double Vk;
Vk = Math.Atan(((Math.Sqrt(1 - M[15] * M[15])) * Math.Sin(Ek)) / (Math.Cos(Ek) - M[15]));
//计算升交角距
double ok;
ok = Vk + M[24];
//计算摄动改正项
double ou, or, oi;
ou = M[14] * Math.Cos(2 * ok) + M[16] * Math.Sin(2 * ok);
or = M[23] * Math.Cos(2 * ok) + M[11] * Math.Sin(2 * ok);
oi = M[19] * Math.Cos(2 * ok) + M[21] * Math.Sin(2 * ok);
//改正
double uk, rk, ik;
uk = ok + ou;
rk = a * (1 - M[15] * Math.Cos(Ek)) + or;
ik = M[22] + oi + M[26] * (t - M[18]);
//计算卫星在升交点轨道直角坐标系的坐标
double xk, yk;
xk = rk * Math.Cos(uk);
yk = rk * Math.Sin(uk);
//计算升交点经度
double xt, we = 7.2921151467e-005;
xt = M[20] + (M[25] - we) * (t - M[18]) - we * M[18];
//计算卫星在地固坐标系中的空间直角坐标
double X, Y, Z;
X = xk * Math.Cos(xt) - yk * Math.Cos(ik) * Math.Sin(xt);
Y= xk * Math.Sin(xt) + yk * Math.Cos(ik) * Math.Cos(xt);
Z = yk * Math.Sin(ik);
ListViewItem li = new ListViewItem();
string T;
T = textBox2.Text + "年" + textBox3.Text + "月" + textBox4.Text + "日" + textBox5.Text + "时" + textBox6.Text + "分" + textBox7.Text + "秒";
li.Text = T.ToString();
li.SubItems.Add(X.ToString("f3"));
li.SubItems.Add(Y.ToString("f3"));
li.SubItems.Add(Z.ToString("f3"));
listView1.Items.Add(li);
}
}
}
结果演示
代码分享
链接: CSDN链接
https://download.csdn.net/download/QY1021371614/85092594
如果不能下载请私信博主,博主会尽量第一时间回复