I'm experimenting with signed distance functions and constructive solid geometry, and I've came accross a problem I can't wrap my head around.
I have a function for my distance field, that takes a 3D point $x$ and yields a value:
$$f : x \mapsto f(x)$$
Now, my csg object is moving through space. So I represent it's transform by a 4x4 matrix $T$, and it's velocity by a 4x4 matrix $V$. Using a matrix for velocity may be overkilled, but it allows to compute the transform at any moment $t$ using $T + t V$.
Now, let $$g : x, t \mapsto f((T + tV) x)$$ be the value of our signed distance field at any moment $t$, with transform position $T$ and velocity $V$.
We will define the multiplication between a 4x4 matrix and a 3-length vector by expanding our vector to the fourth dimension by adding $1$, computing the matrix-vector product, and then normalizing the 4-length vector by it's 4th component and taking the first 3 values, just like this is done in computer graphics.
Now, my question is: if I know the gradient of $f$, how can I compute the gradient of $g$ ? I'v been trying to write it down without any success. I've seen there is a chain rule that can be expanded to multi variable functions, but even with that I failed.
Edit :
As asked, I've expanded the formulas and looked up the general rule. I'll try to make it clear.
we will rewrite everything using 1D-variables, so using again our functions we have : $$f: x, y, z \mapsto f(x, y, z)$$ $$ h : x, y, z, t \mapsto (T + tV) \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} $$
(where we then normalize by the fourth component, and keep the first three so that this gives us a 3D vector)
$$g: x, y, z, t \mapsto f(h(x,y,z,t))$$
We can then expand the formula for $g$, writing $T_{i, j}$ the $i, j$th elements of T (similarly for V) :
$$g(x, y, z, t) = f \left(\frac{f_1}{f_4}, \frac{f_2}{f_4}, \frac{f_3}{f_4}\right)$$
where :
$$f_i = (T_{i,1} + t V_{i,1}) x + (T_{i,2} + tV_{i,2}) y + (T_{i,3} + t V_{i,3}) z + (T_{i,4} tV_{i,4})$$
Now, the general rule from the provided link states :
$$D_{\mathbf{a}}(f \circ g) = D_{g(\mathbf{a})}f \circ D_{\mathbf{a}}g$$
Now, I have no idea where to go. Because the chain rule explain how to compute derivatives for nested functions, where I feel like what I have is a mapping from $g$ to $f$, but modifying the input variables, I don't see how to apply it.