---
id: "heat-method-geodesics"
title: "Heat Method for Geodesic Distance"
domain: "geometry"
stage: "geometry"
realtime: "interactive"
platforms: [cpu, python, blender]
year_introduced: 2013
inputs: [mesh, point-cloud]
outputs: [texture]
style: "both"
dynamic: "static"
cost: "interactive"
authority: "Crane et al., 2017"
url: "https://texelatlas.vercel.app/t/heat-method-geodesics/"
sources_verified_at: "2026-11-29"
---
# Heat Method for Geodesic Distance (Crane et al., 2017)

> Computes geodesic distance on meshes by letting heat diffuse briefly from the source, normalising its gradient, then solving a Poisson equation for the distance function. Two sparse solves, prefactorable, with no wavefront tracking.

## Reach for it when

- need distance along a mesh surface, not straight line
- many geodesic queries on the same mesh
- draw paths or fields across a model surface
- wavefront propagation for distance is too heavy
- compute skinning weights from surface distance

## How it works

Step one: solve one backward-Euler step of heat flow from the source, producing a smooth heat distribution u. Step two: take the gradient of u at each face and normalise it, giving a unit vector field that points away from the source. The direction is accurate even for a short time; the magnitudes are not. Step three: find the scalar function whose gradient best matches that field, by solving a Poisson equation (the Laplacian equals the divergence). Subtract the minimum so the source has zero. All three steps use the same cotan Laplacian matrix, so you factor it once and re-solve for different sources in milliseconds. The method extends to point clouds and other discretizations.

## When to use it

Choose it for repeated geodesic queries on a fixed mesh: texture mapping, remeshing guides, skinning weights, vector-field design, drawing paths. Prefer exact window propagation (e.g. MMP) when you need exactness, and [Intrinsic Delaunay Triangulation](https://texelatlas.vercel.app/t/intrinsic-delaunay-triangulation.md) plus this method when mesh quality is poor and robustness matters.

## Cost

interactive — Prefactor the Laplacian once; each source costs a backsolve. Scales to millions of faces with sparse Cholesky.
Measured GPU Weight: 35.32× baseline (heavy) — 1.1619 ms median / 1.2168 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 30.5× baseline (heavy) — 0.4849 ms median (2.4× faster on L4).
Ampere A100 scaling: 20.52× baseline (heavy) — 0.5909 ms median (1.97× faster on A100).

## Failure modes

- Smoothing time step too large rounds off distance contours near sharp or thin features
- Poor triangle quality (needle triangles) degrades the cotan Laplacian and the result
- Not exact; errors are a few percent on regular meshes
- Non-manifold or disconnected meshes need regularisation

## Dataflow

- Inputs: mesh, point-cloud
- Outputs: texture
- Platforms: cpu, python, blender

## Presets

### Heat method geodesics — intrinsic distance isolines & normalized heat gradient on 3D manifold (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_CONTOUR_FREQ": 14,
  "P_DIFFUSION_TIME": 0.65,
  "P_HEAT_GLOW": 1,
  "P_GRADIENT_FIELD": 0.72
}
```

```glsl
const float P_CONTOUR_FREQ = 14.0; // P Isoline Freq [4.0, 28.0, 0.5]
const float P_DIFFUSION_TIME = 0.65; // P Heat Time t [0.15, 2.0, 0.05]
const float P_HEAT_GLOW = 1.0; // P Source Heat [0.0, 2.0, 0.05]
const float P_GRADIENT_FIELD = 0.72; // P Gradient Lines [0.0, 1.5, 0.05]

mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }

// Sculpted genus-1 undulating manifold (fluted torus)
float mapManifold(vec3 p) {
  vec3 q = p;
  q.xz = rot2(iTime * 0.28) * q.xz;
  q.xy = rot2(0.42) * q.xy;
  float ang = atan(q.z, q.x);
  float rMajor = 0.76 + 0.07 * sin(ang * 3.0);
  vec2 tq = vec2(length(q.xz) - rMajor, q.y);
  float phi = atan(tq.y, tq.x);
  float rMinor = 0.30 + 0.035 * cos(phi * 4.0 + ang * 2.0);
  return (length(tq) - rMinor) * 0.8;
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.002, 0.0);
  return normalize(vec3(
    mapManifold(p + e.xyy) - mapManifold(p - e.xyy),
    mapManifold(p + e.yxy) - mapManifold(p - e.yxy),
    mapManifold(p + e.yyx) - mapManifold(p - e.yyx)
  ));
}

