eciToGeodetic function
Implementation
Map<String, dynamic> eciToGeodetic(Map<String, dynamic> eci, gmst) {
// http://www.celestrak.com/columns/v02n03/
final a = 6378.137;
final b = 6356.7523142;
final R = Math.sqrt((eci['x'] * eci['x']) + (eci['y'] * eci['y']));
final f = (a - b) / a;
final e2 = ((2 * f) - (f * f));
var longitude = Math.atan2(eci['y'], eci['x']) - gmst;
while (longitude < -pi) {
longitude += twoPi;
}
while (longitude > pi) {
longitude -= twoPi;
}
final kmax = 20;
var k = 0;
var latitude = Math.atan2(
eci['z'],
Math.sqrt((eci['x'] * eci['x']) + (eci['y'] * eci['y'])),
);
var C;
while (k < kmax) {
C = 1 / Math.sqrt(1 - (e2 * (Math.sin(latitude) * Math.sin(latitude))));
latitude = Math.atan2(eci['z'] + (a * C * e2 * Math.sin(latitude)), R);
k += 1;
}
final height = (R / Math.cos(latitude)) - (a * C);
return { 'longitude': longitude, 'latitude': latitude, 'height': height };
}