Peyep CGA 函数参考变换 · 2025.1
版本首页查看 demo →
← 返回 2025.1 分类导航

变换 Transformations · 6 个函数

平移、旋转、缩放与居中

center native ✓ cpp-fast ✓ 已验证 195 条 · gold 官方文档 ↗ #
把形状居中到指定坐标轴
签名(1 种重载)
center(axes)
参数说明
参数类型说明
axesselector{ x | y | z | xy | xz | yz | xyz }—Axes to include in center calculation.
官方说明(英文原文)

The center operation moves the scope of the current shape to the center of the previous shape's scope. 'Previous shape' means the previous shape on the shape stack.

官方示例 · 点击展开
Lot-->
  primitiveCube()

   s(4,4,4)
   t(-2,-2,-2)
   SelCube
 
SelCube-->
   [ color("#ff0000") s(1,1,1) center(x)   X ]
   [ color("#00ff00") s(1,1,1) center(y)   X ]
   [ color("#0000ff") s(1,1,1) center(z)   X ]
   [ color("#ffff00") s(1,1,1) center(xy)  X ]
   [ color("#ff00ff") s(1,1,1) center(xz)  X ]
   [ color("#00ffff") s(1,1,1) center(yz)  X ]
   [ color("#ffffff") s(1,1,1) center(xyz) X ]
