Skip to content

Commit

Permalink
ECI to Geodetic conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
xclud committed Feb 7, 2024
1 parent a591599 commit be5b6d5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [2.0.0]

* ECI to Geodetic conversion.

## [2.0.0]

* Introduce Angle class.

## [1.0.3]
Expand Down
40 changes: 40 additions & 0 deletions lib/src/eci.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,44 @@ class EarthCenteredInertial {
EarthCenteredEarthFixed toEcfByDateTime(DateTime utc) {
return toEcf(utc.toUtc().gsmt);
}

LatLngAlt toGeodetic(Planet planet, double gmst) {
// http://www.celestrak.com/columns/v02n03/
final a = planet.radius;
final f = planet.flattening;
final e2 = (2 * f) - (f * f);

final R = sqrt((x * x) + (y * y));

var longitude = atan2(y, x) - gmst;
while (longitude < -pi) {
longitude += pi * 2;
}
while (longitude > pi) {
longitude -= pi * 2;
}

const int kmax = 20;
var k = 0;
var latitude = atan2(z, sqrt((x * x) + (y * y)));
var C = 1.0;
while (k < kmax) {
C = 1 / sqrt(1 - (e2 * (sin(latitude) * sin(latitude))));
latitude = atan2(z + (a * C * e2 * sin(latitude)), R);
k += 1;
}

final height = (R / cos(latitude)) - (a * C);

return LatLngAlt(
Angle.radian(latitude),
Angle.radian(longitude),
height,
);
}

LatLngAlt toGeodeticByDateTime(Planet planet, DateTime utc) {
final gmst = Julian.fromDateTime(utc).toGmst();
return toGeodetic(planet, gmst);
}
}
2 changes: 1 addition & 1 deletion lib/src/look_angle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class LookAngle {

@override
String toString() {
return 'Azimuth: ${azimuth.degrees}°, Elevation: ${elevation.degrees}°, Range: ${range}';
return 'Azimuth: ${azimuth.degrees}°, Elevation: ${elevation.degrees}°, Range: $range';
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: latlng
description: GeoJSON, Geodesy and Geographical calculations for Dart. Provides LatLong and Mercator projection (EPSG4326).
version: 2.0.0
version: 2.0.1
repository: https://github.com/xclud/dart_latlng
homepage: https://pwa.ir

Expand Down

0 comments on commit be5b6d5

Please sign in to comment.