Code Analysis: International City, Part 2

- categorizing lots and apportioning land use within them according to a distanceToCenter formula
- finding the distanceToCenter calculations on the CityEngine CGA console

This analysis covers lines 58 thru 69 of the International City.cga file.

To show line numbers in rule files within CityEngine, right-click on the rule file window and select Preferences, then check “Show line numbers”.

# Constants

const getType = case distanceToCenter < radiusHighriseArea   :     
     80%: "Highrise Building"  
     15%: "Office Building"      
     2%: "Apartment Building"           
  else: "Open Space"     # mainly highrises and commercial 

case distanceToCenter < radiusCommercialArea :   
    29%: "Highrise Building"  
    60%: "Office Building"     
    10%: "Apartment Building"           
  else: "Open Space"     # mainly offices 

case distanceToCenter < radiusApartmentArea  :   
    20%: "Office Building"    
    76%: "Apartment Building"   
    3%: "Residential"                  
 else: "Open Space"     # mainly apartments
case distanceToCenter < radiusResidentialArea:    
    5%: "Office Building"    
    40%: "Apartment Building"  
    53%: "Residential"                  
 else: "Open Space"     # mainly residential and apartments

else :    
    1%: "Office Building"     
    4%: "Apartment Building"  
    90%: "Residential"                  
 else: "Open Space"     # more or less only residential

const radiusHighriseArea = 500
const radiusCommercialArea = 900
const radiusApartmentArea = 1300
const radiusResidentialArea = 1600
const distanceToCenter  = 
   sqrt(initialShape.origin.px*initialShape.origin.px +initialShape.origin.pz*initialShape.origin.pz)
  • We know it assigns rules to the constant “get type” based on certain conditions because it uses the words “case” and “else.
  • The outcome is based on whether distanceToCenter is less than minimum values for four land use types: radiusHighriseArea, radiusCommercialArea, radiusApartmentArea and radiusResidentialArea.
  • Depending on which of these statements is true, building types or open spaces are assigned to land parcels (lots) in varying proportions (percentages).

The key to understanding how this code works lies in the distanceToCenter constant and how it is calculated. It involves two values, the pivot coordinates px and pz of the initialShape. Again, the formula from the last line of code is:

const distanceToCenter = 
sqrt(initialShape.origin.px*initialShape.origin.px +initialShape.origin.pz*initialShape.origin.pz)

Where can we get these values?  I created a block of lots, applied the cga code "test_0115_coordinate_systems .cgaref.cga" found at the bottom of the CityEngine help file page on Coordinate Systems to two different sized lots in the block and looked at the readout in the CGA Console window -- click the image to see the larger screen shot.

So, let's plug the initialShape.origin.px and .pz values from the console into the distanceToCenter: formula and see what we get:

sqrt(-577 * -577 + 629 * 629) 
sqrt (332929 + 395641) 
sqrt (728570) 
distanceToCenter = 853.56 

sqrt(-617 * -617 + 668 * 668) 
sqrt (380689 + 446224) 
sqrt (826913) distanceToCenter = 909.34

Therefore in CASE...

  • ...the distance to center is less than 500, 80 percent of the lots will have highrise buildings;
  • distance to center is less than 900, 60 percent of the lots will have office buildings;
  • distance to center is less than 1300, 76 percent of the lots will have apartment buildings;
  • distance to center is less than 1600, 53 percent of the lots will be residential space;
  • distance to center is greater than 1600, 90 percent of the lots will be residential space;
  • whatever lots remain unapportioned will be open space

Leave a Reply

Your email address will not be published. Required fields are marked *