Specify trimming curve in 3D space

126 views
Skip to first unread message

Andras Lasso

unread,
Nov 11, 2020, 4:04:43 PM11/11/20
to NURBS-Python
Dear Onur,

Thank you very much for providing this awesome package. I could successfully use it for creating smooth, editable surface models of pediatric heart valve leaflets. While some leaflets can be represented well with a full spline surface, others would require trimming.

I have the trimming curve points specified in 3D, but geomdl.NURBS.Surface.trims require point coordinates to be in UV coordinates. I understand that in general it is a very hard problem to find closest surface point to a 3D position (invert "evaluate"), but I have a quite simple "Pringles" shape surface and the trimming points are very close to the surface, so most likely a simple iterative method could find the optimal UV coordinate.

Can you give any advice or example of how a "uv = find_closest_point_on_surface(xyz)" method could be implemented?

Thank you,
Andras Lasso
Senior Research Engineer
PerkLab, School of Computing
Queen's University, Kingston, ON, Canada

Onur Bingol

unread,
Nov 11, 2020, 5:26:47 PM11/11/20
to nurbs-python
Hi Andras,

Some time ago, I received an email from a geomdl user who wanted to find uv from xyz (3D points on the surface or curve), and he had some success using SciPy's optimize.minimize (https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html). I am not sure how he implemented that (I don't have the code), I suppose he used the result of "evaluate_single" method somewhere in the optimization function.

I hope this helps a bit.

Thanks,
Onur



---- On Wed, 11 Nov 2020 13:04:43 -0800 Andras Lasso <andra...@gmail.com> wrote ----

--
You received this message because you are subscribed to the Google Groups "NURBS-Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nurbs-python...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nurbs-python/2a6af57c-0691-4886-b192-becdd128a211n%40googlegroups.com.


Andras Lasso

unread,
Jan 13, 2021, 12:13:03 AM1/13/21
to NURBS-Python
Hi Onur,

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.

Andras


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


Onur Bingol

unread,
Jan 14, 2021, 3:16:28 AM1/14/21
to nurbs-python
Thanks for sharing the code, Andras!

---- On Tue, 12 Jan 2021 21:13:02 -0800 Andras Lasso <andra...@gmail.com> wrote ----

Reply all
Reply to author
Forward
0 new messages