Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

How to... rounded rectangle?

$
0
0

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?

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles