geometryOps.transform

A copy of a geometry under an affine map from translate, rotate and scale or a matrix, about a pivot, with normals moved correctly.

GeometricSince 0.16.0

Usage

TypeScript
GeometryOps.transform(geometry: Geometry | VerbValue, params?: GeometryTransformParams): Result<VerbValue>

Parameters

  • geometryGeometry | VerbValue

    Polygon, curve or point geometry; the input is not modified.

    Required

  • params.txnumber

    Translation along x (ty, tz the same along y and z). Default 0. In model.

  • params.rxnumber

    Rotation about x (ry, rz about y and z); the rotation is Rx · Ry · Rz, so a point turns about z first. Default 0. In radians.

  • params.sxnumber

    Scale along x (sy, sz along y and z), applied before the rotation; negative mirrors, 0 is refused. Default 1. In ratio.

  • params.pivot{ x?: number, y?: number, z?: number }

    The fixed point of the rotation and scale: x ↦ pivot + L · (x − pivot) + t. Default { x: 0, y: 0, z: 0 }. In model.

  • params.matrixnumber[]

    Instead of tx … sz: a 4 × 4 affine matrix, 16 entries column-major (entries 12–14 the translation, the last row 0 0 0 1), applied about pivot. Default undefined (the TRS params).

Returns

Ok with a VerbValue (the caller frees it): the geometry moved by x ↦ pivot + L · (x − pivot) + t, L = Rx · Ry · Rz · diag(sx, sy, sz) or the matrix’s upper 3 × 3 block; data.mirrored says whether det L < 0, in which case every polygon’s winding is reversed (its first corner kept).

Errors

Guarantees

  • every position is L · (x − pivot) + pivot + t, computed in f64; transforming by a map and then by its inverse returns each coordinate within 1e-12 of the coordinates’ magnitude for a well-conditioned map
  • transforming by A and then by B gives the transform by B · A, within the same bound
  • normals stay unit length and perpendicular to the moved faces: a face’s winding normal points along its moved N
  • ids, roles and the face count are unchanged
  • the same input and parameters give the same bytes (geometryContentHash), natively and in WASM
  • The same result on every machine.

Example

TypeScript
const r = GeometryOps.transform(Mesh.box().value, { ry: Math.PI / 2, sx: 2, pivot: { x: 1 } })
r.ok || r.diagnostics[0].code // → the box scaled and turned about x = 1 once loadGeometryKernel() has run

See also