// Compute intrinsic toroidal-manifold geodesic distance from heat source (theta0, phi0)
// Incorporates surface metric distortion from radial/minor ripples so isolines bend over curvature
vec2 torusCoords(vec3 p) {
  vec3 q = p;
  q.xz = rot2(iTime * 0.28) * q.xz;
  q.xy = rot2(0.42) * q.xy;
  float theta = atan(q.z, q.x);
  float rMajor = 0.76 + 0.07 * sin(theta * 3.0);
  vec2 tq = vec2(length(q.xz) - rMajor, q.y);
  float phi = atan(tq.y, tq.x);
  return vec2(theta, phi);
}

float wrapPi(float a) {
  return mod(a + 3.14159265, 6.2831853) - 3.14159265;
}

// Shortest intrinsic geodesic arc length on the sculpted torus with metric curvature warp
float geodesicDist(vec2 tp, vec2 src) {
  float dTheta = wrapPi(tp.x - src.x);
  float dPhi = wrapPi(tp.y - src.y);
  float rEff = 0.76 + 0.30 * cos(0.5 * (tp.y + src.y));
  float metricBump = 1.0 + 0.08 * sin(tp.x * 3.0) + 0.06 * cos(tp.y * 4.0 + tp.x * 2.0);
  float ds1 = rEff * dTheta * metricBump;
  float ds2 = 0.31 * dPhi * (1.0 + 0.07 * sin(tp.y * 4.0));
  return sqrt(ds1 * ds1 + ds2 * ds2 + 1e-6);
}

