%time
var('x,y,z')
p=parametric_plot((x,y,9-x^2-y^2), (x,-3,3), (y,-3,3), mesh=True)
f=x^2-sin(x*y^2)+cos(z)
ff=fast_float(f, 'x', 'y','z')
p.triangulate()
vertices=p.vertex_list()
mesh=[]
for target in [0,2,..,20]:
cache={}
for face in [f+[f[0]] for f in p.index_faces()]:
pts = [calculate_crossing(ff,target,face[i], face[i+1],vertices=vertices, cache_dict=cache) for i in range(len(face)-1)]
pts = [i for i in pts if i is not None]
mesh+=[line([pt1,pt2],thickness=3, color='black') for pt1,pt2 in Subsets(pts, 2)]