Bitbybit Docs
    Preparing search index...

    Class Transforms

    Builds transformation matrices for moving, rotating, scaling and stretching geometry. A transformation is a 4x4 matrix as 16 numbers in column-major order; most methods return a short list of them that is applied in order, so a rotation about a point is a move to the origin, the rotation, and the move back. Angles are in degrees. Such a list can also be combined into one matrix, undone, and read for whether it keeps shapes rigid. Apply the result with the transform methods of point, polyline, line and the kernels.

    Index

    Constructors

    combine

    • Folds a transformation into the one matrix that does all its steps in order.

      The lists rotationCenterAxis and the other builders return become a single matrix, which is what a renderer or a placement often wants. An empty list gives the identity. Example: a move by [1,0,0] followed by a move by [0,2,0] -> one move by [1,2,0]

      Parameters

      Returns TransformMatrixes

      A list holding the one combined matrix

      const turn = bitbybit.transforms.rotationCenterAxis({ center: [5, 0, 0], axis: [0, 1, 0], angle: 90 });
      const single = bitbybit.transforms.combine({ transformation: turn });
    • Builds the transformation that undoes one that only moves and turns.

      The transformation is combined first. One that scales, stretches or mirrors is refused, since undoing it exactly takes a general inverse; isRigid tells the two apart. Example: a quarter turn about Z, then a move by [10,0,0] -> the move back, then the turn back

      Parameters

      Returns TransformMatrixes

      A list holding the one matrix that undoes it

      const placement = bitbybit.transforms.rotationCenterAxis({ center: [0, 0, 0], axis: [0, 0, 1], angle: 90 });
      const back = bitbybit.transforms.rigidInverse({ transformation: placement });
    • Measures how a transformation scales volumes, and whether it mirrors.

      It is the determinant of the combined matrix's turn-and-scale part: 1 for a move and turn, the volume factor for a scale, negative when the transformation mirrors. Example: a uniform scale by 2 -> 8

      Parameters

      Returns number

      The determinant

      const factor = bitbybit.transforms.determinant({ transformation: bitbybit.transforms.uniformScale({ scale: 2 }) });
      
    • Tells whether a transformation only moves and turns, without scaling, stretching or mirroring.

      The transformation is combined first; each of its axes must have length 1 and stand square to the others within tolerance. Example: a rotation -> true, a scale by 2 -> false

      Parameters

      Returns boolean

      True when it is a rigid motion

      const rigid = bitbybit.transforms.isRigid({ transformation: bitbybit.transforms.rotationCenterX({ center: [0, 0, 0], angle: 30 }) });
      

    identity

    • Gives the matrix that changes nothing, as a starting point or a placeholder.

      Example: [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]

      Returns TransformMatrix

      The identity matrix

    rotation

    • Builds a rotation about an axis that passes through a center point.

      The result is three matrices applied in order: move the center to the origin, rotate, move back. The angle is in degrees; positive turns counter-clockwise when the axis points toward you. Example: center [5,0,0], axis [0,1,0], angle 90 -> a quarter turn about the vertical line through [5,0,0]

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const turn = bitbybit.transforms.rotationCenterAxis({ center: [5, 0, 0], axis: [0, 1, 0], angle: 90 });
      const points = bitbybit.point.transformPoints({ points: [[10, 0, 0]], transformation: turn });
    • Builds a rotation about a line parallel to the X axis through a center point.

      The result is three matrices applied in order: move the center to the origin, rotate, move back. The angle is in degrees; positive turns counter-clockwise when the axis points toward you. Example: center [0,0,0], angle 90 -> a quarter turn about the X axis

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const turn = bitbybit.transforms.rotationCenterX({ center: [0, 0, 0], angle: 90 });
      
    • Builds a rotation about a line parallel to the Y axis through a center point.

      The result is three matrices applied in order: move the center to the origin, rotate, move back. The angle is in degrees; positive turns counter-clockwise when the axis points toward you. Example: center [0,0,0], angle 90 -> a quarter turn about the Y axis

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const turn = bitbybit.transforms.rotationCenterY({ center: [0, 0, 0], angle: 90 });
      
    • Builds a rotation about a line parallel to the Z axis through a center point.

      The result is three matrices applied in order: move the center to the origin, rotate, move back. The angle is in degrees; positive turns counter-clockwise when the axis points toward you. Example: center [0,0,0], angle 90 -> a quarter turn about the Z axis

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const turn = bitbybit.transforms.rotationCenterZ({ center: [0, 0, 0], angle: 90 });
      
    • Builds a rotation from three angles about a center point: yaw turns about Y, pitch about X and roll about Z.

      The result is three matrices applied in order: move the center to the origin, rotate, move back. Angles are in degrees. Example: yaw 90, pitch 0, roll 0 -> a quarter turn about the vertical axis

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const turn = bitbybit.transforms.rotationCenterYawPitchRoll({ yaw: 90, pitch: 0, roll: 0, center: [0, 0, 0] });
      

    scale

    • Builds a scale with its own factor per axis, measured from a center point that stays in place.

      The result is three matrices applied in order: move the center to the origin, scale, move back. Example: center [5,5,5], factors [2,1,0.5] -> doubles X, keeps Y, halves Z about [5,5,5]

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const scale = bitbybit.transforms.scaleCenterXYZ({ center: [5, 5, 5], scaleXyz: [2, 1, 0.5] });
      
    • Builds a scale with its own factor per axis, measured from the origin.

      Example: factors [2,3,1] -> doubles X, triples Y, keeps Z

      Parameters

      Returns TransformMatrixes

      A list with the one scale matrix

      const scale = bitbybit.transforms.scaleXYZ({ scaleXyz: [2, 3, 1] });
      
    • Builds a stretch along one direction, measured from a center point; distances across that direction stay as they are.

      The result is three matrices applied in order: move the center to the origin, stretch, move back. Example: center [0,0,0], direction [1,0,0], scale 2 -> everything twice as far from the center along X

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const stretch = bitbybit.transforms.stretchDirFromCenter({ center: [0, 0, 0], direction: [1, 0, 0], scale: 2 });
      
    • Builds a scale by the same factor on every axis, measured from the origin.

      Example: 2 -> everything twice as big and twice as far from the origin

      Parameters

      Returns TransformMatrixes

      A list with the one scale matrix

      const scale = bitbybit.transforms.uniformScale({ scale: 2 });
      
    • Builds a scale by the same factor on every axis, measured from a center point that stays in place.

      The result is three matrices applied in order: move the center to the origin, scale, move back. Example: center [5,5,5], scale 0.5 -> everything half as big, shrinking toward [5,5,5]

      Parameters

      Returns TransformMatrixes

      The list of matrices to apply in order

      const scale = bitbybit.transforms.uniformScaleFromCenter({ center: [5, 5, 5], scale: 0.5 });
      

    translation

    • Builds a move by a vector.

      Example: [10,5,0] -> 10 along X, 5 along Y, nothing along Z

      Parameters

      Returns TransformMatrixes

      A list with the one translation matrix

      const move = bitbybit.transforms.translationXYZ({ translation: [10, 5, 0] });
      

    translations

    • Builds one move per vector, for transforming many points each by its own vector.

      Example: [[1,0,0], [0,2,0]] -> two transformations: one along X, one along Y

      Parameters

      Returns TransformMatrixes[]

      One transformation per vector, in the same order

      const moves = bitbybit.transforms.translationsXYZ({ translations: [[1, 0, 0], [0, 2, 0]] });