liveBook · Manning

Gradient

As explained in Geometry for Programmers

A gradient is a vector of partial derivatives describing the direction and rate of greatest increase of a multivariable function.

A gradient combines a function’s partial derivatives into a vector. At any point, it points toward the function’s greatest increase. For a two-variable function, its components describe change along x and along y, turning local slope information into a direction that an algorithm can use. section 11.3.2

Fitting a contour to an SDF

A signed distance function (SDF) supplies both an error and a direction for each contour vertex. Its value estimates how far the vertex is from the target curve; shifting the vertex by that amount against the gradient pulls a coarse straight-segment contour closer to the 0-isoline. section 11.4.1

Gradients also help preserve geometric features. Neighboring gradients that differ greatly can signal a sharp corner, while partial derivatives at segment endpoints can constrain cubic pieces used to smooth a contour. This makes gradients useful for both locating a curve and shaping its final appearance. section 11.3.2 section 11.4.1

Image data needs a practical caution. A pixel grid has no gradient until interpolation turns it into a continuous function. Even then, an interpolated threshold function is not necessarily a true distance function, so repeated gradient-directed adjustments and an approximation threshold are used instead of expecting one exact move. section 12.4.3

Gradient magnitude matters when derivatives become cubic tangent values. A quasi-SDF can produce oversized vectors that make otherwise smooth cubic contours loop. Normalizing tangent vectors retains directional information while avoiding those unwanted loops. section 12.4.4

Figure 11.26 Pulling the points from the original contour by function gradients and values makes the contour fit the 0-isoline better.
11-26

Compare the initial cell-based contour with the gradient- and value-guided fit to see why the direction vector improves placement. section 11.4.1

How Geometry for Programmers covers it

How deep it goes
Defines gradients through partial derivatives, then applies their direction and magnitude to fitting, sharp features, and cubic tangents.
Examples
Uses a two-variable polynomial, SDF contour shifts, interpolated threshold images, and normalized cubic tangent vectors.
What it assumes
Introduces partial derivatives as changes by x and y before combining them into a vector.
What you can do after
Apply it to move contour vertices, derive cubic endpoint constraints, and control tangent-vector scale.
How it connects
Connects partial derivatives with signed distance functions, dual contouring, interpolation, isolines, and cubic curves.

Also explained in

Compare how 20 books explain gradient →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.