# Drawing a tangent line to a specific point of a surface?

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
Manipulate[
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.

Slider2D[Dynamic[p],{{-4,-4},{4,4}}]
Dynamic[
dx=p[[1]];dy=p[[2]];
anchorPoint={dx,dy,dx^2+2*dx*dy};
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}]}],
ParametricPlot3D[anchorPoint+x*xsol+y*ysol,{x,-10,10},{y,-10,10},PlotStyle->Opacity[0.1,Red]]
,PlotRange->{{-4,4},{-4,4},{-20,50}}]
]


Or animated:

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}}]]

• Neat visualization! I'll have to make note of it for demonstrations of my own!
– ktm
Commented Oct 27, 2016 at 18:40
• InfinitePlane[] should be usable here as well. Commented Mar 26, 2017 at 12:10
• Yeah you're right. I updated the anwser. Commented Mar 26, 2017 at 12:20
• You can simplify InfinitePlane[] a bit: InfinitePlane[anchorPoint, {xsol, ysol}]. Commented Mar 27, 2017 at 1:08