Half Circle with Curb - aka "Median Curb Maker"

407
2
01-02-2020 10:40 AM
BrianWamsley
Occasional Contributor II
0 2 407

#CityEngine #halfCircle #parkinglot #quartercircle #CGA

Looks like this:

Half circles from different size squares

Hi all, I am pretty new to CityEngine but I learned something that I didn't see any where else.   How to make a trimmed half circle, in my case for parking lots and medians.

At first, I looked at the complete street code but never found out how it was creating the medians here:

complete street median example

I think those are created by the "street graphing" but I am not totally sure.  I noticed that the texturing in the half-circle-top was always just concrete (not the offset curb with grass effect I was looking for).

To start, I used a 32 sided primitiveDisk, which makes a good looking "circle".  I applied the curb offset first, wondering how it would handle the longest edge, as I wanted that discarded.     I divided it in half using a '50/50 relative' split along the x axis, and discarded the unused half with a NIL.  Next step is offsetting the object by half the length of the starting object using the translate function and moving it -scope.sx/2.   And the last trick was finding the right face, which in my code I use a 32 sided disk split in half, which produces 18 faces after the offset.  I used a comp(f) function for all 18 faces but then made face #17 (the one I wanted) a different shape.  (Code below)

/**
* File: HalfCirclewCurb.cga
* Created: 2 Jan 2020 14:32:08 GMT
* Author: bwamsley
*/

version "2019.1"

const Shift = (scope.sx /2)

@Start

halfCircleSpace-->
alignScopeToGeometry(yUp,0,0)
primitiveDisk(32)
Circle

Circle-->
offset(-1)
split(x){'.5 : NIL
|'.5 : halfCircle}

halfCircle-->
translate(rel,scope,-Shift,0,0)
curbMaker

pavement-->
color(0,1,0)

curbMaker-->
comp(f){17: pavement2
|0 : curb
|1 : curb
|2 : curb
|3 : curb
|4 : curb
|5 : curb
|6 : curb
|7 : curb
|8 : curb
|9 : curb
|10 : curb
|11 : curb
|12 : curb
|13 : curb
|14 : curb
|15 : curb
|16 : curb}


pavement2-->
color(0,1,1)

curb-->
extrude(1)
color(0,0,1)


SquareSpace-->
comp(f){top: textureTop
|side: Sides.}

textureTop-->
split(x){1: curb
|~1: curbTexture
|1: curb}

curbTexture-->
color(0,2,1)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I intend to incorporate this into my parking lot code which is growing in complexity each day:

This picture of my parking lot does not have the half circle with curb yet, but it will once I get my "splits" and conditional rules all set up.  

Parking Lot Code result

Next Steps:

I'm curious if I can use another split, translate and/or scale function to create a quarter circle.

Also curious if I can use the scale function to fill the "circleSpace" back up to full (instead of half).

So even though we don't have arc functions yet, I believe there is still a lot that can be done with half circles (and maybe quarter-circles).

Hope this helps someone!

Update: Quarter Circle

Quarter Circle

/**
* File: QuarterCirclewCurb.cga
* Created: 2 Jan 2020 14:32:08 GMT
* Author: bwamsley
*/

version "2019.1"

const ShiftX = (scope.sx /2)
const ShiftZ = (scope.sz /2)

@Start

halfCircleSpace-->
alignScopeToGeometry(yUp,0,0)
primitiveDisk(32)
Circle

Circle-->
offset(-1)
split(x){'.5 : NIL
|'.5 : halfCircle}

halfCircle-->
split(z){'.5 : NIL
|'.5 : quarterCircle}

quarterCircle-->
translate(rel,scope,-ShiftX,0,-ShiftZ)
curbMaker

curbMaker-->
comp(f){0 : curb
|1 : curb
|2 : curb
|3 : curb
|4 : curb
|5 : curb
|6 : curb
|7 : curb
|8 : curb
|9 : GrassyArea}


GrassyArea-->
color(0,1,1)

curb-->
extrude(1)
color(0,0,1)



‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Update#2

Adding a simple s(ShiftX*2,0,ShiftZ*2) under the translate produces this:

quarterCircle-->	
translate(rel,scope,-ShiftX,0,-ShiftZ)
s(ShiftX*2,0,ShiftZ*2)
curbMaker

QuarterCircleScaledUp

Imagine the possibilities for this guy!!!   Building sidewalk borders, planter borders, etc.

Extra:  parking lot with half circles with curbs (need to tweak the textures still).

Parking Example with Half Circle

2 Comments
BernhardRainer1
New Contributor III

I have played around with a similar technique, however I found that aligning the scope to geometry heavily depends on the geometry and can not be generalized easily. 

alignScopeToGeometry(yUp,0,0) # Pray that the first edge/face is the correct one

Therefore I am using a different approach that utilizes the uv space rather than the actual sope.

  1. Make the desired geometry shape in a modeling program (e.g. blender) and export it as fbx.
  2. Perform multiple uv splits to extract the footprint of the shape
  3. Normalize the uvs such that the entire footprint covers one uv tile ( e.g. from 0 to 1 n both directions) * 
  4. insert the shape via insertAlongUV(...) 

* Or use any other sub area of the uv space to cut parts away from the geometry. 

BrianWamsley
Occasional Contributor II

Thanks!  

I considered an insert "arc-shape" model work flow but I hadn't gone in that direction yet.  Sounds like I should try!  

My only hesitation was that my end goal was an offset curb and I wasn't sure how I could texture the curb separately from the interior space.  Also, I want to add a stormwater calculator into my parking code at the end so I wanted to try to use CGA's geometry tools as much as possible.  Though I suppose its easily possible to take the square geometry area of the "half-circle space" and apply math to it manually, if needed.  

Alternatively, I wondered if there might be a python script using Shapely tools that could use the selected object and then run what ever shape processes, like "rounding", "simplifying" or what ever.  I have not identified that script yet and have not run in any scripts in City Engine to know how that process goes.