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. Apply the result with the transform methods of point, polyline, line and the kernels.

    Index

    Constructors

    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]] });