second directional derivative in a volume Having computed the gradient in a discrete volume data set with the help of central differences, I now want to compute the second directional derivative (in direction of the gradient). So as I understand it, this should be the curvature of an isosurface.
Can I do it like this? (pseudo code)
gradX=(value(x-1,y,z)-value(x+1,y,z))/2
gradY=(value(x,y-1,z)-value(x,y+1,z))/2
gradZ=(value(x,y,z-1)-value(x,y,z+1))/2

scndDerX=(gradLength(x-1,y,z)-gradLength(x+1,y,z))/2
scndDerY=(gradLength(x,y-1,z)-gradLength(x,y+1,z))/2
scndDerZ=(gradLength(x,y,z-1)-gradLength(x,y,z+1))/2

grad.normalize();

scndDer.dot(grad);
curvature=scndDer.length;

I'm trying to visualize it, and it just doesn't look quite correct. Therefor I just want to check if the math is alright.
 A: I have just looked up the definition of the second derivative here. According to this document, the $x, y$ and $z$ components must each be defined based on the entire first derivative. You have only defined each component in your second derivative based on the respective component in the first derivative. For example, the $x$ component of the second derivative will be $$\frac{\partial(f_x\, \mathbf{i} + f_y\,\mathbf{j}+ f_z \, \mathbf k)}{\partial x}\mathbf i$$
Here, I am expressing the function as $f$, and the subscript $_x$ or $_y$ or $_z$ indicates to take the derivative of $f$ with respect to that variable. Since $f$ is a function in three dimensions, I have defined it as a vector function. The unit vector in the $x$ direction is denoted $\mathbf i$ (a vector of length $1$), the unit vector in the $y$ direction is $\mathbf j$ and the unit vector for $z$ is $\mathbf{k}$. The $\partial$ sign indicates that we are treating all the $y$'s and $z$'s as constant as we differentiate (in this case) by $x$. Thus, you can see in the above formula that the first derivative (in the numerator: $f_x\, \mathbf{i} + f_y\,\mathbf{j}+ f_z \, \mathbf k$) is a sum of the derivatives of the function in each of these directions - which is the same as what you stated above. However, where you went wrong is to assume that the second derivative of, for example, the $x$ component is $f_{xx}\mathbf i$, where the double $_{xx}$ denotes taking the derivative with respect to $x$ twice. Once you do the $y$ and $z$ components of the second derivative, the final formula will look like:
$$\nabla \nabla f=\frac{\partial(f_x\, \mathbf{i} + f_y\,\mathbf{j}+ f_z \, \mathbf k)}{\partial x}\mathbf i+\frac{\partial(f_x\, \mathbf{i} + f_y\,\mathbf{j}+ f_z \, \mathbf k)}{\partial y}\mathbf j+\frac{\partial(f_x\, \mathbf{i} + f_y\,\mathbf{j}+ f_z \, \mathbf k)}{\partial z}\mathbf k$$
