Invoking "match" command (for curves) possible from python?

Is there a way to execute the command to match two curves (e.g., their curvature) fully from python? My use case is I have a python script that generates two splines that are connected at one end, and I want to match the curvature (the script does this multiple times).

I can’t find anything in rhinoscriptsyntax. I poked around a bit in RhinoScript and didn’t see anything either. Maybe it’s possible via some form of rs.Command("_Match …"), but I’m not sure how to programatically specify the curves.

The only other idea I had was to modify the curves to be a bit shorter and not quite touch and then invoke rs.AddBlendCurve(), but that seems klunky.

Any suggestions?
Thanks,
Josh

Scripting the Match command won’t be possible, as the command works based on where you pick on the input curves. And there is no way to script this kind of picking.

It does appear that the code behind Match is exposed on the SDK. I’ll add a wish list item to get his wrapped in RhinoCommon and Python.

– Dale

Hi Dale, doesn’t AddBlendCurve have a similar issue about picking the curve ends? You just use rs.CurveDomain() to specify which end of both curves you want the operation to apply to. Or am I missing something?
Josh

I presume you can get all the point data from the curves and then modify their positions.
In other words program your own “match”.

Here is a dummy script that closes a curve if it has more than 3 control points.



import rhinoscriptsyntax as rs
obj = rs.GetObject("Select curve", rs.filter.curve)

if obj:
    rs.EnableObjectGrips( obj, enable=True )
    points = rs.ObjectGripLocations(obj)
    if len(points)>3:
        points[len(points)-1]=points[0]
        rs.ObjectGripLocations(obj,points)
    rs.EnableObjectGrips( obj, enable=False )

You have to rewrite it to work on two curves, find the “mean point”, move the end points to that location, and the “mean direction” for the match and then move the points next to the ends to that mean direction.

Hi Holo,
Do you know how to modify the control points to get the curvature of the end of one curve to match the other one? My NURBS knowledge isn’t super strong.

Hi Dale,
There are a couple of other functions that seem to be missing from python that I’d like to use in my project. How hard would it be to code something using the SDK to make those functions available in python? I’m a software engineer so am open to a bit of hacking…
Josh

I am neither a Nurbs nerd, but I found this and presume MIT has more on the topic.

MIT managed to make that topic really appealing:

I assume you are referring to this RhinoScript method:

http://4.rhino3d.com/5/rhinoscript/curve_methods/addblendcurve.htm

To answer your question about picking, the answer is not. AddBlendCurve requries that you pass in parameters on the two curves that will be used as the blend curve end points

If you are using C++, you can use RhinoSdkBlend::CurveBlend. However, this may not produce the same results as Rhino’s Match command.

Hi Dale,
I was referring to the rhino-python method rs.AddBlendCurve, which maybe is the same as the RhinoScript method. Is there any documentation on RhinoSdkBlend::CurveBlend beyond http://4.rhino3d.com/5/rhinocppsdk/RhinoSdkBlend__CurveBlend@ON_Curve_@double@bool@int@ON_Curve_@double@bool@int.html ? That page sounds like it adds a new curve rather than modifying existing ones.
Josh

Here are the comments from the Rhino C++ SDK:

/*
  Description
    Makes a curve blend between 2 curves at the parameters specified
      with the directions and continuities specified
  Parameters:
    [in] pC0         - First curve to blend from
    [in] t0          - Parameter on first curve for blend endpoint
    [in] bRev0       - if bRev0 is false, the blend will go in the natural direction of the curve
                       if bRev0 is true, the blend will go in the opposite direction to the curve
    [in] continuity0 - continuity for the blend at the start
                           0: position
                           1: tangency
                           2: curvature
    [in] pC1         - Second curve to blend from
    [in] t1          - Parameter on second curve for blend endpoint
    [in] bRev1       - if bRev1 is false, the blend will go in the natural direction of the curve
                       if bRev1 is true, the blend will go in the opposite direction to the curve
    [in] continuity1 - continuity for the blend at the end
                           0: position
                           1: tangency
                           2: curvature
  Returns:
    The blend as an ON_Curve if successful
    NULL if not
*/

Hi @dale, trying to match one curve end to another but cannot find a method to do this in RhinoCommon or python with the same logic as the match command. Has this been added ?

Is it NurbsCurve.SetEndCondition ?

thanks,
c.

Hey @clement,

There is a new Curve.CreateMatchCurve that hasn’t made it into the API documentation yet.

https://mcneel.myjetbrains.com/youtrack/issue/RH-27368

Does this help?

– Dale

2 Likes

Thanks @dale, i’ll try it.

_
c.