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.

In[178]:=

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

In[179]:=

  grad2[f][x,y]

Out[179]=

  {2 x, -1}

In[180]:=

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

Out[180]=

        2 x                1
  {--------------, -(--------------)}
               2                 2
   Sqrt[1 + 4 x ]    Sqrt[1 + 4 x ]

Let's test at a point.

In[181]:=

  u/.x->0

Out[181]=

  {0, -1}

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

In[182]:=

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

In[183]:=

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

In[184]:=

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

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

In[185]:=

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

In[186]:=

  grad2[f][x,y]

Out[186]=

  {1 + 2 x, -1 + 4 y}

In[187]:=

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

Out[187]=

              1 + 2 x
  {------------------------------, 
                 2             2
   Sqrt[(1 + 2 x)  + (-1 + 4 y) ]
   
               -1 + 4 y
    ------------------------------}
                  2             2
    Sqrt[(1 + 2 x)  + (-1 + 4 y) ]

In[188]:=

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

Out[188]=

      5           1
  {--------, -(--------)}
   Sqrt[26]    Sqrt[26]

In[189]:=

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

In[190]:=

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

In[191]:=

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

Up to Gradient and Normals to Curves and Surfaces