[048] Understanding the rotate() Command in Esri CityEngine CGA

Learn how to manipulate 3D geometry coordinates using the rotate() command and understand how rule execution order impacts procedural outcomes.

This tutorial explores the rotate() command in CityEngine CGA, highlighting its similarities to translate() while warning of the complexities involved in 3D rotation. We discuss the importance of coordinate systems and provide a practical exercise to observe how swapping command orders changes model orientation.

rotate() works in much the same way as translate(). There is not much to explain separately.

CityEngine rotate command reference
img 1 : https://doc.arcgis.com/en/cityengine/latest/cga/cga-rotate.htm

As you can see from the reference above, it functions just like translate().

However!!

Why Rotation Can Be Difficult in CGA

Unlike translation, rotation is quite difficult to grasp intuitively.

This happens because when rotation, scale, and translation commands are combined, the transformation result changes depending on the order of execution and the selected mode and coordSystem.

How Transformation Order Changes the Result

To properly understand this behavior, you first need to understand concepts such as axis, scope, and pivot.

A tip I can give you is to learn this through experience while focusing your coding on the rotation methods you find easiest to understand.

Study the example below and try to get familiar with how the transformations behave.


@Order(0)
@Enum("abs","rel",restricted=true)
attr mode = "abs"
# Set the rotation mode (absolute or relative)

@Order(1)
@Enum("scope", "pivot", "object", "world",restricted=true)
attr coordSys = "scope"
# Set the coordinate system to use as a reference

@Order(2) @Angle
attr xAngle = 0
@Order(3) @Angle
attr yAngle = 0
@Order(4) @Angle
attr zAngle = 0
# Set rotation values for X, Y, and Z-axes

Lot -->
  extrude(10) # Create initial height
  comp(f){top : A | all = X.} # Extract top face and pass to rule 'A'

A -->
  t(20,0,0) # Move 20m along the X-axis
  rotate(mode, coordSys, xAngle, yAngle, zAngle) # Execute rotation
  extrude(10) # Extrude again based on the rotated coordinate system
  X.

The code above allows you to verify the results while changing the mode, selector, and coordinates.

There is no video for today's lesson. :)

Practice with rotate() and t()

Try coding the example above yourself. Then, try swapping the order of t() on line 32 and rotate() on line 34, save it, and see what kind of difference it makes.

At this point, we have gone through the basic commands used to create procedural forms.

To summarize...

We use split() to divide faces, extrude() to give height, and comp() to separate components.

We use index and case...else to select specific elements.

We use t() and translate() to adjust position, s() to adjust size, and r() and rotate() to adjust rotation.

And we touched upon the fundamental concept of scope.

Preparing for Axis, Scope, and Pivot

The explanation of basic concepts is finished.

Before moving on to more practical CGA coding workflows, we will briefly go over precautions and tips for coding.

Then, we will deal with axis, scope, and pivot, which are the most important parts of CGA.

I have covered them briefly during the lectures, but only to the extent necessary for the lesson level.

Since these three elements are invisible, they are difficult to explain from a teacher's perspective and difficult to understand from a student's perspective.

Since I need to concentrate on field work until March, it will be difficult to upload new posts. In the meantime, please browse through the following topics in advance:

alignScopeToAxes(),

alignScopeToGeometry(),

alignScopeToGeometryBBox(),

center(),

mirrorScope(),

rotateScope(),

setPivot().

It's okay if you don't understand them yet. Just take a look.

“Our success as a species came not from conquering enemies, but from making friends.”
— Brian Hare & Vanessa Woods,
Survival of the Friendliest
Continue Learning
Explore complete tutorial collections for CityEngine and Global Mapper.

Comments

Popular posts from this blog

029] How to Split Polygon Areas with Intersecting Lines in Global Mapper

[008] How to Understand CGA Rule Structure in CityEngine (Beginner Guide)

046] How to Create Parallel Offset Lines in Global Mapper