Transforms modify a part's position, orientation, or size. All transform methods return a new Part, leaving the original unchanged.
Translate
Moves a part by the specified offset.
.translate(x: f64, y: f64, z: f64) -> Part
xf64requiredOffset along X axis in millimeters.
yf64requiredOffset along Y axis in millimeters.
zf64requiredOffset along Z axis in millimeters.
let moved = part.translate(50.0, 0.0, 10.0);
translate_vec
Translate using a nalgebra Vector3.
.translate_vec(v: Vector3<f64>) -> Part
use nalgebra::Vector3;
let offset = Vector3::new(50.0, 0.0, 10.0);
let moved = part.translate_vec(offset);
Rotate
Rotates a part around the origin. Angles are in degrees.
.rotate(x_deg: f64, y_deg: f64, z_deg: f64) -> Part
x_degf64requiredRotation around X axis in degrees.
y_degf64requiredRotation around Y axis in degrees.
z_degf64requiredRotation around Z axis in degrees.
Rotation order is X → Y → Z (Euler angles, extrinsic).
// Rotate 45° around Z axis
let rotated = part.rotate(0.0, 0.0, 45.0);
// Tip cylinder horizontal (lay on side)
let horizontal = cylinder.rotate(90.0, 0.0, 0.0);
To rotate around a point other than the origin: translate to origin, rotate, translate back.
Scale
Scales a part by the specified factors.
.scale(x: f64, y: f64, z: f64) -> Part
xf64requiredScale factor along X axis.
yf64requiredScale factor along Y axis.
zf64requiredScale factor along Z axis.
// Double width, keep other dimensions
let stretched = part.scale(2.0, 1.0, 1.0);
// Shrink to half size
let smaller = part.scale(0.5, 0.5, 0.5);
scale_uniform
Scales uniformly in all directions.
.scale_uniform(s: f64) -> Part
let doubled = part.scale_uniform(2.0);
Negative scale factors create mirrored geometry. Use the explicit mirror methods for clarity.
Mirror
Creates a mirrored copy across a plane through the origin.
.mirror_x() -> Part // Mirror across YZ plane (flip X)
.mirror_y() -> Part // Mirror across XZ plane (flip Y)
.mirror_z() -> Part // Mirror across XY plane (flip Z)
// Create symmetric bracket
let arm = centered_cube("arm", 40.0, 10.0, 5.0)
.translate(25.0, 0.0, 0.0);
let bracket = &arm + &arm.mirror_x();
Linear Pattern
Creates copies of a part along a vector.
.linear_pattern(dx: f64, dy: f64, dz: f64, count: usize) -> Part
dxf64requiredSpacing in X direction (total distance to last copy).
dyf64requiredSpacing in Y direction.
dzf64requiredSpacing in Z direction.
countusizerequiredTotal number of copies (including original).
The spacing parameters define the total distance from first to last copy. The actual spacing between copies is distance / (count - 1).
// 4 holes, 30mm apart
let hole = centered_cylinder("hole", 3.0, 10.0, 32);
let row = hole.linear_pattern(90.0, 0.0, 0.0, 4);
// Creates holes at X = 0, 30, 60, 90
2D Grid Pattern
Chain linear patterns for grids:
let grid = hole
.linear_pattern(90.0, 0.0, 0.0, 4) // 4 columns
.linear_pattern(0.0, 60.0, 0.0, 3); // 3 rows
// Creates 12 holes
Circular Pattern
Creates copies of a part around the Z axis.
.circular_pattern(radius: f64, count: usize) -> Part
radiusf64requiredRadius of the pattern circle. Use 0 to rotate around origin.
countusizerequiredNumber of copies around the circle.
Copies are evenly spaced around 360°.
// 6 holes around a 30mm radius
let hole = centered_cylinder("hole", 3.0, 10.0, 32)
.translate(30.0, 0.0, 0.0); // Position at radius
let pattern = hole.circular_pattern(0.0, 6);
When radius is 0, the part rotates around the origin. Pre-translate the part to set the pattern radius.
Chaining Transforms
Transforms can be chained. Each returns a new Part:
let positioned = part
.translate(-5.0, -5.0, 0.0) // Center at origin
.rotate(0.0, 0.0, 45.0) // Rotate
.translate(50.0, 0.0, 0.0); // Move to final position
Transform order matters! translate → rotate gives different results than rotate → translate.
Transform Reference
| Method | Description |
|---|---|
.translate(x, y, z) | Move by offset |
.translate_vec(v) | Move by Vector3 |
.rotate(x, y, z) | Rotate (degrees) |
.scale(x, y, z) | Non-uniform scale |
.scale_uniform(s) | Uniform scale |
.mirror_x() | Flip across YZ plane |
.mirror_y() | Flip across XZ plane |
.mirror_z() | Flip across XY plane |
.linear_pattern(dx, dy, dz, n) | Line of copies |
.circular_pattern(r, n) | Circle of copies |