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
