Unit Normal for Curves

Let's consider a plane curve. We can write the equation for the curve in the form f(x,y)=0. Then the unit normal vector to the curve is given by grad(f)/||grad(f)||.
You must be careful about outward and inward normals (watch your + and -). To be sure, test the unit normal vector at a point. If it is not going the correct way, make a sign change.

Let's take y=x^2. This can be written as f(x,y)=0 if f(x,y)=x^2-y.


  Clear[f,x,y]
  f[x_,y_]:=x^2-y


  grad2[f][x,y]


  u=grad2[f][x,y]/norm[grad2[f][x,y]]

Let's test at a point.


  u/.x->0

This vector is pointing outward. Let's see if you are not sure.


  vector=vectorPlot[{{0,0}},{u/.x->0}];


  curve=Plot[x^2,{x,-2,2},DisplayFunction->Identity];


  Show[curve,vector,DisplayFunction->$DisplayFunction];

How about x^2+2y^2+x-y=6?


  Clear[f,x,y,u]
  f[x_,y_]:=x^2+2 y^2+x-y-6


  grad2[f][x,y]


  u=grad2[f][x,y]/norm[grad2[f][x,y]]


  utest=u/.{x->2,y->0}


  curve=ImplicitPlot[f[x,y]==0,{x,-3,3},{y,-3,3},
  DisplayFunction->Identity];


  vector=vectorPlot[{{2,0}},{{2,0}+utest}];


  Show[curve,vector,DisplayFunction->$DisplayFunction];

Up to Gradient and Normals to Curves and Surfaces