Skip to content

Commit

Permalink
Adds ground track (Footprint) calculations.
Browse files Browse the repository at this point in the history
  • Loading branch information
xclud committed Feb 8, 2024
1 parent e2d8c74 commit 0457d76
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.2]

* Adds ground track (Footprint) calculations.

## [2.0.1]

* ECI to Geodetic conversion.
Expand Down
11 changes: 11 additions & 0 deletions example/bin/example.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import 'package:example/example.dart' as example;
import 'package:latlng/latlng.dart';

void main(List<String> arguments) {
final gt = wgs84.getGroundTrack(
LatLngAlt(
Angle.degree(10),
Angle.degree(10),
500,
),
);

print(gt);

print('Hello world: ${example.calculate()}!');
}
30 changes: 19 additions & 11 deletions lib/src/planet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ abstract class Planet {
/// Flattening of the planet.
final double flattening;

/// Gets a polygon on the surface of the planet where a viewer can see.
/// Gets a polygon on the surface of the planet where a [satellite] or flying object can see.
///
/// [satellite] Altitude must be in Kilometers and positive (altitude > 0).
List<LatLng> getGroundTrack(
LatLngAlt satellite, {
double precesion = 1,
Expand All @@ -39,24 +41,30 @@ abstract class Planet {

final latitude = satellite.latitude.radians;
final longitude = satellite.longitude.radians;
final altitude = satellite.altitude;
final temp = satellite.altitude;

if (temp <= 0) {
throw Exception('Altitude must be higher then 0 ($temp).');
}

final altitude = radius + temp;

final cosLat = cos(latitude);
final sinLat = sin(latitude);

double num4 = acos(radius / altitude);
if (num4.isNaN) {
num4 = 0.0;
double asocAlt = acos(radius / altitude);
if (asocAlt.isNaN) {
asocAlt = 0.0;
}
final cosNum4 = cos(num4);
final sinNum4 = sin(num4);
final cosAlt = cos(asocAlt);
final sinAlt = sin(asocAlt);
int i = 0;
do {
final angle = pi / 180.0 * i;
final lat = asin(sinLat * cosNum4 + cos(angle) * sinNum4 * cosLat);
final num9 = (cosNum4 - sinLat * sin(lat)) / (cosLat * cos(lat));
final lng = (((i != 0 || !(num4 > pi / 2.0 - latitude)) && 0 == 0)
? (((i == 180 && num4 > pi / 2.0 + latitude))
final lat = asin(sinLat * cosAlt + cos(angle) * sinAlt * cosLat);
final num9 = (cosAlt - sinLat * sin(lat)) / (cosLat * cos(lat));
final lng = (((i != 0 || !(asocAlt > pi / 2.0 - latitude)) && 0 == 0)
? (((i == 180 && asocAlt > pi / 2.0 + latitude))
? (longitude + pi)
: ((num9.abs() > 1.0)
? longitude
Expand Down
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.1
version: 2.0.2
repository: https://github.com/xclud/dart_latlng
homepage: https://pwa.ir

Expand Down

0 comments on commit 0457d76

Please sign in to comment.