通过在三维空间中明确指出 x、y 和 z 坐标,可以创建特定的几何体对象。但是,通常在对象本身或其基本 CoordinateSystem 上使用几何变换将几何体移动到其最终位置。
平移
最简单的几何变换是平移,可在 x、y 和 z 方向上将对象移动指定的单位数。
// create a point at x = 1, y = 2, z = 3
p = Point.ByCoordinates(1, 2, 3);
// translate the point 10 units in the x direction,
// -20 in y, and 50 in z
// p2’s new position is x = 11, y = -18, z = 53
p2 = p.Translate(10, -20, 50);
旋转
虽然 Dynamo 中的所有对象均可通过在对象名称末尾附加 .Translate 方法进行转换,但更复杂的变换需要将对象从一个基础坐标系变换到新坐标系。例如,要绕 x 轴将对象旋转 45 度,我们将对象从其现有 CoordinateSystem(不旋转)变换为 CoordinateSystem(已使用 .Transform 方法绕 x 轴旋转 45 度):
cube = Cuboid.ByLengths(CoordinateSystem.Identity(),
10, 10, 10);
new_cs = CoordinateSystem.Identity();
new_cs2 = new_cs.Rotate(Point.ByCoordinates(0, 0),
Vector.ByCoordinates(1,0,0.5), 25);
// get the existing coordinate system of the cube
old_cs = CoordinateSystem.Identity();
cube2 = cube.Transform(old_cs, new_cs2);