Thanks for your advice, based on that I was able implement surface trimming using a 3D curve (defined in xyz space). I used the code below to convert curve xyz points to uv points.
def dist(uv, surf, xyz):
# surf.evaluate_single raises an exception if it get out of bounds values thereby
# aborting the optimization, so we keep the optimizer away from invalid range by returning a large value
# (probably a gradually increasing error function would be more appropriate, but this simple large value
# seems to work well enough)
if uv[0]<=0 or uv[0]>=1 or uv[1]<=0 or uv[1]>=1:
return 1000
return numpy.linalg.norm(surf.evaluate_single(uv)-xyz)
def uvFromXyz(surf, xyz):
from scipy.optimize import minimize
bounds = Bounds([0, 0], [1.0, 1.0])
res = minimize(lambda uv, surf=surf, xyz=xyz: dist(uv, surf, xyz), np.array([0.5, 0.5]), method='nelder-mead')
return res.x