Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Interpolation tables

Learn how HPR Sim reads values between a table’s points, along straight lines or a spline, and what each table does past its ends.

In short

  • What it models: reading values between a table’s points, such as drag coefficient against Mach number, along straight lines or a smooth natural cubic spline. Each table sets what happens past its ends, and every lookup says if it went there.
  • Sources: the slope form of the cubic spline in C. de Boor, A Practical Guide to Splines (Springer, 2001).
  • How well it is validated: analytic and unit tests only. The spline through (0, 0), (1, 1) and (2, 0) matches its closed form, y=3x/2−x3/2 on [0,1]. Property tests check that both kinds hit every point. Not compared with another simulator or a flight.
  • What it leaves out: tables of more than one input. A natural spline can overshoot where data turn sharply (a thrust spike, a transonic drag peak). There is no overshoot-free (monotone) cubic yet, so use linear tables there.

Code and sources

Code: hpr_core::interp (Table1D). Today it carries the tables that override HPR Sim’s own drag (CD(M)), and normal force with its center of pressure (Aerodynamics). Thrust curves and soundings interpolate on their own (Solid motors, Atmosphere). Every table states how it interpolates and what happens outside its range, and every lookup reports whether it extrapolated.

Knots

A table has n≥2 knots (xi,yi). The xi strictly increase, and every value and every secant slope δi=(yi+1−yi)/hi, with hi=xi+1−xi, is finite. Construction and deserialization both enforce this.

Interpolation

Inside [x0,xn−1], with t=(x−xi)/hi on interval i:

  • Linear: y=(1−t)yi+tyi+1. This form returns the knot values exactly.

  • Natural cubic spline: the cubic Hermite form with knot slopes si:

    y=h00(t)yi+h10(t)hisi+h01(t)yi+1+h11(t)hisi+1,h00=(1+2t)(1−t)2,h10=t(1−t)2,h01=t2(3−2t),h11=−t2(1−t)

    The second derivative at the ends of interval i is

    y″(xi+)=6δi−4si−2si+1hi,y″(xi+1−)=−6δi+2si+4si+1hi

    Equating the two at each interior knot and multiplying by hi−1hi/2 gives

    hisi−1+2(hi−1+hi)si+hi−1si+1=3(hiδi−1+hi−1δi)

    Setting y″ to zero at both ends (the “natural” or free-end condition) closes the system with 2s0+s1=3δ0 and sn−2+2sn−1=3δn−2. This is the slope form of cubic spline interpolation (C. de Boor, A Practical Guide to Splines, rev. ed., Springer, 2001, ch. IV). Every row is strictly diagonally dominant, so the Thomas algorithm needs no pivoting. With two knots the spline is the straight line.

A natural spline can overshoot where the data turn sharply (a thrust spike, a transonic drag peak). Use linear tables for such data; a monotone cubic can be added when a model needs one.

Extrapolation

policybelow x0above xn−1
clamp (default)y0yn−1
lineary0+m0(x−x0)yn−1+mn−1(x−xn−1)
errorCoreError::OutOfRangeCoreError::OutOfRange

m is the end interval’s secant for a linear table and the spline’s end slope s0 or sn−1 for a cubic one. So linear extrapolation of a natural spline stays twice differentiable. A lookup at NaN is an error under every policy.

Tests that pin this

The tests are in crates/hpr-core/src/interp.rs.

  • natural_spline_matches_the_three_knot_closed_form: knots (0,0), (1,1), (2,0) give slopes (3/2,0,−3/2) and y=3x/2−x3/2 on [0,1], symmetric about x=1.
  • Property tests: both kinds reproduce the knots exactly. Linear values stay within each interval’s end values. The spline’s second derivative is continuous at interior knots and zero at the ends. The spline reproduces straight lines, extrapolation included. Each policy behaves as in the table above. A JSON round trip rebuilds an identical table.
  • rejects_malformed_knots, deserializing_checks_the_knots: malformed input fails.
FusionSpace HPRVersion 0.1.0Issued 2026-11-21In preparationAbout HPR Sim