# Transforming implicit surface (distance field) and their gradient

Transform a 3D field function / distance field and its gradient with a 4x4 matrix - 10/2016 - #Distance Field

\( \renewcommand{\vec}[1]{ \mathbf{#1} } \)

Let \( f:\mathbb R^3 \rightarrow\mathbb R\) be any distance field. We can transform any implicit surface \( f(x,y,z) = c\) with a 4x4 transformation matrix as follows:

$$ \hat f(\vec p) = f( \mathbf T^{-1} \vec p)$$

### Gradient

Sometimes you need to compute the normal of an implicit surface. You usually do this using the gradient \(\nabla f\) which needs to be transformed as well. Similar to the normal of a mesh use the inverse transpose of \( \mathbf T \):

$$ \hat{ \nabla f}(\vec p) = \left ( \mathbf T^{-1} \right )^{T} . \nabla f ( \mathbf T^{-1} \vec p )$$

### Code

float transformed_value_and_gradient(Point pos, Vec3& grad) { Point p = T.inverse() * pos; float field_values = distance_field(p, grad); // original field function value grad = T.inverse().transpose() * grad; return field_values; }

### Special transformations

TODO

- bend
- twist
- ..

No comments