I am new at Mathematica and I am really confused about drawing a tangent lines and surfaces issues. My teacher wants me to draw a tangent line to specific point of a surface.

The surface equation is $z=x^2 + 2 x y$; the point is (1,3,7) and he wants me to draw a 3 tangent lines which are passing through the that point on $z = x^2 + 2 x y$ surface. He also want to see $z$ surface on the graphic at the same time.

If I am not wrong I've just plotted surface and that point but the tangent lines are still not included correctly:

    F[x_, y_] := x^2 + 2*x*y
 Show[Plot3D[F[x, y], {x, -10, 10}, {y, -10, 10}, 
   PlotStyle -> Opacity[.5], Mesh -> False], 
  Graphics3D[Point[Table[{1, 3, 7}]]]]]

Could anyone can help me for the Mathematica code for this question?


First of all, a little bit of theory here.

After that it's just typing it in. Here is a version, where you can drag the point to wherever you want. It uses, Plot3D for your surface, Graphics3D with InfiniteLine to draw the lines and a ParametricPlot3D to draw the tangent-plane.


Or animated:

enter image description here

With InfinitePlane as suggested by J.M. in the comments:

Slider2D[Dynamic[p], {{-4, -4}, {4, 4}}]
Dynamic[dx = p[[1]]; dy = p[[2]];
 anchorPoint = {dx, dy, dx^2 + 2*dx*dy};
 anchorRules = MapThread[Rule, {{x, y, z}, anchorPoint}];
 xsol = (D[{x, y, (x^2 + 2*x*y)}, x] /. anchorRules);
 ysol = (D[{x, y, (x^2 + 2*x*y)}, y] /. anchorRules);
 Show[Plot3D[x^2 + 2*x*y, {x, -4, 4}, {y, -4, 4}, 
   PlotStyle -> Opacity[0.3, Blue], ImageSize -> 900], 
  Graphics3D[{Black, PointSize[Large], Point[anchorPoint], Thick, 
    InfiniteLine[{anchorPoint, anchorPoint + xsol}], 
    InfiniteLine[{anchorPoint, anchorPoint + ysol}], 
    InfiniteLine[{anchorPoint, anchorPoint + ysol + xsol}], 
    InfiniteLine[{anchorPoint, anchorPoint + ysol - xsol}], 
    Opacity[0.2, Red], 
    InfinitePlane[{anchorPoint, anchorPoint + xsol, 
      anchorPoint + ysol}]}], 
  PlotRange -> {{-4, 4}, {-4, 4}, {-20, 50}}]]
  • $\begingroup$ Neat visualization! I'll have to make note of it for demonstrations of my own! $\endgroup$ – ktm Oct 27 '16 at 18:40
  • 1
    $\begingroup$ InfinitePlane[] should be usable here as well. $\endgroup$ – J. M.'s ennui Mar 26 '17 at 12:10
  • $\begingroup$ Yeah you're right. I updated the anwser. $\endgroup$ – Julien Kluge Mar 26 '17 at 12:20
  • $\begingroup$ You can simplify InfinitePlane[] a bit: InfinitePlane[anchorPoint, {xsol, ysol}]. $\endgroup$ – J. M.'s ennui Mar 27 '17 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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