use cheby::{fit_from_fn_t, ChebySegment};
use qtty::{Kilometer, Second};
fn main() {
const N: usize = 15;
let start = Second::new(0.0);
let end = Second::new(std::f64::consts::TAU); let half = (end - start) * 0.5;
let mid = start + half;
let coeffs: [Kilometer; N] = fit_from_fn_t(
|t: Second| Kilometer::new(7000.0 + 250.0 * t.value().sin()),
start,
end,
);
let seg: ChebySegment<Kilometer, Second, N> = ChebySegment::new(coeffs, mid, half);
for raw_t in [0.5, 1.5, 3.0, 5.5] {
let t = Second::new(raw_t);
let (val, dval_dt) = seg.eval_both(t);
let exact_val = Kilometer::new(7000.0 + 250.0 * raw_t.sin());
let exact_dval = 250.0 * raw_t.cos(); println!(
"t={raw_t:.2} s: val={val:.6} (exact {exact_val:.6}) \
dval/dt={:.6} km/s (exact {exact_dval:.6} km/s)",
dval_dt.value()
);
}
}