liveBook · Manning

Geometric deformation

As explained in Geometry for Programmers

Deformation modeling is the construction of changed geometric objects by applying a position-dependent displacement function.

Geometric deformation constructs a changed geometric object by evaluating a position-dependent displacement function and adding the resulting vectors to its points. section 8.3.4

A practical deformation workflow is:

  • Define displacement values at selected spatial locations. section 8.3.4
  • Interpolate those values with a continuous, smooth function. section 8.3.4
  • Evaluate the function for every model point and add the displacement components to its coordinates. section 8.3.4

Interpolating a mushroom deformation

Random displacement values are assigned around a mushroom model. Inverse-distance interpolation estimates displacement at each point, producing varied and lifelike mushrooms while preserving continuity and smoothness. section 8.3.4

def F(x, y, z, dds):
    global dxs, dys, dzs, n
    N = 0.                                                          #1
    D = 0.                                                          #2
    for i in range(len(dds)):
        di = ((x-dxs[i])**2 + (y-dys[i])**2 + (z-dzs[i])**2)**0.5   #3
        if di == 0.:
            return dds[i]
        ki = 1/di                                                   #4
        N += ki * dds[i]
        D += ki
    return N / D

The interpolation function combines displacement samples with inverse-distance weights, returning an exact sample value when a point coincides with a control location. section 8.3.4

for i in range(len(x)):
    for j in range(len(x[0])):
        xij = x[i][j]
        yij = y[i][j]
        zij = z[i][j]
        ddx = F(xij, yij, zij, ddxs)
        ddy = F(xij, yij, zij, ddys)
        ddz = F(xij, yij, zij, ddzs)
        x[i][j] += ddx
        y[i][j] += ddy
        z[i][j] += ddz

The coordinate-update loop evaluates displacement separately along each axis before modifying every model point. section 8.3.4

How Geometry for Programmers covers it

How deep it goes
Defines vector-function deformation, implements inverse-distance interpolation, and applies smooth displacements point by point; it stops short of broader deformation theory.
Examples
Uses randomly perturbed displacement samples, Python listings, and a figure of generated and deformed mushrooms.
What you can do after
Build it from scratch by interpolating displacement vectors and adding them to every model point in Python.
How it connects
Connects deformation to multivariable interpolation, surfaces, geometric objects, and geometric data representations.

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.