def eci2geodetic(x, y, z, gmst=None, ellipsoid=None): """Converts the given ECI coordinates to Geodetic coordinates at the given Greenwich Mean Sidereal Time (GMST) (defaults to now) and with the given ellipsoid (defaults to WGS84). This code was adapted from `shashwatak/satellite-js <https://github.com/shashwatak/satellite-js/blob/master/src/coordinate-transforms.js>`_ and http://www.celestrak.com/columns/v02n03/ """ if gmst is None: gmst = dmc.toGMST() if ellipsoid is None: ellipsoid = WGS84 a = WGS84.a f = WGS84.f r = math.sqrt((x * x) + (y * y)) e2 = (2 * f) - (f * f) lon = math.atan2(y, x) - gmst k = 0 kmax = 20 lat = math.atan2(z, r) while k < kmax: slat = math.sin(lat) C = 1 / math.sqrt(1 - e2 * (slat * slat)) # noqa lat = math.atan2(z + (a * C * e2 * slat), r) k += 1 z = (r / math.cos(lat)) - (a * C) return lat, lon, z
def test_eci2ecef(): eci = -6.0744*1e6, -1.8289*1e6, 0.6685*1e6 t = datetime.datetime(2010, 1, 17, 10, 20, 36) gmst = dmc.toGMST(t) ecef = coord.eci2ecef(eci[0], eci[1], eci[2], gmst=gmst) assert float_equality(ecef[0], 1628340.306018) assert float_equality(ecef[1], -6131208.5609442) assert float_equality(ecef[2], 668500.0)
def test_eci2geodetic(): eci = -6.0744*1e6, -1.8289*1e6, 0.6685*1e6 t = datetime.datetime(2010, 1, 17, 10, 20, 36) gmst = dmc.toGMST(t) lla = list(coord.eci2geodetic(eci[0], eci[1], eci[2], gmst=gmst)) lla[0] = math.fmod(lla[0], math.pi * 2) lla[1] = math.fmod(lla[1], math.pi * 2) assert float_equality(math.degrees(lla[0]), 6.0558200) assert float_equality(math.degrees(lla[1]), -75.1266047) assert float_equality(lla[2], 978.4703290)
def eci2ecef(x, y, z, gmst=None): """Converts the given ECI coordinates to ECEF at the given Greenwich Mean Sidereal Time (GMST) (defaults to now). This code was adapted from `shashwatak/satellite-js <https://github.com/shashwatak/satellite-js/blob/master/src/coordinate-transforms.js>`_ and http://ccar.colorado.edu/ASEN5070/handouts/coordsys.doc """ if gmst is None: gmst = dmc.toGMST() X = (x * math.cos(gmst)) + (y * math.sin(gmst)) # noqa Y = (x * (-math.sin(gmst))) + (y * math.cos(gmst)) # noqa Z = z # noqa return X, Y, Z