Rhinoscriptsyntax AddFilletCurve

Hi

I am looking for a Rhinoscriptsyntax function in python 3 for adding a fillet between two curves and trimming the input curves and joining the fillet and remaining curves together.

Basically the rs equivalent to the manual command.

I appreciate there is a rhino common command but I lack experience in this approach so would like to stick to rs commands if possible. If there isn’t such a a command then I shall ask the powers to be why there isn’t as I’m sure other people would need this as well.

Roger

Hi @RogerD,

This should achieve what you are after, I have not tested it on edge cases (no pun intended) and I don’t have the time to but hopefully this will get you what you need, you can select two curves as input and it will fillet to the hardcoded radius

Input:

Output:

#! python 3 
import rhinoscriptsyntax as rs



def FilletAndJoinCurves(radius):
    # Get curves to fillet
    curves = rs.GetObjects("Select curves to fillet", rs.filter.curve, preselect=True)
    if not curves or len(curves) < 2:
        print("At least two curves must be selected")
        return

    curve_id_1 = curves[0]
    curve_id_2 = curves[1]

    # Store curves for joining
    crvs_to_join = []

    # Get fillet points before creating the fillet
    crv_fillet_pts = rs.CurveFilletPoints(curve_id_1, curve_id_2, radius, None, None, True)

    if crv_fillet_pts:
        # Create the fillet
        fillet_curve = rs.AddFilletCurve(curve_id_1, curve_id_2, radius)
        if fillet_curve:
            crvs_to_join.append(fillet_curve)

            # Get parameters on the curves
            param_1 = rs.CurveClosestPoint(curve_id_1, crv_fillet_pts[0])
            param_2 = rs.CurveClosestPoint(curve_id_2, crv_fillet_pts[1])

            # Get the fillet center point (reference point)
            fillet_curve_midpoint = rs.CurveMidPoint(fillet_curve)

            # The correct way to use TrimCurve - create domain intervals
            domain_1 = rs.CurveDomain(curve_id_1)
            domain_2 = rs.CurveDomain(curve_id_2)

            # For first curve, check which segment to keep
            segment1_a_midpoint = rs.EvaluateCurve(curve_id_1, (domain_1[0] + param_1) / 2)
            segment1_b_midpoint = rs.EvaluateCurve(curve_id_1, (param_1 + domain_1[1]) / 2)

            dist1_a = rs.Distance(segment1_a_midpoint, fillet_curve_midpoint)
            dist1_b = rs.Distance(segment1_b_midpoint, fillet_curve_midpoint)

            # Keep segment farther from fillet (reverse the previous logic)
            if dist1_a > dist1_b:
                curve_1_trim = rs.TrimCurve(curve_id_1, (domain_1[0], param_1), True)
            else:
                curve_1_trim = rs.TrimCurve(curve_id_1, (param_1, domain_1[1]), True)

            # For second curve, check which segment to keep
            segment2_a_midpoint = rs.EvaluateCurve(curve_id_2, (domain_2[0] + param_2) / 2)
            segment2_b_midpoint = rs.EvaluateCurve(curve_id_2, (param_2 + domain_2[1]) / 2)

            dist2_a = rs.Distance(segment2_a_midpoint, fillet_curve_midpoint)
            dist2_b = rs.Distance(segment2_b_midpoint, fillet_curve_midpoint)

            # Keep segment farther from fillet (reverse the previous logic)
            if dist2_a > dist2_b:
                curve_2_trim = rs.TrimCurve(curve_id_2, (domain_2[0], param_2), True)
            else:
                curve_2_trim = rs.TrimCurve(curve_id_2, (param_2, domain_2[1]), True)

            if curve_1_trim:
                crvs_to_join.append(curve_1_trim)

            if curve_2_trim:
                crvs_to_join.append(curve_2_trim)

            # Join all curves
            if len(crvs_to_join) >= 2:
                joined_curve = rs.JoinCurves(crvs_to_join, True)
                return joined_curve

    return None


# Run the script
if __name__ == "__main__":
    # Set radius for filleting
    radius = 3
    # Fillet and join the selected curves to specified radius
    FilletAndJoinCurves(radius)
1 Like

Hi Michael,

Many thanks for the reply it is greatly appreciated.

I think I will raise the subject of fillet and join with McNeels as the amount of code and extra work just to join the lines is not justified it really should be an option in the basic rs.AddFilletCurve function.

Regards

Roger

Hi @RogerD,

I’m not sure about Rhinoscriptsyntax but I believe in Rhinocommon it is far simplified within the CreateFilletCurves method:

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.curve/createfilletcurves

Note the additional arguments for join and trim for example.