{
 "id": "verlet-integration-constraints",
 "title": "Verlet integration with relaxation constraints",
 "aliases": [
  "Jakobsen method"
 ],
 "domain": "simulation",
 "subdomain": "particle/constraint solvers",
 "stage": "simulation",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cpu"
 ],
 "year_introduced": 2001,
 "inputs": [
  "particles"
 ],
 "outputs": [
  "particles",
  "skeleton"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Stores current and previous positions instead of velocity and enforces constraints by repeatedly projecting positions, giving robust ropes, cloth and ragdolls in a few dozen lines.",
 "how_it_works": "Positional Verlet updates `x_next = x + (x - x_prev) + a*dt^2`, so velocity is implicit. Constraints (fixed distance between particles, planes, pins) are satisfied by iterating over them several times per frame and moving the particles directly to satisfy each one, split by inverse mass. Because velocity is derived from the position change, projecting a particle out of a collider also removes the velocity into it, so collisions behave plausibly with no explicit impulse. Rigid bodies and ragdolls are built from particles linked by distance constraints into stiff tetrahedra or sticks.",
 "when_to_use": "Choose it for quick, stable, easily-tuned rope, cloth, cape or ragdoll effects in games and creative coding. Prefer `position-based-dynamics` or `xpbd` when you need volume, bending, or time-step-independent stiffness, and `sequential-impulses` when rigid bodies must stack and have accurate friction and restitution.",
 "cost": {
  "class": "cheap",
  "notes": "Very cheap: linear in particles and constraints."
 },
 "failure_modes": [
  "Stiffness depends on iteration count: long chains stretch",
  "Friction and restitution are crude; stacking stability is poor",
  "Angular momentum is not conserved for rigid shapes built from particles",
  "Fixed time step is assumed; variable dt changes the implicit velocity"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf",
   "type": "web",
   "title": "Advanced Character Physics",
   "authors": [
    "Thomas Jakobsen"
   ],
   "year": null,
   "venue": "cs.cmu.edu",
   "url": "https://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261115033117/http://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf",
     "timestamp": "20261115033117"
    },
    "page_title": null,
    "host": "cs.cmu.edu",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://www.cs.cmu.edu/afs/cs/academic/class/15462-s13/www/lec_slides/Jakobsen.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "jakobsenadvanced"
  }
 ],
 "presets": [
  {
   "id": "verlet-integration-constraints-live",
   "title": "Verlet Integration & Constraints — 2 relaxation sweeps (left) vs 16 Gauss-Seidel iterations (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_RELAX_ITERS": 14,
    "P_WIND_FORCE": 0.95,
    "P_WIRE_VIS": 0.85,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_RELAX_ITERS = 14.0; // P Relaxation Iters [2.0, 24.0, 1.0]\nconst float P_WIND_FORCE = 0.95; // P Wind Gust [0.0, 2.0, 0.05]\nconst float P_WIRE_VIS = 0.85; // P Constraint Mesh [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Low / High Iter Split [0.0, 1.0, 0.02]\n\n// Analytic Verlet cloth surface height & sag modeled from Gauss-Seidel convergence rate (1 - c)^N\nvec3 clothSurface(vec2 q, float iters, float wind, float t) {\n  // q.x in [-1, 1], q.y in [0, 1] (top pinned at y=1, hanging down to y=0)\n  float drop = 1.0 - q.y;\n  // Few iterations leave distance constraints stretched; high iterations converge to inextensible drape\n  float stretchFactor = 0.34 / (1.0 + 0.32 * iters);\n  float pinDip = (1.0 - abs(sin(q.x * 3.1415926 * 1.5))) * 0.06 * (1.0 + 2.4 * stretchFactor);\n\n  float y = q.y * 1.05 - 0.50 - drop * drop * stretchFactor * 0.85 - pinDip * drop;\n  float x = q.x * 0.82 * (1.0 - 0.06 * drop * (1.0 - stretchFactor));\n\n  // Travelling wind ripple obeying Verlet inertia x_new = 2x - x_prev + a*dt^2\n  float wave1 = sin(q.x * 4.2 - t * 2.6 + drop * 2.1) * 0.11;\n  float wave2 = sin(q.x * 8.6 + t * 3.7 - drop * 3.8) * 0.042;\n  float z = (wave1 + wave2) * wind * smoothstep(0.0, 0.35, drop) + 0.05 * drop * drop * wind;\n  return vec3(x, y, z);\n}\n\n// Signed distance to hanging cloth sheet\nfloat mapCloth(vec3 p, float iters, float wind, float t, out vec2 uvCloth) {\n  float drop = clamp((0.55 - p.y) / 1.05, 0.0, 1.0);\n  float stretchFactor = 0.34 / (1.0 + 0.32 * iters);\n  float effH = 1.05 + stretchFactor * 0.85;\n  vec2 q = vec2(clamp(p.x / 0.82, -1.0, 1.0), clamp(1.0 - (0.55 - p.y) / effH, 0.0, 1.0));\n  uvCloth = q;\n\n  vec3 surf = clothSurface(q, iters, wind, t);\n  vec2 outBound = vec2(max(abs(p.x) - 0.82, 0.0), max(max(p.y - 0.55, surf.y - p.y - 0.01), 0.0));\n  float bottomY = clothSurface(vec2(q.x, 0.0), iters, wind, t).y;\n  float dY = max(p.y - 0.55, bottomY - p.y);\n  float dX = abs(p.x) - 0.82;\n  float dSheet = abs(p.z - surf.z) - 0.016;\n  return max(dSheet, max(dX, dY));\n}\n\nvec3 calcNormal(vec3 p, float iters, float wind, float t) {\n  vec2 e = vec2(0.004, 0.0);\n  vec2 tmp;\n  return normalize(vec3(\n    mapCloth(p + e.xyy, iters, wind, t, tmp) - mapCloth(p - e.xyy, iters, wind, t, tmp),\n    mapCloth(p + e.yxy, iters, wind, t, tmp) - mapCloth(p - e.yxy, iters, wind, t, tmp),\n    mapCloth(p + e.yyx, iters, wind, t, tmp) - mapCloth(p - e.yyx, iters, wind, t, tmp)\n  ));\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isHigh = screenX >= split;\n  float iters = isHigh ? clamp(P_RELAX_ITERS, 2.0, 24.0) : 2.0;\n  float wind = max(P_WIND_FORCE, 0.0);\n  float wireVis = clamp(P_WIRE_VIS, 0.0, 1.5);\n  float t = iTime;\n\n  vec3 ro = vec3(0.0, 0.02, 2.25);\n  vec3 rd = normalize(vec3(uv, -1.55));\n\n  vec3 col = mix(vec3(0.028, 0.036, 0.056), vec3(0.075, 0.095, 0.142), smoothstep(-0.5, 0.55, uv.y));\n\n  // Top hanging rod (cylinder along x at y=0.56)\n  float tRod = (0.0 - ro.z) / rd.z;\n  vec3 pRod = ro + rd * tRod;\n  if (abs(pRod.y - 0.56) < 0.026 && abs(pRod.x) < 0.92) {\n    float cy = (pRod.y - 0.56) / 0.026;\n    float shading = 0.35 + 0.65 * sqrt(max(1.0 - cy * cy, 0.0));\n    col = vec3(0.45, 0.52, 0.64) * shading;\n  }\n\n  float tHit = 0.0;\n  bool hit = false;\n  vec2 cUV = vec2(0.0);\n  for (int i = 0; i < 64; i++) {\n    vec3 p = ro + rd * tHit;\n    float d = mapCloth(p, iters, wind, t, cUV);\n    if (d < 0.0025) { hit = true; break; }\n    tHit += d * 0.65;\n    if (tHit > 6.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * tHit;\n    vec3 n = calcNormal(p, iters, wind, t);\n    if (dot(n, rd) > 0.0) n = -n;\n\n    vec3 l1 = normalize(vec3(0.55, 0.72, 0.65));\n    vec3 l2 = normalize(vec3(-0.65, -0.25, 0.55));\n    float diff1 = max(dot(n, l1), 0.0);\n    float diff2 = max(dot(n, l2), 0.0);\n    float sheen = pow(1.0 - max(dot(n, -rd), 0.0), 3.0);\n\n    // Structural & shear Verlet distance constraint grid\n    vec2 g = cUV * vec2(12.0, 9.0);\n    vec2 gf = abs(fract(g - 0.5) - 0.5);\n    float structWire = smoothstep(0.065, 0.015, min(gf.x, gf.y));\n    float shearWire = smoothstep(0.055, 0.012, min(abs(fract(g.x + g.y) - 0.5), abs(fract(g.x - g.y) - 0.5)));\n    float nodeDot = smoothstep(0.14, 0.05, length(fract(g + 0.5) - 0.5));\n\n    // Strain coloring: left side stretches red/orange under gravity; right side holds crisp teal\n    float stretchAmt = (1.0 - cUV.y) * (isHigh ? 0.14 : 0.92);\n    vec3 fabricCol = isHigh\n      ? mix(vec3(0.14, 0.64, 0.76), vec3(0.24, 0.84, 0.72), cUV.y)\n      : mix(vec3(0.86, 0.34, 0.22), vec3(0.92, 0.64, 0.28), cUV.y);\n\n    col = fabricCol * (0.28 + 0.82 * diff1 + 0.24 * diff2) + vec3(0.55, 0.78, 0.98) * sheen * 0.35;\n    col = mix(col, vec3(0.05, 0.10, 0.16), structWire * 0.55 * min(wireVis, 1.0));\n    col = mix(col, vec3(0.95, 0.88, 0.45), shearWire * 0.22 * min(wireVis, 1.0));\n    col = mix(col, vec3(0.96, 0.98, 1.0), nodeDot * 0.55 * min(wireVis, 1.0));\n    col += vec3(0.25, 0.05, 0.02) * stretchAmt * 0.25;\n  }\n\n  // Split divider\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "verlet-integration-constraints",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:37.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7088,
      "std": 0.1672,
      "min": 0.1906,
      "max": 0.9014
     },
     "image": "/specimens/verlet-integration-constraints-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "position-based-dynamics",
  "xpbd",
  "sequential-impulses"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/simulation/verlet-integration-constraints.json"
 },
 "solves": [
  "need quick rope, cloth or cape in a few lines",
  "ragdoll simulation explodes with velocity integration",
  "want stable constraints that are easy to tune",
  "creative coding physics with simple code"
 ],
 "authority": "Jakobsen",
 "url": "https://texelatlas.vercel.app/t/verlet-integration-constraints/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 13.67,
  "tier": "moderate",
  "p50_ms": 0.4238,
  "p95_ms": 0.4419,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "verlet-integration-constraints-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 10.81,
   "tier": "moderate",
   "p50_ms": 0.1718,
   "p95_ms": 0.1755,
   "speedup_x": 2.47,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 9.08,
   "tier": "moderate",
   "p50_ms": 0.2616,
   "p95_ms": 0.2644,
   "speedup_x": 1.62,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}