var('x,y,t,z')
f(x,y)=sin(x)*cos(y)
pif = float(pi)
line_thickness=3
surface_color='blue'
plane_color='purple'
curve_color='red'
tangent_color='green'
surface_opacities = 0.5
@interact
def myfun(location=input_grid(1, 2, default=[0,0], label = "Location (x,y)", width=2), angle=slider(0, 2*pif, label = "Angle"), show_surface=("Show surface", True)):
location3d = vector(location[0]+[0])
location = location3d[0:2]
direction3d = vector(RDF, [cos(angle), sin(angle), 0])
direction=direction3d[0:2]
direction_vector=line3d([location3d, location3d+direction3d], arrow_head=True, rgbcolor=plane_color, thickness=line_thickness)
curve_point = (location+t*direction).list()
curve = parametric_plot(curve_point+[f(*curve_point)], (t,-3,3),color=curve_color,thickness=line_thickness)
plane = parametric_plot((cos(angle)*x,sin(angle)*x,t), (x, -3,3), (t,-3,3),opacity=0.8, color=plane_color)
pt = point3d(location.list()+[0],color='green', size=10)
df = f.gradient()
partialx_arrow = line3d([location3d, location3d[0:3]+vector([1,0,df(*location)[0]])], arrow_head=True, rgbcolor=tangent_color,thickness=line_thickness )
partialy_arrow = line3d([location3d, location3d[0:3]+vector([0,1,df(*location)[1]])], arrow_head=True, rgbcolor=tangent_color,thickness=line_thickness )
tangent_line = parametric_plot((location[0]+t*cos(angle), location[1]+t*sin(angle), f(*location)+t*df(*location)*(direction)), (t, -3,3), thickness=line_thickness, color=tangent_color)
picture = direction_vector+curve+plane+pt+tangent_line
tanplane = plot3d(f(*location) + df(*location)[0]*(x-location[0])+df(*location)[1]*(x-location[1]), (x,-3,3),(y,-3,3),opacity=surface_opacities,color=tangent_color)
if show_surface:
picture += plot3d(f, (x,-3,3),(y,-3,3),opacity=surface_opacities)+tanplane+partialx_arrow+partialy_arrow
show(picture,aspect=[1,1,1], axes=True)