Bitbybit Docs
    Preparing search index...

    Class JSCADPolygon

    Building flat JSCAD shapes, the filled 2D regions that booleans combine and extrusions turn into solids. They lie in the XY plane: a shape made from points or a curve keeps only the X and Y coordinates, and the circle, ellipse, rectangle, square and star primitives take a 2D center. List outline points counter-clockwise.

    Index

    Constructors

    from

    • Builds a filled 2D shape from the outline points, taken in order and closed back to the first.

      Only X and Y are used, Z is dropped; repeated consecutive points are removed and at least three distinct points are needed. Counter-clockwise order gives a normal shape, clockwise gives a negative one.

      Parameters

      Returns Promise<JSCADEntity>

      The 2D shape

      const triangle = await bitbybit.jscad.polygon.createFromPoints({ points: [[0, 0, 0], [10, 0, 0], [5, 8, 0]] });
      
    • Builds a filled 2D shape from the points of a polyline, closed back to the first point whatever the polyline says.

      Only X and Y are used, Z is dropped; repeated consecutive points are removed and at least three distinct points are needed.

      Parameters

      Returns Promise<JSCADEntity>

      The 2D shape

      const shape = await bitbybit.jscad.polygon.createFromPolyline({ polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]], isClosed: true } });
      
    • Builds a filled 2D shape from a NURBS curve by sampling it into points and closing the outline.

      Only X and Y of the sampled points are used, Z is dropped.

      Parameters

      Returns Promise<JSCADEntity>

      The 2D shape

      This takes a verb-nurbs curve, and verb is deprecated for removal in the next major, so this goes with it. It is also the one method here that converts between two different CAD kernels, which belongs above a kernel-specific package rather than inside one. Build the polygon from points or from a polyline instead.

      const shape = await bitbybit.jscad.polygon.createFromCurve({ curve });
      
    • Builds a filled 2D shape from the points of a 2D path, closed back to the first point.

      Repeated consecutive points are removed and at least three distinct points are needed; a 2D shape or a solid throws an error.

      Parameters

      Returns Promise<JSCADEntity>

      The 2D shape

      const path = await bitbybit.jscad.path.createFromPoints({ points: [[0, 0], [10, 0], [10, 10]], closed: true });
      const shape = await bitbybit.jscad.polygon.createFromPath({ path });

    primitives

    • Builds a filled circle of the given radius around a 2D center; segments is the number of straight sides that approximate it.

      Parameters

      Returns Promise<JSCADEntity>

      The circle as a 2D shape

      const disc = await bitbybit.jscad.polygon.circle({ center: [0, 0], radius: 5, segments: 32 });
      
    • Builds a filled ellipse around a 2D center, with radius holding the X and Y half-sizes; segments is the number of straight sides that approximate it.

      Parameters

      Returns Promise<JSCADEntity>

      The ellipse as a 2D shape

      const oval = await bitbybit.jscad.polygon.ellipse({ center: [0, 0], radius: [10, 5], segments: 48 });
      
    • Builds a filled rectangle around a 2D center, with width along X and length along Y.

      Parameters

      Returns Promise<JSCADEntity>

      The rectangle as a 2D shape

      const plate = await bitbybit.jscad.polygon.rectangle({ center: [0, 0], width: 20, length: 10 });
      
    • Builds a filled rectangle with its four corners rounded by roundRadius, around a 2D center with width along X and length along Y.

      roundRadius must be less than half of the smaller side or an error is thrown; segments sets how smoothly each corner is faceted.

      Parameters

      • inputs: RoundedRectangleDto

        The center, the rounding radius, the segment count, the width and the length

      Returns Promise<JSCADEntity>

      The rounded rectangle as a 2D shape

      const plate = await bitbybit.jscad.polygon.roundedRectangle({ center: [0, 0], roundRadius: 2, segments: 16, width: 20, length: 10 });
      
    • Builds a filled square of side size around a 2D center, with its sides parallel to the axes.

      Parameters

      Returns Promise<JSCADEntity>

      The square as a 2D shape

      const tile = await bitbybit.jscad.polygon.square({ center: [0, 0], size: 10 });
      
    • Builds a filled star with vertices tips around a 2D center, the tips at outerRadius and the notches between them at innerRadius.

      startAngle in degrees turns the first tip away from the X axis. density matters only when innerRadius is 0: the notch radius is then derived from it, as in a pentagram with density 2.

      Parameters

      • inputs: Bit.Inputs.JSCAD.StarDto

        The center, the number of tips, the density, the two radii and the start angle

      Returns Promise<JSCADEntity>

      The star as a 2D shape

      const star = await bitbybit.jscad.polygon.star({ center: [0, 0], vertices: 5, density: 2, outerRadius: 10, innerRadius: 4, startAngle: 90 });