Bezier Interpolant Curves (r183-inspired)

Interactive keyframe interpolation lab using cubic Bezier interpolation between sampled points with tunable tension and live marker playback.

Key topics: three.js animation, bezier interpolant, keyframe interpolation, curve tension, r183

Overview

Animation is mostly about what happens between keyframes. Linear interpolation moves at constant speed and changes direction abruptly at every key, which looks robotic. Curved interpolation passes smoothly through the keys. This lab samples a set of 3D keyframes and joins them with cubic Bézier segments whose smoothness you control with a tension value, then sends a marker along the result.

How it works

A cubic Bézier segment from point P0 to P3 is shaped by two control points, P1 and P2. The curve starts heading towards P1 and arrives from the direction of P2, but it does not pass through them. To build a smooth path through a sequence of keyframes, each segment's control points are derived from the neighbouring keyframes: the tangent at a key is parallel to the line between the previous and next keys (the Catmull-Rom construction), and it is scaled by the tension factor.

  • Low tension shortens the tangents, so the path hugs the straight-line polyline with tight corners.
  • High tension lengthens them, so the path swings wider and smoother, and can overshoot.

Because neighbouring segments share a tangent at each key, the path is continuous in both position and direction. Three.js's animation system uses the same family of ideas in its interpolants, and CubicBezierCurve3 and CatmullRomCurve3 expose them for paths.

Exploring the demo

Compare the dim polyline (the raw samples) with the bright interpolated curve. Drag tension from low to high and watch the corners round off, then start to bulge. Follow the moving marker: it passes through every keyframe without stopping or kinking.

Where this is used

Camera rails in cutscenes, enemy patrol routes, motion paths for UI, and smoothing noisy sensor or GPS data all use this interpolation. For moving the camera along a curve see the camera tour in the cathedral, for curve-driven geometry see splines, and for deforming a mesh along a path see the curve modifier.

What this code does

- Bezier Keyframe Interpolation: each segment derives Bezier control points from neighboring keyframes and a tension factor.
- Live Curve Rebuild: changing tension updates the entire smoothed path so interpolation behavior is immediately visible.
- Marker Playback: animated sphere traverses the interpolated curve to show temporal continuity between samples.
- Comparison Baseline: dim polyline shows raw samples while bright line shows Bezier-smoothed interpolation.
- Practical Use: helps tune path smoothness for camera rails, motion curves, and timeline-based procedural animation.

Continue Learning

JavaScript Implementation

ES6+
function cubicBezier (t, p0, p1, p2, p3) {
  const it = 1 - t
  return (
    it * it * it * p0 +
    3 * it * it * t * p1 +
    3 * it * t * t * p2 +
    t * t * t * p3
  )
}

// A tiny Bezier interpolant over keyframes.

function evaluateBezierKeyframe (u, values, tension) {
  const count = values.length
  const scaled = u * (count - 1)
  const i = Math.min(Math.floor(scaled), count - 2)
  const localT = scaled - i
  const p0 = values[Math.max(0, i - 1)]
  const p1 = values[i]
  const p2 = values[i + 1]
  const p3 = values[Math.min(count - 1, i + 2)]
  const c1 = p1 + (p2 - p0) * tension / 3
  const c2 = p2 - (p3 - p1) * tension / 3
  return cubicBezier(localT, p1, c1, c2, p2)
}

Related demos

Trending this week

Most popular