Bitbybit Docs
    Preparing search index...

    Class Frame

    Frames: a frame is a point with three axes at right angles, written as its origin, its normal (the Z axis) and its direction (the X axis), the Y axis following from those two. Frames place things: a shape lands on one, points convert between one and the world, and frame patterns lay out copies. Every method returns new values and never changes its inputs.

    Index

    Constructors

    change

    • Moves frames by one vector in world coordinates, as translate moves one; their axes keep their directions.

      Parameters

      Returns Bit.Inputs.Base.Frame[]

      New frames, in the same order

      const floor = bitbybit.frame.grid({ countX: 3, countY: 3, spacingX: 2, spacingY: 2, centered: true });
      const ceiling = bitbybit.frame.translateFrames({ frames: floor, translation: [0, 0, 3] });
    • Moves a frame along its own normal, keeping the directions of its axes.

      A negative distance moves it against the normal.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const lid = bitbybit.frame.offset({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }), distance: 10 });
      
    • Moves each frame along its own normal by the same distance, as offset moves one; their axes keep their directions.

      Frames facing different ways move different ways: a negative distance moves each against its own normal.

      Parameters

      Returns Bit.Inputs.Base.Frame[]

      New frames, in the same order

      const ring = bitbybit.frame.polar({ count: 8, radius: 5, angle: 360, startAngle: 0, rotate: true });
      const raised = bitbybit.frame.offsetFrames({ frames: ring, distance: 2 });
    • Turns a frame about one of its own axes, through its origin.

      The angle is in degrees; positive is counter-clockwise when that axis points toward you.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const tilted = bitbybit.frame.rotate({ frame: bitbybit.frame.world(), axis: Bit.Inputs.Frame.frameAxisEnum.x, angle: 30 });
      
    • Turns each frame about one of its own axes, through its own origin, as rotate turns one.

      The angle is in degrees; positive is counter-clockwise when that axis points toward you.

      Parameters

      • inputs: RotateFramesDto

        The frames, the axis to turn each about and the angle

      Returns Bit.Inputs.Base.Frame[]

      New frames, in the same order

      const row = bitbybit.frame.grid({ countX: 4, countY: 1, spacingX: 2, spacingY: 2, centered: true });
      const tilted = bitbybit.frame.rotateFrames({ frames: row, axis: Bit.Inputs.Frame.frameAxisEnum.x, angle: 30 });
    • Turns a frame over: its normal points the other way and its Y axis with it, its origin and X axis stay.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const underside = bitbybit.frame.flip({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }) });
      
    • Turns each frame over, as flip turns one: its normal and Y axis point the other way, its origin and X axis stay.

      Parameters

      Returns Bit.Inputs.Base.Frame[]

      New frames, in the same order

      const tops = bitbybit.frame.grid({ countX: 2, countY: 2, spacingX: 3, spacingY: 3, centered: true });
      const bottoms = bitbybit.frame.flipFrames({ frames: tops });

    coordinates

    • Converts a point given in a frame's coordinates into world coordinates.

      [1, 2, 3] becomes the point 1 along the frame's X axis, 2 along its Y axis and 3 along its normal, from its origin.

      Parameters

      Returns Point3

      The point in world coordinates

      const corner = bitbybit.frame.pointToWorld({ frame: bitbybit.frame.zx({ origin: [0, 2, 0] }), point: [1, 1, 0] });
      
    • Converts a point given in world coordinates into a frame's coordinates, the reverse of pointToWorld.

      The third coordinate of the result is the point's signed distance from the frame's plane.

      Parameters

      • inputs: FramePointDto

        The frame and the point in world coordinates

      Returns Point3

      The point in the frame's coordinates

      const local = bitbybit.frame.pointToLocal({ frame: bitbybit.frame.zx({ origin: [0, 2, 0] }), point: [1, 5, 1] });
      
    • Converts points given in a frame's coordinates into world coordinates, as pointToWorld does for one.

      Parameters

      Returns Point3[]

      The points in world coordinates, in the same order

      const square = bitbybit.frame.pointsToWorld({ frame: bitbybit.frame.yz({ origin: [3, 0, 0] }), points: [[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]] });
      
    • Converts points given in world coordinates into a frame's coordinates, as pointToLocal does for one.

      Parameters

      Returns Point3[]

      The points in the frame's coordinates, in the same order

      const flat = bitbybit.frame.pointsToLocal({ frame: bitbybit.frame.yz({ origin: [3, 0, 0] }), points: [[3, 0, 0], [3, 1, 0], [3, 1, 1]] });
      
    • Turns a vector given along a frame's axes into one along the world axes; the frame's origin plays no part.

      Parameters

      Returns Vector3

      The vector along the world axes

      const up = bitbybit.frame.vectorToWorld({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }), vector: [0, 0, 1] });
      
    • Turns a vector given along the world axes into one along a frame's axes, the reverse of vectorToWorld.

      Parameters

      Returns Vector3

      The vector along the frame's axes

      const local = bitbybit.frame.vectorToLocal({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }), vector: [0, 1, 0] });
      

    create

    • Builds a frame from where it sits, where its Z axis points and roughly where its X axis points.

      direction is turned square to normal and both are scaled to length 1, so they only have to be roughly right. A normal of zero length or a direction along it throws.

      Parameters

      • inputs: CreateFrameDto

        The origin, the normal and the rough X direction

      Returns Bit.Inputs.Base.Frame

      A new frame

      const tilted = bitbybit.frame.create({ origin: [0, 5, 0], normal: [0, 1, 1], direction: [1, 0, 0] });
      
    • Gives the world frame: its origin at zero, its X, Y and Z axes along the world's.

      Placing something on the world frame leaves it where it is, and it is the frame the other methods use when one is left out.

      Returns Bit.Inputs.Base.Frame

      The world frame

      const world = bitbybit.frame.world();
      const raised = bitbybit.frame.offset({ frame: world, distance: 5 });
    • Builds a frame lying in the XY plane: its X axis along the world X, its Y axis along the world Y and its normal along the world Z.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const floor = bitbybit.frame.xy({ origin: [0, 0, 2] });
      
    • Builds a frame lying in the YZ plane: its X axis along the world Y, its Y axis along the world Z and its normal along the world X.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const side = bitbybit.frame.yz({ origin: [3, 0, 0] });
      
    • Builds a frame lying in the ZX plane, the ground when Y points up: its X axis along the world Z, its Y axis along the world X and its normal along the world Y.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const ground = bitbybit.frame.zx({ origin: [0, 0, 0] });
      
    • Builds a frame from three points: where it sits, a point its X axis runs toward and a point on the side its Y axis points to.

      The normal follows by the right-hand rule. xPoint at origin, or three points on one line, throws.

      Parameters

      • inputs: ThreePointsDto

        The origin, a point along the X axis and a point in the plane

      Returns Bit.Inputs.Base.Frame

      A new frame

      const frame = bitbybit.frame.fromThreePoints({ origin: [0, 0, 0], xPoint: [4, 0, 0], planePoint: [0, 0, -3] });
      
    • Builds a frame from a point and a normal, choosing its X axis by a fixed rule.

      The same normal always gives the same X axis: square to the normal and to the world axis the normal leans on least. A normal of zero length throws.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const onSlope = bitbybit.frame.fromPointAndNormal({ origin: [2, 1, 0], normal: [0, 1, 1] });
      
    • Fits a frame to points that lie on or near one plane.

      It sits at their average. The normal follows their order by the right-hand rule, and X runs along their widest spread, toward the first point; with no widest spread, as around a square, X points at the first point. Fewer than three points, or nearly collinear ones, throw.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame in the plane that fits the points best

      const frame = bitbybit.frame.bestFit({ points: [[0, 0, 0], [4, 0.1, 0], [4, 3, 0.1], [0, 3, 0]] });
      

    frame in frame

    • Places a frame given in another frame's coordinates into the world: a frame within a frame.

      child is read as if parent were the world, so a child at the origin sits on parent and one lifted along Z rises along the parent's normal.

      Parameters

      • inputs: ChildFrameDto

        The parent frame and the child frame given in its coordinates

      Returns Bit.Inputs.Base.Frame

      The child frame in world coordinates

      const table = bitbybit.frame.zx({ origin: [0, 1, 0] });
      const onTable = bitbybit.frame.frameToWorld({ parent: table, child: bitbybit.frame.xy({ origin: [0.5, 0.2, 0] }) });
    • Places frames given in one parent frame's coordinates into the world, as frameToWorld places one: every child sits on parent as it would sit on the world.

      Parameters

      • inputs: ChildFramesDto

        The parent frame and the frames given in its coordinates

      Returns Bit.Inputs.Base.Frame[]

      The frames in world coordinates, in the same order

      const table = bitbybit.frame.zx({ origin: [0, 1, 0] });
      const spots = bitbybit.frame.grid({ countX: 3, countY: 2, spacingX: 0.4, spacingY: 0.4, centered: true });
      const onTable = bitbybit.frame.framesToWorld({ parent: table, children: spots });
    • Describes a frame given in world coordinates in another frame's coordinates, the reverse of frameToWorld.

      The result is where child sits and how it turns as seen from parent, as if parent were the world.

      Parameters

      • inputs: ChildFrameDto

        The parent frame and the child frame in world coordinates

      Returns Bit.Inputs.Base.Frame

      The child frame in the parent's coordinates

      const table = bitbybit.frame.zx({ origin: [0, 1, 0] });
      const seenFromTable = bitbybit.frame.frameToLocal({ parent: table, child: bitbybit.frame.world() });
    • Describes frames given in world coordinates in one parent frame's coordinates, the reverse of framesToWorld, as frameToLocal describes one.

      Parameters

      • inputs: ChildFramesDto

        The parent frame and the frames in world coordinates

      Returns Bit.Inputs.Base.Frame[]

      The frames in the parent's coordinates, in the same order

      const table = bitbybit.frame.zx({ origin: [0, 1, 0] });
      const seen = bitbybit.frame.framesToLocal({ parent: table, children: [bitbybit.frame.world(), bitbybit.frame.yz({ origin: [2, 0, 0] })] });

    matrices

    • Gives the transformation that moves anything from the world frame onto a frame.

      It takes the world origin to the frame's origin and the world axes to the frame's axes, and comes as a list holding one matrix, the form every transformation input takes.

      Parameters

      Returns TransformMatrixes

      The transformation onto the frame

      const onFrame = bitbybit.frame.toMatrix({ frame: bitbybit.frame.zx({ origin: [0, 2, 0] }) });
      const moved = bitbybit.point.transformPoints({ points: [[1, 0, 0]], transformation: onFrame });
    • Reads the frame a transformation puts the world frame on: where it moves the world origin and where it turns the world X and Z axes.

      Scaling is dropped, a shear keeps the Z axis and squares X to it, and a mirror keeps X and Z with the Y axis that follows from them. A perspective part throws.

      Parameters

      Returns Bit.Inputs.Base.Frame

      A new frame

      const turned = bitbybit.transforms.rotationCenterAxis({ center: [0, 0, 0], axis: [0, 1, 0], angle: 45 });
      const frame = bitbybit.frame.fromMatrix({ transformation: turned });
    • Gives the transformation that carries anything placed on one frame onto another, turning it the same way.

      Left out, from is the world frame, which makes this toMatrix of to. The result is a list holding one matrix.

      Parameters

      Returns TransformMatrixes

      The transformation from from onto to

      const from = bitbybit.frame.xy({ origin: [0, 0, 0] });
      const to = bitbybit.frame.zx({ origin: [0, 3, 0] });
      const carry = bitbybit.frame.matrixFromTo({ to, from });

    patterns

    • Lays out a rectangular grid of frames in a frame's plane, each turned the same way as that frame.

      The frames come row by row, along X first. Left out, frame is the world frame, so the grid lies in the XY plane.

      Parameters

      • inputs: GridDto

        The frame to follow, the counts and spacings, and whether to center the grid

      Returns Bit.Inputs.Base.Frame[]

      The frames of the grid

      const spots = bitbybit.frame.grid({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }), countX: 4, countY: 3, spacingX: 2, spacingY: 2, centered: true });
      
    • Lays out a ring of frames around a frame's normal, in its plane.

      Each is frame turned by its angle about the normal and moved out by radius along its turned X axis. A full turn spaces them evenly, a smaller angle puts one at each end, and a larger one throws. Left out, frame is the world frame.

      Parameters

      • inputs: PolarDto

        The frame to turn around, the count, radius, angles and whether frames turn

      Returns Bit.Inputs.Base.Frame[]

      The frames of the ring, in the direction of the angle

      const bolts = bitbybit.frame.polar({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }), count: 8, radius: 5, angle: 360, startAngle: 0, rotate: true });
      
    • Lays out a honeycomb of frames in a frame's plane, one at each hexagon's center, turned as that frame is.

      The hexagons have corners toward the frame's Y axis and flat sides toward X. Rows run along X, every second shifted by half a hexagon, and frames come row by row. Left out, frame is the world frame.

      Parameters

      • inputs: HexGridDto

        The frame to follow, the counts, the hexagon size and whether to center it

      Returns Bit.Inputs.Base.Frame[]

      The frames of the honeycomb

      const cells = bitbybit.frame.hexGrid({ frame: bitbybit.frame.zx({ origin: [0, 0, 0] }), countX: 5, countY: 4, radius: 1, centered: true });
      

    read

    • Reads where a frame sits: the point its three axes start from.

      Parameters

      Returns Point3

      The origin

    • Reads where a frame's Z axis points, as a vector of length 1.

      Parameters

      Returns Vector3

      The normal

    • Reads where a frame's X axis points, as a vector of length 1 square to the normal.

      Parameters

      Returns Vector3

      The X direction

    • Reads where a frame's Y axis points: the normal crossed with the direction, as a vector of length 1.

      Parameters

      Returns Vector3

      The Y direction