-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTLE_Parser.html
More file actions
300 lines (258 loc) · 11.1 KB
/
TLE_Parser.html
File metadata and controls
300 lines (258 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<style>
/* 使用属性选择器避免ID冲突 */
[data-tle-parser] {
position: relative;
margin: 20px 0;
}
[data-tle-parser] .box {
border: 2px solid #2c3e50;
border-radius: 10px;
padding: 25px;
max-width: 600px;
margin: 0 auto;
background-color: #f8f9fa;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
[data-tle-parser] .input-area {
margin-bottom: 20px;
}
[data-tle-parser] textarea {
width: 100%;
height: 120px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-family: 'Courier New', monospace;
font-size: 14px;
resize: vertical;
}
[data-tle-parser] .grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin: 20px 0;
}
[data-tle-parser] .item {
display: flex;
flex-direction: column;
}
[data-tle-parser] .label {
font-weight: bold;
margin-bottom: 5px;
color: #2c3e50;
}
[data-tle-parser] input {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
background-color: white;
font-family: 'Courier New', monospace;
}
[data-tle-parser] .buttons {
text-align: center;
margin-top: 20px;
}
[data-tle-parser] button {
padding: 12px 25px;
margin: 0 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
[data-tle-parser] .parse {
background-color: #3498db;
color: white;
}
[data-tle-parser] .parse:hover {
background-color: #2980b9;
}
[data-tle-parser] .reset {
background-color: #e74c3c;
color: white;
}
[data-tle-parser] .reset:hover {
background-color: #c0392b;
}
[data-tle-parser] .error {
color: #e74c3c;
font-weight: bold;
text-align: center;
margin: 10px 0;
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<div data-tle-parser>
<div class="box">
<h2 style="text-align: center; color: #2c3e50;">TLE轨道要素解析器</h2>
<div class="input-area">
<label>请输入TLE数据(三行格式):</label>
<textarea placeholder="在此粘贴完整的三行TLE数据... 例如: ISS (ZARYA) 1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927 2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537"></textarea>
</div>
<div class="error"></div>
<div class="grid">
<div class="item">
<span class="label">半长轴 a (km):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">离心率 e:</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">轨道倾角 i (度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">轨道倾角 i (弧度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">升交点赤经 Ω (度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">升交点赤经 Ω (弧度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">近地点幅角 ω (度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">近地点幅角 ω (弧度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">真近点角 ν (度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">真近点角 ν (弧度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">平近点角 M (度):</span>
<input type="text" readonly>
</div>
<div class="item">
<span class="label">卫星编号:</span>
<input type="text" readonly>
</div>
</div>
<div class="buttons">
<button class="parse">解析TLE</button>
<button class="reset">重置</button>
</div>
</div>
</div>
<script>
$(document).ready(function () {
// 为每个[data-tle-parser]元素创建独立的解析器
$('[data-tle-parser]').each(function () {
const $container = $(this);
const parserId = 'parser-' + Math.random().toString(36).substr(2, 9);
// 创建封闭的解析器对象
const parser = {
seq: 0,
elements: {},
init: function () {
$container.find('.parse').click(() => this.parse());
$container.find('.reset').click(() => this.reset());
},
parse: function () {
const input = $container.find('textarea').val().trim();
const $error = $container.find('.error');
$error.hide();
if (!input) {
$error.text('请输入TLE数据').show();
return;
}
try {
this.processTLE(input);
} catch (e) {
$error.text('错误: ' + e.message).show();
}
},
reset: function () {
$container.find('textarea').val('');
$container.find('input').val('');
$container.find('.error').hide();
},
processTLE: function (tle) {
const lines = tle.split('\n').filter(l => l.trim());
if (lines.length < 3) throw new Error('需要三行TLE数据');
const line0 = lines[0].trim();
const line1 = lines[1].trim();
const line2 = lines[2].trim();
if (!line1.startsWith('1 ') || !line2.startsWith('2 ')) {
throw new Error('TLE格式不正确');
}
// 解析完整的TLE数据
const satId = parseInt(line1.substring(2, 7));
// 第二行数据
const inclination = parseFloat(line2.substring(8, 16)); // 轨道倾角 i
const raan = parseFloat(line2.substring(17, 25)); // 升交点赤经 Ω
const eccentricityStr = line2.substring(26, 33);
const eccentricity = parseFloat("0." + eccentricityStr); // 离心率 e
const argPerigee = parseFloat(line2.substring(34, 42)); // 近地点幅角 ω
const meanAnomaly = parseFloat(line2.substring(43, 51)); // 平近点角 M
const meanMotion = parseFloat(line2.substring(52, 63)); // 平均运动
// 计算半长轴 a
const muEarth = 3.986004418E+14; // 地球引力常数 (m³/s²)
const n = meanMotion * 2 * Math.PI / 86400; // 平均运动 (rad/s)
const semiMajorAxis = Math.pow(muEarth / (n * n), 1/3) / 1000; // 半长轴 (km)
// 角度转换为弧度
const inclinationRad = inclination * Math.PI / 180;
const raanRad = raan * Math.PI / 180;
const argPerigeeRad = argPerigee * Math.PI / 180;
const meanAnomalyRad = meanAnomaly * Math.PI / 180;
// 使用牛顿-拉弗森法求解偏近点角 E
let E = meanAnomalyRad; // 初始猜测值
const tolerance = 1e-8;
const maxIterations = 100;
for (let iteration = 0; iteration < maxIterations; iteration++) {
const f = E - eccentricity * Math.sin(E) - meanAnomalyRad;
if (Math.abs(f) <= tolerance) break;
const df = 1 - eccentricity * Math.cos(E);
E = E - f / df;
}
// 计算真近点角 ν
const trueAnomalyRad = 2 * Math.atan(Math.sqrt((1 + eccentricity) / (1 - eccentricity)) * Math.tan(E / 2));
const trueAnomalyDeg = trueAnomalyRad * 180 / Math.PI;
// 更新显示 - 完整的轨道六根数
const inputs = $container.find('input');
inputs.eq(0).val(semiMajorAxis.toFixed(3)); // a (km)
inputs.eq(1).val(eccentricity.toFixed(7)); // e
inputs.eq(2).val(inclination.toFixed(4)); // i (度)
inputs.eq(3).val(inclinationRad.toFixed(6)); // i (弧度)
inputs.eq(4).val(raan.toFixed(4)); // Ω (度)
inputs.eq(5).val(raanRad.toFixed(6)); // Ω (弧度)
inputs.eq(6).val(argPerigee.toFixed(4)); // ω (度)
inputs.eq(7).val(argPerigeeRad.toFixed(6)); // ω (弧度)
inputs.eq(8).val(trueAnomalyDeg.toFixed(4)); // ν (度)
inputs.eq(9).val(trueAnomalyRad.toFixed(6)); // ν (弧度)
inputs.eq(10).val(meanAnomaly.toFixed(4)); // M (度)
inputs.eq(11).val(satId); // 卫星编号
// 存储轨道六根数到该实例的独立变量中
const elementId = (++this.seq).toString();
this.elements[elementId] = {
semiMajorAxis: semiMajorAxis, // a (km)
eccentricity: eccentricity, // e
inclination: inclinationRad, // i (弧度)
raan: raanRad, // Ω (弧度)
argPerigee: argPerigeeRad, // ω (弧度)
trueAnomaly: trueAnomalyRad // ν (弧度)
};
console.log(`${parserId} 解析完成,元素ID: ${elementId}`);
console.log(`${parserId} 轨道六根数:`, this.elements[elementId]);
}
};
parser.init();
});
});
</script>