Finding a surface normal of implicit surface f(x,y,z) Let's say that I have some function $f(x,y,z)$ representing an implicit surface.
For instance it might be the equation of a sphere like below, but could also be many other types of functions / shapes.
$f(x,y,z) = (x^2+y^2+z^2)^{0.5} - 0.5 = 0$
If I have a point that I know to be on the surface, what is the correct way to get a vector that is perpendicular to the surface (aka the surface normal)?
I've tried normalizing the vector made up of partial derivatives of x, y and z, but that seems to be failing for some situations.
It's difficult to provide specifics of what is failing specifically, but I'm curious, is that the correct way? or is it a problem that I really have an equation like the below with an implicit variable $w$ that I'm not taking into account in the gradient calculation?
$w=f(x,y,z)$
 A: 
The unit surface normal of the implicit surface $f(x,y,z)=0$ is indeed
the normalized gradient of $f$.  You were also right that the unit 
surface normal of $z=g(x,y)$ is the normalized vector 
$(-g_x \ -g_y \ 1)$ (the cross product of 
$\mathbf{x}_u$ and $\mathbf{x}_v$, with $\mathbf{x} = (x \ y \ z)$ 
and $x=u$ and $y=v$).


Here is a quick proof that the unit surface normal is 
the normalized gradient.
The function $f(x,y, g(x,y))$ is a composition of the mapping $f$
from $\mathbb{R}^3$ to $\mathbb{R}$ and the function $h$ from 
$\mathbb{R}^2$ to $\mathbb{R}^3$ with $h(x,y)= (x,y,g(x,y))$.
The total derivative of this function using the chain rule is
$$
  D(f\circ h) = (Df)(Dh) = (f_x + f_zg_x \ f_y+f_zg_y).
$$
Setting this derivative to zero (since $f\circ h(x,y) = 0$ is the 
definition of the surface) yields $g_x = -f_x/f_z$ and 
$g_y = -f_y/f_z$.  Substituting these values of 
$g_x$ and $g_y$ into $(-g_x \ -g_y \ 1)$
gives $(f_x \ f_y \ f_z) / f_z,$ a multiple of the gradient.

You must have computed the partial derivatives of $f$ incorrectly,
because the unit surface normal of an implicit surface $f(x,y,z)=0$ definitely
is the normalized gradient of $f.$
A: The gradient of $f$ along any vector tangent to the surface must be zero, so that $f$ is constant along the surface. Solving $\vec{v} \cdot \nabla f(x,y,z) = 0$ for two linearly independent vectors $\vec{v}$ span the tangent surface. You can then construct the normal vector using a cross product ($\vec{v}_1 \times \vec{v}_2$).
A: The change of $z$ with respect to moving a unit in the $x$ direction $z_x$. This corresponds vector $\langle 1,0,z_x \rangle$. As for the change in $f$ with respect to moving in the $y$ direction $1$ unit, this is $z_y$. This corresponds to $\langle 0,1,z_y \rangle$.
These two vectors are obviously tangent to the surface and linearly independent. Then taking their cross product, $\langle 1,0,z_x \rangle \times \langle 0,1,z_y \rangle$ should give you (a) normal. Implicit differentiation should work for finding the partials. 
But I suppose that exploiting the fact that gradients are parallel to level curves are easier so that a normal to your surface is $\nabla f$.
Then normalizing what you get should give a correct answer.
