Class PAGestureParametric

java.lang.Object
net.paulhertz.pixelaudio.curves.PAGestureParametric

public final class PAGestureParametric extends Object
Treats a gesture defined by (time, x, y) samples as a parametric curve.
    u ∈ [0,1] → (t(u), x(u), y(u))
 
Under the hood:
  • timesMs: int[] of time offsets (ms), ascending, timesMs[0] == 0
  • points: PVector list (x,y) of same length
You can:
  • sample with a linear parameter: f(u) = u
  • pass a warp function f(u) to speed up/slow down traversal
Exponential warp (speeding up over time)
    DoubleUnaryOperator expWarp = u -> (float_ Math.pow(u, 2.0);   // u squared
    GestureParametric.Sample s = gp.sample(0.5f, expWarp);
 
Log-like warp (fast at start, slow at end)
    DoubleUnaryOperator sqrtWarp = u -> (float_ Math.sqrt(u);     // square root of u
    GestureParametric.Sample s = gp.sample(0.5f, sqrtWarp);
 
Something like f(u) = (e^{k * u} - 1) / (e^{k} - 1) for more dramatic warps.
  • Field Details

    • points

      private final List<processing.core.PVector> points
    • timesMs

      private final int[] timesMs
    • count

      private final int count
    • totalDurationMs

      private final float totalDurationMs
  • Constructor Details

    • PAGestureParametric

      public PAGestureParametric(List<processing.core.PVector> points, int[] timesMs)
      Parameters:
      points - gesture points (x,y)
      timesMs - time offsets (ms), same length as points, ascending, timesMs[0] == 0
  • Method Details

    • getTotalDurationMs

      public float getTotalDurationMs()
      Total gesture duration in ms.
    • sample

      public PAGestureParametric.Sample sample(float u)
      Sample with linear parameterization: f(u) = u. u is clamped to [0,1].
    • sample

      public PAGestureParametric.Sample sample(float u, DoubleUnaryOperator warp)
      Sample with an optional warp function f(u) → [0,1]. If warp is null, identity is used.
    • findSegment

      private int findSegment(float tTarget)
      Find the largest i such that timesMs[i] <= tTarget. Returns count-1 if tTarget is beyond the last sample.
    • lerp

      private static float lerp(float a, float b, float u)