-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathSatellite_Orbit_Visualization_in_3D_with_TLE_Data.cpp
134 lines (113 loc) · 3.73 KB
/
Satellite_Orbit_Visualization_in_3D_with_TLE_Data.cpp
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <GL/glut.h>
#include <OrekitHeaders.hpp>
using namespace std;
using namespace Orekit;
// Define satellite data struct
struct SatelliteData {
string name;
string line1;
string line2;
float color[3];
};
vector<SatelliteData> satelliteDataList;
void readTLEData(const string& tleFile) {
ifstream file(tleFile);
string line;
while (getline(file, line)) {
SatelliteData satelliteData;
satelliteData.name = line;
getline(file, satelliteData.line1);
getline(file, satelliteData.line2);
satelliteData.color[0] = 0.0f; // Set default color to black
satelliteData.color[1] = 0.0f;
satelliteData.color[2] = 0.0f;
satelliteDataList.push_back(satelliteData);
}
file.close();
}
void drawSphere(GLfloat radius, GLint slices, GLint stacks) {
GLUquadricObj* quadric = gluNewQuadric();
gluSphere(quadric, radius, slices, stacks);
gluDeleteQuadric(quadric);
}
void drawCylinder(GLfloat base, GLfloat top, GLfloat height, GLint slices, GLint stacks) {
GLUquadricObj* quadric = gluNewQuadric();
gluCylinder(quadric, base, top, height, slices, stacks);
gluDeleteQuadric(quadric);
}
void renderScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Draw Earth
glColor3f(0.0f, 0.0f, 1.0f);
drawSphere(1.0f, 32, 32);
// Draw satellite paths
for (const SatelliteData& satelliteData : satelliteDataList) {
glColor3fv(satelliteData.color);
stringstream line1Stream(satelliteData.line1);
stringstream line2Stream(satelliteData.line2);
TLE tle("", line1Stream.str(), line2Stream.str());
Orbit orbit = tle.getOrbit();
double t = 0.0;
double dt = 5.0;
glBegin(GL_LINE_STRIP);
for (int i = 0; i < 72; i++) {
AbsoluteDate date = AbsoluteDate::J2000_EPOCH().shiftedBy(t);
PVCoordinates pvCoordinates = orbit.getPVCoordinates(date);
double x = pvCoordinates.getPosition().getX() / 1000.0;
double y = pvCoordinates.getPosition().getY() / 1000.0;
double z = pvCoordinates.getPosition().getZ() / 1000.0;
glVertex3d(x, y, z);
t += dt;
}
glEnd();
}
glFlush();
glutSwapBuffers();
}
void reshape(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)width / height, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
}
void initGL() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
int main(int argc, char** argv) {
// Initialize Orekit
try {
string orekitData = "<PATH_TO_OREKIT_DATA>"; // Set the path to Orekit data
Orekit::init(orekitData);
} catch (exception& e) {
cerr << "Failed to initialize Orekit: " << e.what() << endl;
return 1;
}
// Read TLE data from a file
string tleFile = "tle_data.txt"; // Path to the TLE file
readTLEData(tleFile);
// Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("Satellite Orbits");
// Set GLUT callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(reshape);
// Initialize OpenGL
initGL();
// Start the main GLUT loop
glutMainLoop();
return 0;
}