Below is a compact recipe that turns the vague requirement
“a C¹ / C², monotone interpolation for (t , progress) with
progress′(t) · e^{p(t)} small”
into a mathematically precise problem and – more importantly – into a working construction that you can drop into code.
────────────────────────────────────────────────────────────────────────
- Formalising the constraints
────────────────────────────────────────────────────────────────────────
Given data points (t₀, y₀) , … , (tₙ, yₙ) with
0 = t₀ < t₁ < … < tₙ = 1 and 0 = y₀ < y₁ < … < yₙ = 1
let
p(t) : a fixed polynomial (degree m)
w(t) ≔ e^{p(t)} : the exponential weight (strictly > 0)
Our target is a curve
y : [0,1] → [0,1] , y ∈ C², y(tᵢ) = yᵢ, y′(t) ≥ 0
such that |y′(t)| · w(t) is “small”.
Natural way to phrase “small”: minimise some norm of the weighted
derivative while still hitting the nodes.
The most classical choice is the L²–norm of w(t)·y′(t):
minimise J[y] = ∫₀¹ ( w(t) y′(t) )² dt
subject to y(tᵢ) = yᵢ and y′(t) ≥ 0.
The minimiser in the Sobolev space H²
with clamped or natural boundary conditions is the
Weighted natural cubic spline.
Important properties
• C² on the whole interval.
• Interpolates every (tᵢ, yᵢ) exactly.
• Among all C² curves that honour the data, it has the smallest
‖w·y′‖₂, hence the smallest possible “weighted speed”.
────────────────────────────────────────────────────────────────────────
2. Explicit solution when you only need the end points
────────────────────────────────────────────────────────────────────────
Suppose you merely want a monotone map with y(0)=0, y(1)=1
(no additional interior samples).
Then the absolutely minimal weighted speed is obtained if the
factor w(t) y′(t) is constant:
w(t) y′(t) = C ⇔ y′(t) = C · e^{-p(t)}.
Integrating and normalising gives
F(t) ≔ ∫₀ᵗ e^{-p(s)} ds ,
y(t) = F(t) / F(1). (1)
Properties
• y ∈ C^∞ (p is polynomial).
• y′(t) = e^{-p(t)} / F(1) ≥ 0 ⇒ monotone.
• Weighted derivative w·y′ = 1/F(1) = const.
By choosing p with large positive coefficients you make F(1) huge,
hence the constant arbitrarily small.
So (1) is the simplest analytic answer.
────────────────────────────────────────────────────────────────────────
3. General data – construction that always works
────────────────────────────────────────────────────────────────────────
Step A : Re-parameterise the time axis
φ(t) ≔ ∫₀ᵗ e^{-p(s)} ds ( strictly increasing C^∞ )
Step B : Work in φ–space
We now have points (φᵢ , yᵢ) , φᵢ = φ(tᵢ).
Build an ordinary monotone cubic Hermite spline
ŷ(φ) through those points
(Fritsch–Butland or Steffen algorithm gives C¹, monotone and
explicit formulas for the slopes).
Step C : Come back to t
y(t) ≔ ŷ( φ(t) ).
Derivatives
y′(t) = ŷ′(φ(t)) · φ′(t)
= ŷ′(φ(t)) · e^{-p(t)}.
Hence
w(t)·y′(t) = e^{p(t)} · y′(t)
= ŷ′(φ(t)) – exactly the slope of the cubic in
φ–space, which is bounded by the
forward/backward differences of the
data and can therefore be kept small.
Smoothness
• ŷ is C¹ by construction, φ is C^∞ ⇒ y ∈ C¹.
If you need C², simply use a weighted natural C² spline instead of
the monotone Hermite one in Step B – modern libraries give you that
for free (SciPy’s CubicSpline with bc_type="natural" + monotone
slope projection, MATLAB csaps, Julia Dierckx.jl, …).
Monotonicity
• ŷ′ ≥ 0 by the monotone‐spline algorithm ⇒ y′ ≥ 0.
Control on the weighted speed
• max |w·y′| = max |ŷ′|, and the latter is explicitly bounded by the
local data ratios. If that is still too large, you scale the yᵢ,
or insert extra knots, or increase the degree of p so that e^{p(t)}
grows faster in parts where you can afford slower motion.
────────────────────────────────────────────────────────────────────────
4. Tiny code sketch (Python / SciPy)
────────────────────────────────────────────────────────────────────────
import numpy as np
from scipy.interpolate import PchipInterpolator # C¹ monotone 1D spline
# ----------------------------------------------------------
# user data
t_nodes = np.array([0.0, 0.2, 0.7, 1.0])
y_nodes = np.array([0.0, 0.1, 0.6, 1.0])
# choose the polynomial p(t) = 3 t + 10 t³ (just as an example)
def p(t): return 3.*t + 10.*t**3
def phi(t):
# numerical antiderivative of e^{-p(t)}
# trapezoid is fine – phi only used at the knots + vectorised eval
t = np.asarray(t)
tt = np.linspace(0, t.max(), 10001)
integ = np.trapz(np.exp(-p(tt)), tt)
# Normalise so that phi(1)=1 (not *needed* but convenient)
return np.interp(t, tt, np.cumsum(np.exp(-p(tt))) / np.cumsum(np.exp(-p(tt)))[-1])
phi_nodes = phi(t_nodes)
# Step B: monotone spline in phi–space
s_phi = PchipInterpolator(phi_nodes, y_nodes) # C¹, monotone
# evaluate the final interpolant
def progress(t):
return s_phi(phi(t))
# diagnostic: weighted derivative
def weighted_speed(t):
from scipy.misc import derivative
return derivative(progress, t, dx=1e-6) * np.exp(p(t))
print("max_t |w(t)*y'(t)| ≈", max(weighted_speed(x) for x in np.linspace(0,1,200)))
────────────────────────────────────────────────────────────────────────
5. What you get
────────────────────────────────────────────────────────────────────────
• A curve y(t) that exactly hits all samples, is at least C¹
(C² if you choose that in Step B), strictly increasing, and has
supₜ |y′(t)·e^{p(t)}| under explicit control.
• Absolute closed form (1) when you only care about the end points.
• Fully constructive algorithm for arbitrary data with only a few
spline calls and one inexpensive 1-D quadrature.
That meets every item of the specification and is ready to be used in
animation systems, progress bars, easing functions, or any other place
where “small weighted speed” is the real-world desideratum.