brian.wamsley

Fun with Quarter Circles - Rounded Squares

Blog Post created by brian.wamsley on Jan 3, 2020

#CityEngine #quarterCircle #roundedSquares #CGA #roundedBuildings

 

Once again, I'm a new CityEngine user and didn't see anything describing these findings so I'm going to share:

Taking my "quarter circle" (32 sided disc) studies a step further, I developed CGA for a footprint with four 90 degree corners.  I don't know if I did the best coding ever (more on that) but I got the result I intended in the end.  The code works on squares, rectangles and even circles(?).  But not on oddly angled rectangles or triangles (see bottom and bottom left).  I think this code would work well inside of another "grided" code (x and z splits so that it's all very "sqaure").

 

To create these shapes I used the primitiveDisc splits as described in my first post.  But each corner gave me some problems so I separated them individually "Z1,Z2,Z3,Z4" and tweaked any translation/pivot issues individually.

 

Rounded corners on various footprint shapes

 

/**
* File:    FourBldgCorners.cga
* Created: 17 Dec 2019 20:40:03 GMT
* Author:  bwamsley
*/

version "2019.1"

///////////////
##Attributes
@Range(min=1,max=100, restricted = false)
attr CornerBendRadius = 20
@Range(min=1,max=100, restricted = false)
attr BuildingH = 20
@Range(min=1,max=100, restricted = false)
attr CornerH = 20

################################
@Start

Footprint-->
     alignScopeToGeometry(yUp,0,0)
     FootprintSplit
     
FootprintSplit-->     
     split(x){CornerBendRadius: CornerBendX1
               |~1                    :  BuildingWidth
               |CornerBendRadius: CornerBendX2}
               
CornerBendX1-->
     split(z){CornerBendRadius: CornerBendZ1
               |~1                    :  BuildingWidth
               |CornerBendRadius: CornerBendZ2}
               
CornerBendX2-->
     split(z){CornerBendRadius: CornerBendZ3
               |~1                    :  BuildingWidth
               |CornerBendRadius: CornerBendZ4}               
               
/////CornerZ1 (DARK BLUE)
CornerBendZ1-->
     primitiveDisk(32)
     CircleZ1

CircleZ1-->     
     color(0,0,1)
     split(x){'.5 : halfCircleZ1
     |'.5 : NIL}
     
halfCircleZ1-->
     split(z){'.5 : quarterCircle1
     |'.5 : NIL}     
     
quarterCircle1-->
     setPivot(xyz,2)
     t(-(CornerBendRadius/2),0,-(CornerBendRadius/2))
     s(CornerBendRadius,0,CornerBendRadius)
     BuildingCurve               

/////CornerZ2 (TEAL)
     
CornerBendZ2-->
     primitiveDisk(32)
     CircleB
     
CircleB-->     
     color(0,1,1)
     split(x){'.5 : halfCircleZ2
     |'.5 : NIL}
     
halfCircleZ2-->
     split(z){'.5 : NIL
     |'.5 : quarterCircle2}
     
quarterCircle2-->
     setPivot(xyz,1)
     t(-(CornerBendRadius/2),0,-(CornerBendRadius/2))
     s(CornerBendRadius,0,CornerBendRadius)
     BuildingCurve          

/////CornerZ3 (RED)

CornerBendZ3-->
     primitiveDisk(32)
     CircleC
     
CircleC-->     
     color(2,0,0)
     split(x){'.5 : NIL
     |'.5 : halfCircleZ3}
     
halfCircleZ3-->
     split(z){'.5 : quarterCircle3
     |'.5 : NIL}     

quarterCircle3-->
     setPivot(xyz,3)
     t(-(CornerBendRadius/2),0,-(CornerBendRadius/2))
     s(CornerBendRadius,0,CornerBendRadius)
     BuildingCurve               
     
/////CornerZ4 (PURPLE)     
     
CornerBendZ4-->
     primitiveDisk(32)
     CircleD
     
CircleD-->     
     color(1,0,1)
     split(x){'.5 : NIL
     |'.5 : halfCircleZ4}
     
halfCircleZ4-->
     split(z){'.5 : NIL
     |'.5 : quarterCircle4}
     
quarterCircle4-->
     t(-(CornerBendRadius/2),0,-(CornerBendRadius/2))
     s(CornerBendRadius,0,CornerBendRadius)
     BuildingCurve
     
BuildingCurve-->
     extrude(CornerH)     
     
BuildingWidth-->
     color("#E3CF57")
     extrude(BuildingH)

 

If any one knows of a better way to organize the scopes and pivots to simplify my code, I would be grateful to learn.

 

Hope this helps some one!!

Outcomes