Skip to content

Commit 753d1dd

Browse files
author
reed
committed
cleaned up code and expanded Passes and EpochTime
1 parent 2386aeb commit 753d1dd

19 files changed

+295
-81
lines changed

OneSGP4_Example/Program.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ static void Main(string[] args)
1010
{
1111
//Parse three line element
1212
Tle tleISS = ParserTLE.parseTle(
13-
"1 25544U 98067A 19097.23063721 -.00000469 00000-0 00000+0 0 9999",
14-
"2 25544 51.6449 353.9503 0002279 151.1697 290.4275 15.52495932164239",
13+
"1 25544U 98067A 19132.30925117 .00001081 00000-0 24694-4 0 9993",
14+
"2 25544 51.6426 179.4820 0001363 344.4861 92.2261 15.52657683169680",
1515
"ISS 1");
1616

1717
//Parse tle from file
@@ -32,9 +32,21 @@ static void Main(string[] args)
3232

3333
//Create Time points
3434
EpochTime startTime = new EpochTime(DateTime.UtcNow);
35-
EpochTime anotherTime = new EpochTime(2018, 100.5); //(Year 2017, 100 day at 12:00 HH)
35+
EpochTime anotherTime = new EpochTime(2018, 100.5); //(Year 2018, 100 day at 12:00 HH)
3636
EpochTime stopTime = new EpochTime(DateTime.UtcNow.AddHours(1));
3737

38+
//get time difference
39+
double daysSince = startTime - anotherTime;
40+
//throws exception if first time > second time
41+
//double daysSince = anotherTime - startTime;
42+
43+
//compare Time points
44+
EpochTime compareTime = new EpochTime(2018, 100.5); //(Year 2018, 100 day at 12:00 HH)
45+
bool equals = anotherTime == compareTime;
46+
bool notequals = startTime != anotherTime;
47+
bool greater = startTime > anotherTime;
48+
bool smaler = anotherTime < startTime;
49+
3850
//Add 15 Seconds to EpochTime
3951
anotherTime.addTick(15);
4052
//Add 20 Min to EpochTime
@@ -54,7 +66,7 @@ static void Main(string[] args)
5466
resultDataList = sgp4Propagator.getRestults();
5567

5668
//Coordinate of an observer on Ground lat, long, height(in meters)
57-
One_Sgp4.Coordinate observer = new Coordinate(35.554595, 18.888574, 0);
69+
One_Sgp4.Coordinate observer = new Coordinate(35.00, 18.0, 0);
5870
//Convert to ECI coordinate system
5971
One_Sgp4.Point3d eci = observer.toECI(startTime.getLocalSiderealTime());
6072
//Get Local SiderealTime for Observer
@@ -75,6 +87,7 @@ static void Main(string[] args)
7587
{
7688
Console.Out.WriteLine(p.ToString());
7789
}
90+
Console.Out.WriteLine("Done");
7891
}
7992
}
8093
}

One_Sgp4/Pass.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

One_Sgp4/SatFunctions.cs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ public class SatFunctions
3939
public const double twoPi = pi * 2.0; //!< double constant two Pi
4040
public const double toDegrees = 180.0 / pi; //!< double constant conversion to degree
4141
public const double toRadians = pi / 180.0; //!< double constant converstion to radians
42-
43-
private const double a_Wgs72 = 6378.135; //!< double WGS72 const in Km
44-
private const double a_Wgs84 = 6378.137; //!< double WGS84 const in Km
4542

4643

