Bitbybit Docs
    Preparing search index...

    Class OCCTTransforms

    Moving, turning, scaling and mirroring OpenCascade shapes, and building the 4x4 matrices that describe such moves. Every method returns a new shape and leaves the input as it was. Angles are in degrees, distances in model units, and a rotation axis passes through the origin unless a method takes a center. Matrices are 16 numbers in column-major order (the translation sits at indices 12 to 14); a list of matrices is applied first to last as one combined move, which is how transformByMatrix and the ...ToMatrix builders fit together.

    Index

    Constructors

    by matrix

    • Applies a 4x4 matrix, or a list of matrices applied first to last, to a shape.

      The matrix is column-major, so the translation sits at indices 12 to 14. A matrix that stretches or shears is allowed; build matrices with the ...ToMatrix methods and combine them with multiplyTransforms. A matrix the kernel cannot apply throws an error.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The transformed shape

      const move = await bitbybit.occt.transforms.translationToMatrix({ translation: [10, 0, 0] });
      const turn = await bitbybit.occt.transforms.rotationAxisAngleToMatrix({ axis: [0, 1, 0], angle: 90, center: [0, 0, 0] });
      const placed = await bitbybit.occt.transforms.transformByMatrix({ shape: box, transformation: [turn, move] });
    • Reads the placement a shape carries, the transform stored on it rather than baked into its geometry, as a matrix plus its translation, rotation quaternion and uniform scale.

      A shape placed with align or through an assembly carries such a placement; most other methods here bake the move into the geometry, and such a shape reports the identity.

      Parameters

      Returns Promise<ShapeTransformInfo>

      The matrix, the translation, the quaternion as [x, y, z, w] and the scale

      const placement = await bitbybit.occt.transforms.getShapeTransform({ shape: movedBox });
      console.log(placement.translation, placement.scale);

    matrix builders

    • Builds the identity matrix, the transform that changes nothing, as a starting point for composing others.

      Returns Promise<TransformMatrix>

      The identity matrix, column-major

      const identity = await bitbybit.occt.transforms.identityTransform();
      
    • Builds one matrix from a translation, three rotation angles in degrees about X, Y and Z, and a uniform scale.

      The scale is applied first, then the rotations (Z first, then Y, then X), then the translation, which is the order assembly placements use. Any part left out is taken as no change.

      Parameters

      • inputs: ComposeTransformDto

        The translation, the three rotation angles in degrees and the scale factor

      Returns Promise<TransformMatrix>

      The combined matrix, column-major

      const placement = await bitbybit.occt.transforms.composeTransform({ translation: [10, 0, 0], rotation: [0, 90, 0], scale: 1 });
      
    • Folds a list of matrices into one, applied first to last, so a chain of moves becomes a single matrix.

      A single matrix is returned unchanged and an empty list gives the identity.

      Parameters

      Returns Promise<TransformMatrix>

      The combined matrix, column-major

      const combined = await bitbybit.occt.transforms.multiplyTransforms({ transformation: [turn, move] });
      
    • Inverts a matrix, giving the transform that undoes it: applying a matrix and then its inverse puts a shape back where it was.

      Parameters

      Returns Promise<TransformMatrix>

      The inverse matrix, column-major

      const back = await bitbybit.occt.transforms.invertTransform({ transformation: placement });
      
    • Builds the matrix of a move by a vector, in model units.

      Parameters

      Returns Promise<TransformMatrix>

      The translation matrix, column-major

      const move = await bitbybit.occt.transforms.translationToMatrix({ translation: [10, 0, 0] });
      
    • Builds the matrix of a rotation by an angle in degrees about an axis, through the origin or through an optional center point.

      The rotation follows the right-hand rule about axis.

      Parameters

      Returns Promise<TransformMatrix>

      The rotation matrix, column-major

      const turn = await bitbybit.occt.transforms.rotationAxisAngleToMatrix({ axis: [0, 1, 0], angle: 90, center: [5, 0, 5] });
      
    • Builds the matrix of a uniform scale by a factor about the origin or an optional center point.

      Parameters

      Returns Promise<TransformMatrix>

      The scale matrix, column-major

      const grow = await bitbybit.occt.transforms.scaleUniformToMatrix({ factor: 2, center: [0, 0, 0] });
      
    • Builds the matrix of a mirror through a point, the transform mirrorAboutPoint applies.

      Parameters

      Returns Promise<TransformMatrix>

      The mirror matrix, column-major

      const invert = await bitbybit.occt.transforms.mirrorPointToMatrix({ point: [0, 0, 0] });
      
    • Builds the matrix of a mirror across a line, the transform mirror applies: the axis through origin along direction.

      Parameters

      Returns Promise<TransformMatrix>

      The mirror matrix, column-major

      const flip = await bitbybit.occt.transforms.mirrorAxisToMatrix({ origin: [0, 0, 0], direction: [0, 1, 0] });
      
    • Builds the matrix of a mirror across a plane, the transform mirrorAlongNormal applies: the plane through origin with the given normal.

      Parameters

      Returns Promise<TransformMatrix>

      The mirror matrix, column-major

      const reflect = await bitbybit.occt.transforms.mirrorPlaneToMatrix({ origin: [0, 0, 0], normal: [1, 0, 0] });
      
    • Builds the rotation matrix of a quaternion given as [x, y, z, w].

      The quaternion is normalized first, so its length does not matter.

      Parameters

      Returns Promise<TransformMatrix>

      The rotation matrix, column-major

      const turn = await bitbybit.occt.transforms.quaternionToMatrix({ quaternion: [0, 0.7071, 0, 0.7071] });
      

    on shapes

    • Applies transform to several shapes, each with its own translation, rotation axis, angle and scale factor.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The transformed shapes, in the same order

      const moved = await bitbybit.occt.transforms.transformShapes({
      shapes: [box, sphere],
      translations: [[10, 0, 0], [-10, 0, 0]],
      rotationAxes: [[0, 1, 0], [0, 1, 0]],
      rotationAngles: [45, 0],
      scaleFactors: [1, 2],
      });
    • Applies rotate to several shapes, each about its own axis through the origin and by its own angle in degrees.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The rotated shapes, in the same order

      const turned = await bitbybit.occt.transforms.rotateShapes({ shapes: [box, sphere], axes: [[0, 1, 0], [1, 0, 0]], angles: [90, 45] });
      
    • Applies rotateAroundCenter to several shapes, each with its own angle in degrees, center and axis.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The rotated shapes, in the same order

      const turned = await bitbybit.occt.transforms.rotateAroundCenterShapes({
      shapes: [box, sphere],
      angles: [90, 45],
      centers: [[5, 0, 5], [0, 0, 0]],
      axes: [[0, 1, 0], [0, 1, 0]],
      });
    • Applies align to several shapes, each with its own from and to frames.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The aligned shapes, in the same order

      const placed = await bitbybit.occt.transforms.alignShapes({
      shapes: [cylinder, cylinder2],
      fromOrigins: [[0, 0, 0], [0, 0, 0]],
      fromDirections: [[0, 1, 0], [0, 1, 0]],
      toOrigins: [[10, 0, 0], [20, 0, 0]],
      toDirections: [[1, 0, 0], [0, 0, 1]],
      });
    • Applies alignAndTranslate to several shapes, each with its own direction and center.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The placed shapes, in the same order

      const placed = await bitbybit.occt.transforms.alignAndTranslateShapes({
      shapes: [profile, profile2],
      directions: [[1, 0, 0], [0, 0, 1]],
      centers: [[10, 0, 0], [0, 0, 10]],
      });
    • Applies translate to several shapes, each by its own vector.

      The two lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The moved shapes, in the same order

      const moved = await bitbybit.occt.transforms.translateShapes({ shapes: [box, sphere], translations: [[10, 0, 0], [-10, 0, 0]] });
      
    • Applies scale to several shapes, each uniformly about the origin by its own factor.

      The two lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The scaled shapes, in the same order

      const scaled = await bitbybit.occt.transforms.scaleShapes({ shapes: [box, sphere], factors: [2, 0.5] });
      
    • Applies scale3d to several shapes, each with its own three factors and center.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The scaled shapes, in the same order

      const scaled = await bitbybit.occt.transforms.scale3dShapes({
      shapes: [box, sphere],
      scales: [[1, 2, 1], [2, 2, 2]],
      centers: [[0, 0, 0], [10, 0, 0]],
      });
    • Applies mirror to several shapes, each across its own axis.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The mirrored shapes, in the same order

      const flipped = await bitbybit.occt.transforms.mirrorShapes({
      shapes: [box, sphere],
      origins: [[0, 0, 0], [0, 0, 0]],
      directions: [[0, 1, 0], [1, 0, 0]],
      });
    • Applies mirrorAlongNormal to several shapes, each across its own plane.

      All the lists must have the same length, or an error is thrown.

      Parameters

      Returns Promise<TopoDSShapePointer[]>

      The mirrored shapes, in the same order

      const others = await bitbybit.occt.transforms.mirrorAlongNormalShapes({
      shapes: [leftArm, leftLeg],
      origins: [[0, 0, 0], [0, 0, 0]],
      normals: [[1, 0, 0], [1, 0, 0]],
      });

    on single shape

    • Scales, rotates and moves a shape in one go: first the scale about the origin, then the rotation about an axis through the origin, then the translation.

      Because the scale and the rotation happen about the origin, a shape that is not there also swings around it; move it first, or use rotateAroundCenter and scale3d for a chosen center.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The transformed shape

      const moved = await bitbybit.occt.transforms.transform({
      shape: box,
      translation: [10, 0, 0],
      rotationAxis: [0, 1, 0],
      rotationAngle: 45,
      scaleFactor: 2,
      });
    • Rotates a shape about an axis that passes through the origin, by an angle in degrees.

      The rotation follows the right-hand rule: with the thumb along axis, the fingers show the positive direction. A shape away from the origin swings around it; rotateAroundCenter rotates about a chosen point instead.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The rotated shape

      const turned = await bitbybit.occt.transforms.rotate({ shape: box, axis: [0, 1, 0], angle: 90 });
      
    • Rotates a shape about an axis that passes through a chosen point, by an angle in degrees.

      The shape is moved so the point sits at the origin, rotated there with the right-hand rule about axis, and moved back.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The rotated shape

      const turned = await bitbybit.occt.transforms.rotateAroundCenter({ shape: box, angle: 90, center: [5, 0, 5], axis: [0, 1, 0] });
      
    • Moves a shape so that one point and direction on it land on another point and direction: the frame fromOrigin with fromDirection is carried onto toOrigin with toDirection.

      This is the way to stand a shape on a surface or point it along a line: the shape is both moved and turned, never scaled.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The aligned shape

      const standing = await bitbybit.occt.transforms.align({
      shape: cylinder,
      fromOrigin: [0, 0, 0],
      fromDirection: [0, 1, 0],
      toOrigin: [10, 5, 0],
      toDirection: [1, 0, 0],
      });
    • Moves a shape so that a full frame on it lands on another frame: a point, its normal and one axis in the plane of that normal are carried onto their targets.

      Where align fixes one direction and leaves the spin around it free, this also fixes the spin, which matters for shapes that are not round about their axis.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The aligned shape

      const placed = await bitbybit.occt.transforms.alignNormAndAxis({
      shape: bracket,
      fromOrigin: [0, 0, 0],
      fromNorm: [0, 1, 0],
      fromAx: [1, 0, 0],
      toOrigin: [10, 0, 0],
      toNorm: [0, 0, 1],
      toAx: [0, 1, 0],
      });
    • Turns a shape so that its Y axis points along direction, then moves it to center.

      The flat shapes and primitives of this package are built on the ground with Y up, so this is the one call that places any of them: the direction becomes their new up, and the center where they sit.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The placed shape

      const placed = await bitbybit.occt.transforms.alignAndTranslate({ shape: profile, direction: [1, 0, 0], center: [10, 0, 0] });
      
    • Scales a shape uniformly about the origin by a factor.

      A shape away from the origin also moves away from or toward it; scaleFromCenter scales about a chosen point and scale3d scales each axis by its own factor.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The scaled shape

      const bigger = await bitbybit.occt.transforms.scale({ shape: box, factor: 2 });
      
    • Scales a shape by a separate factor along X, Y and Z, about a chosen center point.

      Unequal factors stretch the shape, which turns circles into ellipses and can make later operations, such as fillets, slower or fail; keep the factors equal when the shape only needs to grow.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The scaled shape

      const stretched = await bitbybit.occt.transforms.scale3d({ shape: box, scale: [1, 2, 1], center: [0, 0, 0] });
      
    • Mirrors a shape across a line: the axis through origin along direction.

      Every point lands as far behind the line as it was in front, which in 3D is the same as a half turn about that axis.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The mirrored shape

      const flipped = await bitbybit.occt.transforms.mirror({ shape: box, origin: [0, 0, 0], direction: [0, 1, 0] });
      
    • Mirrors a shape across a plane given by a point on it and its normal.

      This is the usual mirror image, the kind a symmetric part needs; the result is turned inside out in the sense that a left-hand shape becomes a right-hand one.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The mirrored shape

      const other = await bitbybit.occt.transforms.mirrorAlongNormal({ shape: leftHalf, origin: [0, 0, 0], normal: [1, 0, 0] });
      
    • Scales a shape uniformly about a chosen point by a factor.

      The point stays where it is and everything else moves away from it or toward it.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The scaled shape

      const bigger = await bitbybit.occt.transforms.scaleFromCenter({ shape: box, factor: 2, center: [5, 0, 5] });
      
    • Mirrors a shape through a point: every point of the shape lands as far beyond the point as it was before it, on the opposite side.

      The result is turned inside out, the way a plane mirror turns a left hand into a right hand.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The mirrored shape

      const inverted = await bitbybit.occt.transforms.mirrorAboutPoint({ shape: box, point: [0, 0, 0] });
      
    • Rotates a shape about the origin by a quaternion given as [x, y, z, w].

      The quaternion is normalized first, so its length does not matter. Quaternions are what animation and physics libraries hand out, so this saves converting them to an axis and an angle.

      Parameters

      Returns Promise<TopoDSShapePointer>

      The rotated shape

      const turned = await bitbybit.occt.transforms.rotateByQuaternion({ shape: box, quaternion: [0, 0.7071, 0, 0.7071] });