Affine transform
meshioplusplus.transform(mesh, ...) applies a geometric transform to a mesh's point coordinates — translate, scale (per-axis or uniform), rotate (axis + angle), a general 4×4 affine matrix, or a unit-scale factor. Only the points change; connectivity, cell_data, field_data, and (by default) point_data are carried through. It is a mesh operation (like reordering and quality metrics), not a file format, and uses only standard C++/numpy, so it runs under every mesh backend.

import meshioplusplus
mesh = meshioplusplus.read("part.vtu")
t = meshioplusplus.transform(mesh, translate=[1, 2, 3])
s = meshioplusplus.transform(mesh, scale=[2, 2, 1]) # per-axis
u = meshioplusplus.transform(mesh, scale=0.5) # uniform
r = meshioplusplus.transform(mesh, rotate=("z", 90)) # 90° about z
m = meshioplusplus.transform(mesh, matrix=my_4x4) # general affine
mm = meshioplusplus.transform(mesh, scale_units=0.001) # mm -> m
meshioplusplus.write("part_moved.vtu", t)Parameters
| parameter | meaning |
|---|---|
translate | a 3-vector (dx, dy, dz) (applied last when several are combined) |
scale | a scalar (uniform) or 3-vector (sx, sy, sz) about the origin |
rotate | (axis, angle_deg) where axis is "x"/"y"/"z" or a 3-vector; angle in degrees |
matrix | a full 4×4 (or flat 16-element) row-major affine matrix; overrides the others |
scale_units | a scalar unit-conversion factor |
rotate_vector_data | when true, rotate vector (dim 3) / tensor (dim 9) point_data by the linear part; off by default |
Several builders compose (in the fixed order units → scale → rotate → translate). An orientation-reversing transform (negative determinant of the 3×3 linear block) logs a warning that cell orientation may be flipped.
What changes
- Points are transformed by
p' = M · [x, y, z, 1]. - Connectivity,
cell_data, andfield_dataare unchanged. point_datais copied unchanged unlessrotate_vector_data=True, which rotates arrays whose trailing dimension is 3 (R·v) or 9 (R·A·Rᵀ).point_sets/cell_setspass through unchanged (indices are stable).
CLI
meshioplusplus transform in.vtu out.vtu --translate 1,2,3
meshioplusplus transform in.vtu out.vtu --scale 2,2,1
meshioplusplus transform in.vtu out.vtu --rotate z,90
meshioplusplus transform in.vtu out.vtu --matrix m00,...,m33
meshioplusplus transform in.vtu out.vtu --scale-units 0.001Give exactly one transform source. Values that begin with - (e.g. a negative translation) need the --translate=-1,0,0 form so argparse doesn't read them as a flag. See the CLI reference.
Other languages
- C API —
mio_transform(mesh, matrix[16], rotate_vector_data). See the C API reference. - Fortran —
mesh%transform(matrix, rotate_vector_data=...). See the Fortran reference. - WebAssembly / JavaScript —
transform(mesh, matrix, rotateVectorData). See the WebAssembly reference.