4744
//! Ground constructor.
@@ -124,7 +121,6 @@ public static bool isSatVisible(Coordinate coordinate,
124121
public static Point3d calcSphericalCoordinate(Coordinate coordinate,
125122
EpochTime time, Sgp4Data satPosData)
126123
{
127-
128124
double lsr = time.getLocalSiderealTime(coordinate.getLongitude());
129125

130126
Point3d groundLocation = coordinate.toECI(lsr);
@@ -146,21 +142,11 @@ public static Point3d calcSphericalCoordinate(Coordinate coordinate,
146142
double re = -sin_theta * r.x + cos_theta * r.y;
147143
double rz = cos_lat * cos_theta * r.x + cos_lat * sin_theta * r.y + sin_lat * r.z;
148144

149-
result.x = Math.Sqrt(rs * rs + re * re + rz * rz);
150-
result.y = Math.Atan2(-re , rs);
145+
result.x = Math.Sqrt((rs * rs) + (re * re) + (rz * rz));
146+
result.y = AcTan(-re , rs);
151147
result.z = Math.Asin(rz / result.x);
152148

153-
/*
154-
if (rs > 0.0)
155-
{
156-
result.y += pi/2;
157-
}
158-
if (result.y < 0.0)
159-
{
160-
result.y += pi;
161-
}*/
162-
result.y += pi;
163-
result.y = result.y * toDegrees;
149+
result.y = (result.y + pi) * toDegrees;
164150
result.z = result.z * toDegrees;
165151

166152
return result;
@@ -261,39 +247,63 @@ public static Coordinate calcSatSubPoint(EpochTime time, Sgp4Data satPosData,
261247
return new Coordinate(latitude, longitude, height);
262248
}
263249

250+
//! Calculate satellite position at a single point in time
251+
/*!
252+
\param tle of satellite
253+
\param EpochTime to calculate position
254+
\param int WGS-Data to use 0 = WGS_72; 1 = WGS_84
255+
\return SGP4Data containing satellite position data
256+
*/
264257
public static Sgp4Data getSatPositionAtTime(Tle satellite, EpochTime atTime, Sgp4.wgsConstant wgs)
265258
{
266259
Sgp4 sgp4Propagator = new Sgp4(satellite, wgs);
267260
sgp4Propagator.runSgp4Cal(atTime, atTime, 1 / 60.0);
268261
return sgp4Propagator.getRestults()[0];
269262
}
270263

271-
264+
//! Calculate Passes of a satellite for ceratin number of days from a starting time
265+
/*!
266+
\param Coordinate position of observer
267+
\param Tle satellite data
268+
\param EpochTime of startpoint
269+
\param int accuracy time between calculations default 15 seconds
270+
\param int number of days to calculate default 5 days
271+
\param int WGS-Data to use 0 = WGS_72; 1 = WGS_84 default WGS 84
272+
\return List<Pass> List of passes satellite is visible
273+
*/
272274
public static List<Pass> CalculatePasses(Coordinate position, Tle satellite, EpochTime startTime, int accuracy = 15,
273275
int maxNumberOfDays = 5, Sgp4.wgsConstant wgs = Sgp4.wgsConstant.WGS_84)
274276
{
275277
List<Pass> results = new List<Pass>();
276278
EpochTime epoch = new EpochTime(startTime);
277279
EpochTime end = new EpochTime(startTime);
278280
end.addDays(maxNumberOfDays);
281+
279282
while (epoch < end)
280283
{
281284
Sgp4Data satPos = getSatPositionAtTime(satellite, epoch, wgs);
282285
if (SatFunctions.isSatVisible(position, 0.0, epoch, satPos))
283286
{
284-
EpochTime passStart = new EpochTime(epoch);
285287
Point3d spherical = SatFunctions.calcSphericalCoordinate(position, epoch, satPos);
286-
double maxElevation = spherical.z;
288+
PassDetail startDetails = new PassDetail(new EpochTime(epoch), spherical.z, spherical.y, spherical.x);
289+
PassDetail maxEleDetails = new PassDetail(new EpochTime(epoch), spherical.z, spherical.y, spherical.x);
290+
//double maxElevation = spherical.z;
287291
epoch.addTick(accuracy);
288292
satPos = getSatPositionAtTime(satellite, epoch, wgs);
289-
while (SatFunctions.isSatVisible(position, 0.0, epoch, satPos))
293+
while(spherical.z >= 0)
294+
//while (SatFunctions.isSatVisible(position, 0.0, epoch, satPos))
290295
{
296+
291297
spherical = SatFunctions.calcSphericalCoordinate(position, epoch, satPos);
292-
if (maxElevation < spherical.z)
293-
maxElevation = spherical.z;
298+
if (maxEleDetails.elevation < spherical.z)
299+
{
300+
maxEleDetails = new PassDetail(new EpochTime(epoch), spherical.z, spherical.y, spherical.x);
301+
}
294302
epoch.addTick(accuracy);
303+
satPos = getSatPositionAtTime(satellite, epoch, wgs);
295304
}
296-
results.Add(new One_Sgp4.Pass(position, passStart, new EpochTime(epoch), maxElevation * 180.0 / pi));
305+
PassDetail endDetails = new PassDetail(new EpochTime(epoch), spherical.z, spherical.y, spherical.x);
306+
results.Add(new One_Sgp4.Pass(position, startDetails, maxEleDetails, endDetails));
297307
}
298308
epoch.addTick(accuracy);
299309
}

One_Sgp4/Coordinate.cs renamed to One_Sgp4/ground/Coordinate.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public class Coordinate
3737
private double longitude; //!< double longitude in degree
3838
private double height; //!< double height in meters
3939

40-
private const double a_Wgs72 = 6378.135; //!< double WGS72 const in Km
41-
private const double a_Wgs84 = 6378.137; //!< double WGS84 const in Km
42-
private const double f = 1.0 / 298.26;
43-
4440
//! GeoCoordinate constructor.
4541
/*!
4642
\param double latetude
@@ -97,21 +93,29 @@ public double getHeight()
9793
//! Convert to ECI
9894
/*!
9995
\param double SidrealTime
96+
\param WGSconstant default WGS_84
10097
\return point3D ECI-Position vector of the Coordinate
10198
*/
102-
public Point3d toECI(double siderealTime)
99+
public Point3d toECI(double siderealTime, Sgp4.wgsConstant wgs = Sgp4.wgsConstant.WGS_84)
103100
{
101+
double f = WGS_72.f;
102+
double a = WGS_72.radiusEarthKM;
103+
if (wgs == Sgp4.wgsConstant.WGS_84)
104+
{
105+
f = WGS_84.f;
106+
a = WGS_84.radiusEarthKM;
107+
}
104108
double srt = siderealTime + (toRadians * longitude);
105109
double lat_rad = toRadians * latetude;
106110
Point3d eciPos = new Point3d();
107-
111+
//oblate earth
108112
double c = 1.0 / (Math.Sqrt(1.0 + f * (f - 2.0) *
109113
(Math.Sin(lat_rad) * Math.Sin(lat_rad))));
110114

111115
double s = (1.0 - f) * (1.0 - f) * c;
112-
eciPos.x = a_Wgs72 * c * Math.Cos(lat_rad) * Math.Cos(srt);
113-
eciPos.y = a_Wgs72 * c * Math.Cos(lat_rad) * Math.Sin(srt);
114-
eciPos.z = a_Wgs72 * s * Math.Sin(lat_rad);
116+
eciPos.x = a * c * Math.Cos(lat_rad) * Math.Cos(srt);
117+
eciPos.y = a * c * Math.Cos(lat_rad) * Math.Sin(srt);
118+
eciPos.z = a * s * Math.Sin(lat_rad);
115119

116120
return eciPos;
117121
}

One_Sgp4/ground/Pass.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2018 Nikolai Reed <reed@1manprojects.de>
3+
*
4+
* Licensed under the The MIT License (MIT)
5+
* You may obtain a copy of the License at
6+
*
7+
* https://tldrlegal.com/license/mit-license#summary
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
11+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
13+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
14+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
15+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
16+
* OTHER DEALINGS IN THE SOFTWARE.
17+
*/
18+
namespace One_Sgp4
19+
{
20+
public class Pass
21+
{
22+
private Coordinate observer; //!< Coordinates of observer
23+
private PassDetail start; //!< Pass details at start of pass
24+
private PassDetail maxElevation; //!< Pass details at max elevation
25+
private PassDetail end; //!< Pass details at end of pass
26+
27+
//! Constructor
28+
/*!
29+
\param Coordinate of observer
30+
\param PassDetail at start of pass
31+
\param PassDetail at max elevation
32+
\param PassDetail at end of pass
33+
*/
34+
public Pass(Coordinate Observer, PassDetail passStart, PassDetail maxElevation, PassDetail passEnd)
35+
{
36+
this.observer = Observer;
37+
this.start = passStart;
38+
this.end = passEnd;
39+
this.maxElevation = maxElevation;
40+
}
41+
42+
//! get Coorindates of observer
43+
/*!
44+
\return Coordinate
45+
*/
46+
public Coordinate getObserverLocation()
47+
{
48+
return this.observer;
49+
}
50+
51+
//! get the EpochTime at start of the pass
52+
/*!
53+
\return EpochTime
54+
*/
55+
public EpochTime getStartEpoch()
56+
{
57+
return this.start.time;
58+
}
59+
60+
//! get the EpochTime at end
61+
/*!
62+
\return EpochTime
63+
*/
64+
public EpochTime getEndEpoch()
65+
{
66+
return this.end.time;
67+
}
68+
69+
//! get PassDetails at start
70+
/*!
71+
\return PassDetail
72+
*/
73+
public PassDetail getPassDetailsAtStart()
74+
{
75+
return this.start;
76+
}
77+
78+
//! get PassDetail at end
79+
/*!
80+
\return PassDetail
81+
*/
82+
public PassDetail getPassDetailsAtEnd()
83+
{
84+
return this.end;
85+
}
86+
87+
//! get PassDetails at max elevation
88+
/*!
89+
\return PassDetail
90+
*/
91+
public PassDetail getPassDetailOfMaxElevation()
92+
{
93+
return this.maxElevation;
94+
}
95+
96+
//! overriden ToString()
97+
/*!
98+
\return String
99+
*/
100+
public override string ToString()
101+
{
102+
return string.Format("{0}:\nStart: {1}\nMax Elevation: {2}\nEnd: {3}", start.time.getDateToString(), start.ToString(), maxElevation.ToString(), end.ToString());
103+
}
104+
}
105+
}

One_Sgp4/ground/PassDetail.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace One_Sgp4
6+
{
7+
/**
8+
* \brief PassDetail class
9+
*
10+
* This class holds more detailed information over elevation, azimuth for a satellite pass
11+
*/
12+
public class PassDetail
13+
{
14+
public EpochTime time; //!< EpochTime timepoint
15+
public double elevation;//!< double elevation at timepoint in degrees
16+
public double azimuth; //!< double azimuth at timepoint in degrees
17+
public double range; //!< double range to satellite in km
18+
19+
//! Constructor
20+
/*!
21+
\param EpochTime timepoint
22+
\param double elevation at timepoint
23+
\param double azimuth at timepoint
24+
\pram double range at timepoint
25+
*/
26+
public PassDetail(EpochTime timepoint, double elevation, double azimuth, double range)
27+
{
28+
this.time = timepoint;
29+
this.elevation = elevation;
30+
this.azimuth = azimuth;
31+
this.range = range;
32+
}
33+
34+
override
35+
public String ToString()
36+
{
37+
return string.Format("{0} : Elevation: {1}°, Azimuth {2}°, Range {3}km ",time.getTimeToString(), elevation, azimuth, range);
38+
}
39+
}
40+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)