topocentric function

Map<String, dynamic> topocentric(
  1. Map<String, dynamic> observerGeodetic,
  2. Map<String, dynamic> satelliteEcf
)

Implementation

Map<String, dynamic> topocentric(Map<String, dynamic> observerGeodetic, Map<String, dynamic> satelliteEcf) {
  // http://www.celestrak.com/columns/v02n02/
  // TS Kelso's method, except I'm using ECF frame
  // and he uses ECI.

  final longitude = observerGeodetic['longitude'];
  final latitude = observerGeodetic['latitude'];

  final observerEcf = geodeticToEcf(observerGeodetic);

  final rx = satelliteEcf['x'] - observerEcf['x'];
  final ry = satelliteEcf['y'] - observerEcf['y'];
  final rz = satelliteEcf['z'] - observerEcf['z'];

  final topS = ((Math.sin(latitude) * Math.cos(longitude) * rx)
      + (Math.sin(latitude) * Math.sin(longitude) * ry))
    - (Math.cos(latitude) * rz);

  final topE = (-Math.sin(longitude) * rx)
    + (Math.cos(longitude) * ry);

  final topZ = (Math.cos(latitude) * Math.cos(longitude) * rx)
    + (Math.cos(latitude) * Math.sin(longitude) * ry)
    + (Math.sin(latitude) * rz);

  return { 'topS': topS, 'topE': topE, 'topZ': topZ };
}