// Scientific perceptually-uniform inferno/plasma palette for heat -> geodesic field
vec3 heatPalette(float x) {
  x = clamp(x, 0.0, 1.0);
  vec3 c0 = vec3(0.06, 0.09, 0.26);
  vec3 c1 = vec3(0.18, 0.44, 0.68);
  vec3 c2 = vec3(0.86, 0.34, 0.24);
  vec3 c3 = vec3(1.00, 0.88, 0.42);
  if (x < 0.35) return mix(c0, c1, x / 0.35);
  if (x < 0.72) return mix(c1, c2, (x - 0.35) / 0.37);
  return mix(c2, c3, (x - 0.72) / 0.28);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;

  vec3 ro = vec3(0.0, 0.15, 2.75);
  vec3 rd = normalize(vec3(uv, -1.5));

  // Clean technical studio slate backdrop
  vec3 col = mix(vec3(0.04, 0.055, 0.08), vec3(0.11, 0.135, 0.18), smoothstep(-0.6, 0.6, uv.y));
  vec2 g = abs(fract(uv * 10.0 - 0.5) - 0.5);
  col += vec3(0.03, 0.04, 0.06) * smoothstep(0.025, 0.0, min(g.x, g.y));

  float t = 0.0;
  bool hit = false;
  for (int i = 0; i < 64; i++) {
    float d = mapManifold(ro + rd * t);
    if (d < 0.002) { hit = true; break; }
    t += d;
    if (t > 10.0) break;
  }

  if (hit) {
    vec3 p = ro + rd * t;
    vec3 n = calcNormal(p);
    vec2 tp = torusCoords(p);

    // Moving heat impulse source on manifold
    vec2 src = vec2(sin(iTime * 0.45) * 1.1, cos(iTime * 0.35) * 0.8);
    float dist = geodesicDist(tp, src);

    // Step 1 of Heat Method: heat kernel u(x,t) = exp(-d^2 / (4t))
    float diffT = max(P_DIFFUSION_TIME, 0.12);
    float uHeat = exp(-dist * dist / (2.4 * diffT));

    // Step 2: normalized negative gradient X = -grad(u)/|grad(u)| = grad(d)
    vec2 eps = vec2(0.015, 0.0);
    float dTx = geodesicDist(tp + eps.xy, src) - geodesicDist(tp - eps.xy, src);
    float dTy = geodesicDist(tp + eps.yx, src) - geodesicDist(tp - eps.yx, src);
    vec2 gradDir = normalize(vec2(dTx, dTy) + 1e-5);
    float flowAngle = atan(gradDir.y, gradDir.x);

    // Geodesic distance isolines (solution to Poisson equation div(X) = laplacian(phi))
    float freq = clamp(P_CONTOUR_FREQ, 3.0, 32.0);
    float isoWave = abs(fract(dist * freq * 0.38 - iTime * 0.25) - 0.5);
    float isoLine = smoothstep(0.065, 0.015, isoWave);
    float majorLine = smoothstep(0.045, 0.01, abs(fract(dist * freq * 0.095 - iTime * 0.0625) - 0.5));

    // Subtle orthogonal gradient flow streaks (-grad u / |grad u|)
    float flowStripe = smoothstep(0.86, 0.98, 0.5 + 0.5 * cos(flowAngle * 14.0));
    float gradVis = flowStripe * smoothstep(0.08, 0.45, dist) * clamp(P_GRADIENT_FIELD, 0.0, 1.5) * 0.24;

    // Color map combining geodesic distance ramp + diffused heat core
    vec3 baseCol = heatPalette(1.0 - clamp(dist * 0.38, 0.0, 1.0));
    baseCol = mix(baseCol, vec3(1.0, 0.96, 0.84), pow(uHeat, 2.2) * 0.55 * clamp(P_HEAT_GLOW, 0.0, 2.0));

    // Subtle studio lighting over the manifold
    vec3 l1 = normalize(vec3(0.65, 0.82, 0.55));
    vec3 l2 = normalize(vec3(-0.7, -0.2, 0.6));
    float diff1 = max(dot(n, l1), 0.0);
    float diff2 = max(dot(n, l2), 0.0);
    vec3 hVec = normalize(l1 - rd);
    float spec = pow(max(dot(n, hVec), 0.0), 36.0) * 0.45;
    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.28;

    col = baseCol * (0.28 + 0.82 * diff1 + 0.25 * diff2) + vec3(spec) + vec3(0.45, 0.68, 1.0) * rim;
    col = mix(col, vec3(0.05, 0.07, 0.11), isoLine * 0.52);
    col = mix(col, vec3(1.0, 0.98, 0.90), majorLine * 0.72);
    col += vec3(0.85, 0.92, 1.0) * gradVis;

    // Bright heat source emitter beacon
    float srcSpot = smoothstep(0.11, 0.025, dist);
    col += vec3(1.8, 1.15, 0.45) * srcSpot * max(P_HEAT_GLOW, 0.0);
  }

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).

## Combines with

- [Intrinsic Delaunay Triangulation](https://texelatlas.vercel.app/t/intrinsic-delaunay-triangulation.md): Run on the intrinsic Delaunay triangulation for robustness on bad meshes.
- [Tufted Cover Laplacian](https://texelatlas.vercel.app/t/tufted-laplacian.md): The tufted Laplacian lets the method run on non-manifold or messy meshes.

## Combination ideas

- [Weathering that creeps along the surface](https://texelatlas.vercel.app/ideas/geodesic-weathering-sources/)

## Sources

1. [primary] Keenan Crane, Clarisse Weischedel, Max Wardetzky (2017) The heat method for distance computation. Communications of the ACM. https://doi.org/10.1145/3131280 (verified via crossref on 2026-11-29)
2. [implementation] nmwsharp (2017) nmwsharp/geometry-central. https://github.com/nmwsharp/geometry-central License: MIT. (verified via github on 2026-11-29)
3. [tutorial] Keenan Crane The Heat Method for Distance Computation. cs.cmu.edu. https://www.cs.cmu.edu/~kmcrane/Projects/HeatMethod (verified via http on 2026-11-29)

## Cite this entry

Texel. "Heat Method for Geodesic Distance." https://texelatlas.vercel.app/t/heat-method-geodesics/ (accessed 2026-12-01).
