How can I compute the gradient for a tetrahedral mesh (3D)? For triangular mesh, I got an answer from the following post Calculating the gradient of a triangular mesh
How can I get a similar formula for 3D mesh?
Thanks in advance.
Computer Graphics Stack Exchange is a question and answer site for computer graphics researchers and programmers. It only takes a minute to sign up.Sign up to join this community
Assuming a value is assigned to each vertex of the mesh and we use purely linear interpolation, then there will be a constant gradient vector within each tetrahedron.
Linear interpolation can be expressed using barycentric coordinates, like $$ f(x,y,z) = f_1 w_1(x,y,z) + f_2 w_2(x,y,z) + f_3 w_3(x,y,z) + f_4 w_4(x,y,z) $$ where $f_1 \ldots f_4$ are the values of the function at the four vertices, and $w_1 \ldots w_4$ are the barycentric weights for each vertex. Then, finding the gradient of $f$ reduces to finding the gradients of all of the weights.
This can be worked out geometrically by noting that each $w_i$ is 1 at the $i$th vertex, falling off to 0 at the plane formed by the other three vertices. The gradient vector will therefore be normal to that plane, pointing back towards the $i$th vertex, with a magnitude equal to 1 / the distance from the plane to the vertex.
Once you've calculated those barycentric gradients, you can multiply them by $f_1 \ldots f_4$ and sum them up to arrive at the gradient of $f$ overall.
This reasoning works for triangles too, by the way, only replace "plane" with "line".