state method

StateVector state(
  1. double et
)

Position and velocity of target relative to center at et (TDB seconds past J2000).

Supports types 2 (position polynomials; velocity from the derivative) and 3 (separate position and velocity polynomials).

Implementation

StateVector state(double et) {
  if (!covers(et)) {
    throw RangeError('Time $et s outside segment $this');
  }
  if (dataType != 2 && dataType != 3) {
    throw UnsupportedError('SPK segment type $dataType not supported');
  }
  final init = _directory[0];
  final intervalLength = _directory[1];
  final recordSize = _directory[2].toInt();
  final count = _directory[3].toInt();

  final index = ((et - init) / intervalLength).floor().clamp(0, count - 1);
  if (index != _recordIndex) {
    _record = file.words(beginWord + index * recordSize, recordSize);
    _recordIndex = index;
  }
  // Rekord: środek przedziału, połowa długości, potem współczynniki
  // kolejnych składowych (3 dla typu 2, 6 dla typu 3).
  final record = _record;
  final mid = record[0];
  final radius = record[1];
  final components = dataType == 2 ? 3 : 6;
  final n = (recordSize - 2) ~/ components;
  final s = (et - mid) / radius;

  double value(int component) => _chebyshev(record, 2 + component * n, n, s);
  double derivative(int component) =>
      _chebyshevDerivative(record, 2 + component * n, n, s) / radius;

  return dataType == 2
      ? StateVector(
          value(0),
          value(1),
          value(2),
          derivative(0),
          derivative(1),
          derivative(2),
        )
      : StateVector(
          value(0),
          value(1),
          value(2),
          value(3),
          value(4),
          value(5),
        );
}