How to... rounded rectangle?

What would be the simplest way in constrcucting accurate rounded rectangle using ghpython?

I have this as the base (C# Rectangle3d (rounded) - Grasshopper) , what I modified from @PeterFotiadis. I added the separation of X and Y direction “fillets” in order to get consistent diameter on both directions.

import Rhino.Geometry as RG

def createRectangle():
    cornerRadius = 5.0
    length = 48.0
    width = 24.0

    rect = RG.Rectangle3d(RG.Plane.WorldXY, float(length), float(width))
    #implement corner radius
    if cornerRadius>0:
        tx = cornerRadius/length
        ty = cornerRadius/width
        nurbsPts = []
        for i in range(4):
            tdiv0 = i
            nurbsPts.append(rect.PointAt(tdiv0))
            
            if i%2==0: 
                tdiv1 = i+tx
                tdiv2 = i + (1-tx)
            else: 
                tdiv1 = i+ty
                tdiv2 = i + (1-ty)
            nurbsPts.append(rect.PointAt(tdiv1))
            nurbsPts.append(rect.PointAt(tdiv2))
        rect = RG.NurbsCurve.Create(True,3,nurbsPts)
    return rect
    
a = createRectangle()

The issue is at the end with the NurbsCurve.Create(), as this makes a somewhat “sharp” fillets compared to corner arcs. Changing the knot weight does not provide any more accurate results.

How can I most simply get the clean lines+arcs polycurve as the gh component produces?

Depending on “accurate”, the CreateFilletCornersCurve method might be a solution:


240514_FilletCornersCurve_00.gh (7.1 KB)

1 Like

Maybe just make four 90° arcs at the correct coordinates and connect the end points with line segments/join?

1 Like

Thank you @AndersDeleuran and @Helvetosaur
The CreateFilletCornersCurve simplifies the situation a lot.

Here’s the working bare minimum script for posterity:

import Rhino.Geometry

def createRoundedRectangle(plane, length, width, radius=0):
    rect = Rhino.Geometry.Rectangle3d(plane, length, width)
    if radius > 0: rect = Rhino.Geometry.Curve.CreateFilletCornersCurve(rect.ToNurbsCurve(), radius, 0.1,0.1)
    return rect
    
a = createRoundedRectangle(Rhino.Geometry.Plane.WorldXY, 48.0, 24.0, 5.0)
2 Likes

Seems like we can do better - I’ve logged wish for RhinoCommon.

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

– Dale