# Drawing a tangent plane to the torus

I'm trying to draw a torus and a plane tangent to it. Here is my code so far:

F[x_, y_] := {Cos[x] (3 + Cos[y]), Sin[x] (3 + Cos[y]), Sin[y]}
dxF[x_, y_] := D[F[a, b], a] /. {a -> x, b -> y}
dyF[x_, y_] := D[F[a, b], b] /. {a -> x, b -> y}
normal[x_, y_] := Cross[dxF[x, y], dyF[x, y]]
Manipulate[
Show[Plot3D[(normal[px, py][] (x - F[px, py][]) +
normal[px, py][] (y - F[px, py][]))/normal[px, py][] +
F[px, py][], {x, -4, 4}, {y, -4, 4}],
ParametricPlot3D[F[u, t], {t, 0, 2 Pi}, {u, 0, 2 Pi}]], {px, 0,
Pi}, {py, 0.1, Pi/2 - 0.1}]


Not sure how to include the output here. This basically draws a torus and a plane but the plane intersects the torus. For some reason the order of the the arguments of SHOW also makes a big difference in output.

Mathematically this should be pretty simple. I find the normal vector to the torus by taking directional derivatives. Then their cross product is the normal vector $(a,b,c)$ to the tangent plane and the equation $z=\frac{1}{c}(a(x-x_0)+b(y-y_0))+z_0$ defines the plane. What am I doing wrong?

Edit: Just in case somebody comes looking for something like this here is the code I ended up using. I used it as an example in paper to illustrate the concept of tangent spaces.

Manipulate[
Show[ParametricPlot3D[F[u, t], {t, 0, 2 Pi}, {u, 0, 2 Pi},
AxesEdge -> {{-10, 10}, {-10, 10}, {-10, 10}}],
ContourPlot3D[
normal[px, py][] (x - F[px, py][]) +
normal[px, py][] (y - F[px, py][]) +
normal[px, py][] (z - F[px, py][]) == 0, {x, xmin,
xmax}, {y, ymin, ymax}, {z, zmin, zmax},
ContourStyle -> {Opacity[0.5], Blue}],
Graphics3D[{Arrow[{F[px, py], F[px, py] + dxF[px, py]}],
Arrow[{F[px, py], F[px, py] + dyF[px, py]}]}], Boxed -> False,
Axes -> False, PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}], {px, 0,
Pi}, {{py, 0.5}, 0.2, Pi/2 - 0.1}, {{xmin, -5}, -10,
0}, {{ymin, -5}, -10, 0}, {{zmin, -5}, -10, 0}, {{zmax, 3}, 0,
10}, {{ymax, 3}, 0, 10}, {{xmax, 5}, 0, 10}]

• You might want to adapt some of the solutions here to your problem. – J. M.'s ennui Jul 1 '16 at 18:51
• It might interest you to know that Mathematica knows about dot products; thus: ContourPlot3D[normal[px, py].({x, y, z} - F[px, py]) == 0, {x, xmin, xmax}, {y, ymin, ymax}, {z, zmin, zmax}, ContourStyle -> {Opacity[0.5], Blue}] – J. M.'s ennui Jul 2 '16 at 0:49

## 1 Answer

There are just some little mistakes. First your parametric equation of the plane should be $z=-\frac{1}{c}(a(x-x_0)+b(y-y_0))+z_0$. Also, you can adjust AspectRatio and PlotRange for better visibility:

F[x_, y_] := {Cos[x] (3 + Cos[y]), Sin[x] (3 + Cos[y]), Sin[y]}
dxF[x_, y_] := D[F[a, b], a] /. {a -> x, b -> y}
dyF[x_, y_] := D[F[a, b], b] /. {a -> x, b -> y}
normal[x_, y_] := Cross[dxF[x, y], dyF[x, y]]
Manipulate[
Show[Plot3D[-(normal[px, py][] (x - F[px, py][]) +
normal[px, py][] (y - F[px, py][]))/
normal[px, py][] + F[px, py][], {x, -10, 10}, {y, -10, 10},
PlotRange -> {{-5, 5}, {-5, 5}, {-5, 5}}, AspectRatio -> 1,
ClippingStyle -> None],
ParametricPlot3D[F[u, t], {t, 0, 2 Pi}, {u, 0, 2 Pi}]], {px, 0,
2 Pi}, {py, -\[Pi]/2, \[Pi]/2}]

• I'd go further and swap the order of the torus and the tangent plane myself... – J. M.'s ennui Jul 1 '16 at 19:09
• @J.M. Indeed, that is even shorter. – yarchik Jul 1 '16 at 19:11
• Thank you!! I kept working on it and started to gett pretty close by using contourplot to circumvent my horrible arithmetic :P. The PlotRange and AspectRation are a big help as well. – Nikolai Jul 1 '16 at 19:14