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]/norm2[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.
Remember, to draw a vector at (x0,y0) in the direction of v=(v1,v2), you plot
(x0+tv1,y0+tv2), t from 0 to 1.


  vector=ParametricPlot[{0,-t}, {t,0,1},
  PlotStyle->{RGBColor[1,0,0]},DisplayFunction->Identity];


  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]/norm2[grad2[f][x,y]]


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


  <<Graphics`ImplicitPlot`


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


  vector=ParametricPlot[{2+t*utest[[1]],0+t*utest[[2]]}, 
  {t,0,1},PlotStyle->{RGBColor[1,0,0]},
  DisplayFunction->Identity];


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

Up to Gradient and Normals to Curves and Surfaces