Translation


Geometric definition


A translation is a transformation that moves a geometry by a certain distance in a specified direction. The direction can be defined by a vector.

How to add


As often is possible in Rhino to use either RhinoCommons or RhinoScriptSynthax to add a point to the Rhino workspace. Here are the two methods:

RhinoCommons


import Rhino.Geometry as rg
import scriptcontext as sc

# create a rectangle
rectangle = rg.Rectangle3d(rg.Plane.WorldXY, 10, 10)

# create a translation transformation
translation = rg.Transform.Translation(rg.Vector3d(
    10,  # x vector translation value
    0,  # y vector translation value
    0))  # z vector translation value

# transform the rectangle
rectangle.Transform(translation)

# add the rectangle to the document
sc.doc.Objects.AddRectangle(rectangle)


RhinoScriptSynthax


import rhinoscriptsyntax as rs

# create a rectangle
rectangle_id = rs.AddRectangle(rs.WorldXYPlane(), 10, 10)

# create a translation transformation
translation = rs.VectorCreate([10, 0, 0], [0, 0, 0])

# transform the rectangle
rs.MoveObject(rectangle_id, translation)

Main methods and properties


Operators


Translations as all the other transformations have a set of operators that can be used to perform to combine transformations (also different kinds, e.g.: translation with rotation). Here are the main ones:

xform_1 = rg.Transform.Translation(rg.Vector3d(10, 0, 0))
xform_2 = rg.Transform.Translation(rg.Vector3d(0, 10, 0))

xform_3 = xform_1 * xform_2 # Will combine the two transformations

⚠️ Note that the order of the transformations is important. In the example above the first transformation will be applied first and the second transformation will be applied second. ⚠️

Properties


Translations as all the other transformations have a set of properties that can be used to retrieve information about the transformation. Here are the main ones:

translation = rg.Transform.Translation(rg.Vector3d(10, 0, 0))

translation.IsIdentity # Will return True if the transformation is an identity transformation
translation.IsValid # Will return True if the transformation is valid
translation.IsZero # Will return True if the transformation is a zero transformation


🛠 Exercises


Starting file:

01: 🦏⬇️⬇️⬇️ Download the file here ⬇️⬇️⬇️🦏 01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

Solution:

01: 🦏⬇️⬇️⬇️ Download the file here ⬇️⬇️⬇️🦏 01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