2
$\begingroup$

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][[1]] (x - F[px, py][[1]]) + 
       normal[px, py][[2]] (y - F[px, py][[2]]))/normal[px, py][[3]] +
     F[px, py][[3]], {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][[1]] (x - F[px, py][[1]]) + 
     normal[px, py][[2]] (y - F[px, py][[2]]) + 
     normal[px, py][[3]] (z - F[px, py][[3]]) == 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}]
$\endgroup$
2
  • $\begingroup$ You might want to adapt some of the solutions here to your problem. $\endgroup$ Commented Jul 1, 2016 at 18:51
  • $\begingroup$ 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}] $\endgroup$ Commented Jul 2, 2016 at 0:49

1 Answer 1

2
$\begingroup$

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][[1]] (x - F[px, py][[1]]) + 
        normal[px, py][[2]] (y - F[px, py][[2]]))/
     normal[px, py][[3]] + F[px, py][[3]], {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}]
$\endgroup$
3
  • $\begingroup$ I'd go further and swap the order of the torus and the tangent plane myself... $\endgroup$ Commented Jul 1, 2016 at 19:09
  • $\begingroup$ @J.M. Indeed, that is even shorter. $\endgroup$
    – yarchik
    Commented Jul 1, 2016 at 19:11
  • $\begingroup$ 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. $\endgroup$
    – Nikolai
    Commented Jul 1, 2016 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.