Curves in space

Torsion and curvature are useful descriptor of a curve in 3 space. In fact for nondegenerate curves the torsion and curvature functions uniquely describe a curve. This first section of the notebook plots the Frenet frame and gives the torsion and curvature at point. We use the manipulate function to move the point we are looking at.  The bounds and the component functions x, y, and z are all that needs to be changed, everything else will follow.

lowert=0;
uppert=2Pi;
x[t_]=2Cos[t];
y[t_]=2Sin[t];
z[t_]=t;
f[t_]={x[t],y[t],z[t]};
T[t_]=Normalize[f'[t]];
NN[t_]=Normalize[T'[t]];
B[t_]=Cross[T[t],NN[t]];
K[t_]=Norm[Cross[f'[t],f''[t]]]/Norm[f'[t]]^3;
tors[t_]= Cross[f'[t],f''[t]].f'''[t]/Norm[Cross[f'[t],f''[t]]]^2;

T[t_]=FullSimplify[T[t],Element[t,Reals]];
NN[t_]=FullSimplify[NN[t],Element[t,Reals]];
B[t_]=FullSimplify[B[t],Element[t,Reals]];
K[t_]=FullSimplify[K[t],Element[t,Reals]];

fplot=ParametricPlot3D[f[t],{t,lowert,uppert},PlotRange->All, PlotRangePadding->1];
Manipulate[Show[fplot,ParametricPlot3D[{f[u]+s T[u],f[u]+s NN[u],f[u] + s B[u]},{s,0,1}],Graphics3D[Text[Torsion:  tors[u],{0,0,0}]],Graphics3D[Text[Curvature:  K[u], {-1,-1,-1}]]],{u,lowert,uppert}]

Surfaces in 3 space

The easiest way to define a surface is by giving the height as a function of x and y. For instance, in this first section, you can change the bounds and definition of f, then evaluate the cell. The manipulate command is extremely useful. The manipulate function allows you to change the x and y where you want the normal vector and tangent plane.

lowerx=-2;
upperx=2;
lowery=-2;
uppery=2;
f[x_,y_]=x^2-y^2;
tangentf[x_,y_]= {Normalize[{1,0,D[f[x,y],x]}],Normalize[{0,1,D[f[x,y],y]}]};
normalf[x_,y_]=Normalize[Cross[tangentf[x,y][[1]],tangentf[x,y][[2]]]];
Manipulate[Show[Plot3D[f[x,y],{x,-2,2},{y,-2,2},PlotRange->All],ParametricPlot3D[{x,y,f[x,y]}+s normalf[x,y],{s,0,1}],ParametricPlot3D[{x,y,f[x,y]}+s tangentf[x,y][[1]] + t tangentf[x,y][[2]],{s,-.5,.5},{t,-.5,.5}]],{x,-2,2},{y,-2,2}]

A little bit more general way of defining a surface is by a parametric equation. Mathematica was taking a long time to evalute this next cell before I added the FullSimplify commands. It was because it was dealing with cases we don't care about, namely when s and t are complex. This didn't occur when I was testing the code above, but if Mathematica is having trouble, you might try making it do a FullSimplify restricting your variables to the region your interested in.

lowers=0;
uppers=Pi;
lowert=0;
uppert=2Pi;
x[s_,t_]:= Cos[t]Sin[s];
y[s_,t_]:= Sin[t]Sin[s];
z[s_,t_]:= Cos[s];
f[s_,t_]:={x[s,t],y[s,t],z[s,t]};
fs[s_,t_]=FullSimplify[Normalize[D[f[s,t],s]],Element[s,Reals]&&Element[t,Reals]&& lowers≤s≤uppers && lowert ≤t≤uppert];
ft[s_,t_]=FullSimplify[Normalize[D[f[s,t],t]],Element[s,Reals]&&Element[t,Reals]&& lowers≤s≤uppers && lowert ≤t≤uppert];
Nf[s_,t_]=FullSimplify[Normalize[FullSimplify[Cross[fs[s,t],ft[s,t]],Element[s,Reals]&&Element[t,Reals]&& lowers≤s≤uppers && lowert ≤t≤uppert ]],Element[s,Reals]&&Element[t,Reals]&& lowers≤s≤uppers && lowert ≤t≤uppert ];
fplot=ParametricPlot3D[{f[s,t],{0,0,2}},{s,lowers,uppers},{t,lowert,uppert},PlotRange->{-2,2},BoxRatios->{1,1,1}];
Manipulate[Show[
fplot,ParametricPlot3D[f[u,v]+s Nf[u,v],{s,0,1},PlotRange->{-2,2},BoxRatios->{1,1,1}],ParametricPlot3D[f[u,v]+s fs[u,v]+t ft[u,v],{s,-.5,.5},{t,-.5,.5},PlotRange->{-2,2},BoxRatios->{1,1,1},PlotPoints->50,Mesh->None]],{u,lowers,uppers},{v,lowert,uppert}]

We can do a similar process for surfaces given by an equation F(x,y,z)=0. Unfortunately, there is not a tidy way to move around on a general surface so we have to know a specific point on the surface to plot its normal vector and tangent plane.

F[x_,y_,z_]= x^2+y^2+z^4 - 1;
gradF[x_,y_,z_]=Normalize[{D[F[x,y,z],x],D[F[x,y,z],y],D[F[x,y,z],z]}];
tangentF[x_,y_,z_]=Orthogonalize[NullSpace[{gradF[x,y,z]}]];
plotTangentAndNormal[a_,b_,c_]=If[F[a,b,c]==0,Show[ContourPlot3D[F[x,y,z]==0,{x,-2,2},{y,-2,2},{z,-2,2}],ParametricPlot3D[{a,b,c}+s gradF[a,b,c],{s,0,1}],ParametricPlot3D[{a,b,c}+s tangentF[a,b,c][[1]]+t tangentF[a,b,c][[2]],{s,-.5,.5},{t,-.5,.5}]],Print["Point not on surface."]];

plotTangentAndNormal[.5,.5,1/2^(1/4)]