[045] Understanding the translate() Command in CityEngine CGA

Precisely control asset positioning by understanding absolute and relative movement across different coordinate systems.

This tutorial explains the 4-parameter translate() command in CGA. We explore how "abs" and "rel" modes interact with World, Pivot, and Scope coordinate systems, accompanied by video demonstrations to visualize how 3D assets shift within the procedural environment.

    Syntax and Parameters of translate()

    Let's look at the reference.

    CityEngine Translate Reference Documentation
    img 1 : CGA Translate Documentation Reference

    It uses a total of four parameters.

    mode determines whether to use absolute (abs) or relative (rel) coordinates.

    coordSystem determines the coordinate system (one of scope, object, world, or pivot coordinate systems).

    x, y, z define movement along the selected coordinate system. In rel mode, they represent movement distances. In abs mode, they represent positions relative to the coordinate system origin.

    Dynamic Testing with CGA Attribute Rules

    
    /**
     * Translation and Rotation Testing Rule
     * This code allows for direct testing of coordinate systems via the Inspector.
     */
    
    @Order(1)
    @Enum("abs", "rel", restricted=true) # Select absolute or relative position mode
    attr mode = "rel"
    
    @Order(2)
    @Enum("world", "object", "pivot", "scope", restricted=true) # Select coordinate system
    attr crd_sys = "scope"
    
    @Order(3)
    @Angle
    attr rotate_Scope = 0 # Rotation angle of the scope
    
    @Order(4)
    @Range(min=0, max=30) # Adjustment range from 0 to 30
    attr x_distance = 0 # Movement distance along X axis
    
    Lot1 -->
        # Extrude by height of 10
        extrude(10) 
        # Rotate scope using the attribute variable
        rotateScope(0, rotate_Scope, 0) 
        # Adjust X-coordinate position using the variable
        translate(mode, crd_sys, x_distance, 0, 0)
    

    The code above was created so that you can check the results while changing the mode, coordSystem, and coordinates directly in the Inspector.

    The items written after the @ symbol are called annotations, which define metadata and UI behavior for attributes (attr).

    Coordinate Systems in CityEngine

    CityEngine Coordinate Systems Overview
    img 3 : Basic form and coordinate systems overview

    The basic form is as shown in the picture above.

    If we check the origin of each coordinate system in the current state: the large axes surrounding the box are the scope axes, the small axes in one corner are the pivot axes, and the location where the thick lines of the grid intersect across the entire screen is the world axes.

     

    While watching the videos, pay close attention to how the position of the model changes when mode and coordSystem are modified.

     

    Case Studies: Translation Modes (abs vs rel)

    World Coordinate System (Video 1 & 2)

    The first is abs, world s, world : Jump to world origin, then move.

    Video 1: CityEngine translate(abs, world) demonstration

    The moment abs, world is selected, the scope origin coincides with the world origin (0,0,0).

    In that state, if you move it along the X-axis, it moves in the direction of the world's X-axis from the origin by that value.

     

    The second is rel, world : Move relative to current position along world axes.

    Video 2: CityEngine translate(rel, world) demonstration

    In abs, the model was moved to the origin and then moved in the direction of the world axes. In rel, it doesn't care about the world origin and simply moves from its current position along the world's axis directions.

     

    The third is movement in the object coordinate system.

    Video 3: CityEngine translate(abs, object) demonstration

    I still do not fully understand how this coordinate system behaves.

    If the scope is not in a rotated state, it moves using the pivot axis of the highest-level shape. However, When the scope is rotated, however, the movement behaves differently than I expected. Because of that, I rarely use this coordinate system in practice.

    If you happen to know, please leave a comment.

     

    Pivot & Scope Coordinate Systems (Video 4, 5, 6, 7)

    - abs/rel, pivot : Translation based on the pivot origin and axes.

    The fourth is abs, pivot.

    Video 4: CityEngine translate(abs, pivot) demonstration

    Once abs is selected, you can consider that the model will jump. Here, because abs and the pivot coordinate system were selected, the model's scope origin moves to the pivot's origin and then moves along the axis directions based on the pivot origin.

     

    The fifth is rel, pivot.

    Video 5: CityEngine translate(rel, pivot) demonstration

    When rel is selected, the model maintains its position and moves along the axis directions of the selected coordinate system.

     

    - abs/rel, scope : Translation based on the scope axes (affected by rotateScope).

    The sixth is abs, scope.

    Video 6: CityEngine translate(abs, scope) demonstration

    In abs mode, translation starts from the pivot origin. Because it uses the scope coordinate system, the direction of movement follows the scope axes surrounding the model. Therefore, if you rotate the scope, the direction of movement also changes.

     

    The seventh is rel, scope.

    Video 7: CityEngine translate(rel, scope) demonstration

    Since the mode is rel, the model maintains its current position and moves based on the scope's axis directions. If the scope is rotated and the axis direction changes, it moves in the changed axis direction.

     The explanation of translate() is finished.

    It can be briefly summarized as follows.

    Summary of translate() Coordinate Behavior

    Coord System Mode Characteristics
    abs rel
    world Moves the model to an absolute position in the world coordinate system.
    Translation follows the world axes.
    Moves the model relative to its current position along the selected coordinate system axes. -
    pivot Moves the model to an absolute position using the pivot coordinate system and pivot axes. -
    scope Moves the model to an absolute position using the scope coordinate system and scope axes. Moves along the axis direction of the scope even if it is rotated.
    object Places the model using the object's local coordinate system. Moves relative to the object's local coordinate system. ?

     

    If you are still unfamiliar with coordinate systems or CGA rules, these concepts may feel abstract at first.

    It is best to code the examples above yourself and get used to them by changing the values in real-time.

     

    Next is size adjustment.

    "We complain that time is short, but in fact, we are given more time than we think. We waste the time we are given by doing nothing, doing things without purpose, or not doing what we should. We always complain that time is insufficient, yet we act as if we will live forever."
    — Seneca, from "Ancient Wisdom" (John Lubbock / Trans. Park Il-gwi)
    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