我方已验证示例:center(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule
Lot -->
primitiveQuad(7, 15)
extrude(4)
t(2, 0, 0)
center(xyz)
color(0.5, 0.5, 1)
r native ✓ cpp-fast ✓ 已验证 112 条 · gold 官方文档 ↗ #
旋转(官方简写操作 r)
签名(2 种重载)
r(xAngle, yAngle, zAngle)
r(center, xAngle, yAngle, zAngle)
参数说明
参数类型说明
xAnglefloatAngle in degrees to rotate about x- axis.
yAnglefloatAngle in degrees to rotate about y- axis.
zAnglefloatAngle in degrees to rotate about each z- axis.
centerselector{ scopeOrgin | scopeCenter }—The rotation center. scopeOrgin is the default. (used if no center selector is given).
官方说明(英文原文)

The r operation rotates the scope of the current shape around the pivot-axes in xyz order. The center of rotation is either the scopeOrigin (scope.t) of the current shape or the scopeCenter of the current shape.

Note:

r(x,y,z) is the same as rotate(rel,pivot,x,y,z)

官方示例 · 点击展开
height = 18
dy = 2
Lot-->
   extrude(height)
   split(y) { dy : r(0, 
                     360*split.index/split.total, 0)
                   X }*
height = 18
dy = 2

Lot-->
   extrude(height)
   split(y) { dy : r(scopeCenter, 0, 
                     360*split.index/split.total, 0)
                   X }*
我方已验证示例:rectify(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule
Lot -->
primitiveQuad(7, 15)
extrude(4)
r(0, 20, 0)
rectify()
color(0.7, 0.8, 0.9)
rotate native ✓ cpp-fast ✓ 已验证 7 条 · gold 官方文档 ↗ #
旋转形状 / scope
签名(1 种重载)
rotate(mode, coordSystem, xAngle, yAngle, zAngle)
参数说明
参数类型说明
modeselector{ abs | rel }—Absolute or relative mode. Absolute means the angles are set to the given value, relative means the angles are added.
coordSystemselector{ scope | pivot | object | world }—Name of the coordinate system in which the following angles are given.
xAnglefloatAngles in degrees to rotate about the x-axis.
yAnglefloatAngles in degrees to rotate about the y-axis.
zAnglefloatAngles in degrees to rotate about the z-axis.
官方说明(英文原文)

The rotate operation rotates the scope around the scope origin. The angles can be defined in any coordinate system, and the rotation can either be absolute (= set the angles) or relative (= add the angles). This operation manipulates the scope orientation (scope.r attribute).

官方示例 · 点击展开
Init-->
   extrude(10)
   t('0.2, 0, '0.3)
   s('0.5, '1, '0.5)
   rotate(abs, world, 0, 90, 0)
我方已验证示例:rotate(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule
Lot -->
primitiveQuad(7, 15)
extrude(4)
rotate(0, 45, 0)
color(0.6, 0.7, 0.8)
s native ✓ cpp-fast ✓ 已验证 409 条 · gold 官方文档 ↗ #
缩放:设置 scope 尺寸(官方简写操作 s)
签名(1 种重载)
s(xSize, ySize, zSize)
参数说明
参数类型说明
xSizefloatSize of the new scope for x-dimension.
ySizefloatSize of the new scope for y-dimension.
zSizefloatSize of the new scope for z-dimension.
官方说明(英文原文)

The s operation sets the size vector scope.s. The relative operator ' permits a convenient notation relative to the current shape's scope size:

s('sx,0,0) is equivalent to s(sx*scope.sx, 0, 0)

Negative sizes result in mirroring along the corresponding axes; this means the normals are inverted.

官方示例 · 点击展开
Lot-->
   extrude(10)
Lot-->
   extrude(10)
   s(5,5,5)
Lot-->
   extrude(10)
   s('0.5,'1,'1.5)
我方已验证示例:平移 / 旋转 / 缩放(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule
Lot -->
primitiveQuad(7, 15)
t(0,0.5,0)
r(0,15,0)
s(0.8,1,0.8)
extrude(5)
color(0.3,0.6,0.4)
t native ✓ cpp-fast ✓ 已验证 406 条 · gold 官方文档 ↗ #
平移(官方简写操作 t)
签名(1 种重载)
t(tx, ty, tz)
参数说明
参数类型说明
txfloatAmount to translate in the x direction.
tyfloatAmount to translate in the y direction.
tzfloatAmount to translate in the z direction.
官方说明(英文原文)

The t operation translates the scope by the vector (tx, ty, tz), i.e. the vector is added to scope.t. If the scope rotation is non-zero, then the passed translation vector is rotated around the pivot first, with angles (scope.rx, scope.ry, scope.rz). In other words, the translation is relative to the scope axes.

The relative operator ' permits a convenient notation relative to the scope size: t('tx,0,0) is equivalent to t(tx*scope.sx, 0, 0).

Note: t(x,y,z) is the same as translate(rel, scope, x, y, z).

官方示例(共 4 个,展示前 3 个) · 点击展开
A-->
   primitiveCube()
A-->
   primitiveCube()
   t(2,0,0)
A-->
   primitiveCube()
   t(2,0,0)
   r(0,30,0)
我方已验证示例:center(verified_gold)· 点击展开代码 · 在 demo 中运行 →
@StartRule
Lot -->
primitiveQuad(7, 15)
extrude(4)
t(2, 0, 0)
center(xyz)
color(0.5, 0.5, 1)
translate native ✓ cpp-fast ✓ 已验证 44 条 · silver 官方文档 ↗ #
平移形状
签名(1 种重载)
translate(mode, coordSystem, x, y, z)
参数说明
参数类型说明
modeselector{ abs | rel }—Absolute or relative mode. Absolute means the position is set to the given value, relative means the translation is added.
coordSystemselector{ scope | pivot | object | world }—Name of the coordinate system in which the following coordinates are given.
x,y,zfloatThe coordinates define a position in the coordSystem to which the current shape's scope (scope.t) is set if the mode is abs or a translation vector to apply if the mode is rel.
官方说明(英文原文)

The translate operation translates the scope. The coordinates can be defined in any coordinate system, and the translation can either be absolute (= set to x,y,z) or relative (= add the x,y,z vector). This operation manipulates the scope position (scope.t attribute).

官方示例 · 点击展开
Init --> split(x) { '0.2 : split(z) { '0.2 : PP }* }*
	
PP --> 43% : primitiveCube()
             X
             translate(rel, world, 2, 0, 0)
             color("#ff0000")
             X
       else : NIL
Init --> split(x) { '0.2 : split(z) { '0.2 : PP }* }*
	
PP --> 43% : primitiveCube()
             X
             translate(rel, object, 2, 0, 0)
             color("#ff0000")
             X
       else : NIL
我方已验证示例:learning case #175(verified_silver)· 点击展开代码 · 在 demo 中运行 →
/* union boolean operation example */
Lot -->
  union { primitiveCube() | translate("rel", "scope", 1, 0, 0) primitiveCube() }
  color("#888888")