2-D shapes

Pure-Python port of the 2-D shape generators from BOSL2’s shapes2d.scad (plus arc()). Each returns a Bosl2Shape2D – the 2-D counterpart of Bosl2Solid – so the geometry chains straight on:

square(20).offset(radius=2).fill().linear_extrude(height=4).show()

The 2-D object

Bosl2Shape2D wraps a native 2-D handle (reachable as .shape) and carries, as chained methods:

  • the 2-D operators – fill() (drop every hole), hull() (convex hull, optionally with more shapes/paths) and offset() (BOSL2’s radius=/delta= spelling);

  • the 2-D → 3-D extruders – linear_extrude(), rotate_extrude() and path_extrude(), each returning a Bosl2Solid;

  • the transforms, the CSG operators (|, &, -), the color.scad operators and the distributors.scad copiers, all returning a new Bosl2Shape2D.

fill() and hull() are also available as free functions (the OpenSCAD module form), and accept a Bosl2Shape2D, a raw native shape, a Path / Region, or a plain point list.

The same operators live on Path and Region (path.fill(), path.hull(), path.linear_extrude(height=...)), and Bosl2Solid.projection() comes back the other way, from a 3-D solid to a Bosl2Shape2D footprint.

Coverage of BOSL2 shapes2d.scad

BOSL2 shape

Status

Notes

square / rect

ported

plus rect_path for the point-list form

circle / ellipse

ported

regular_ngon / pentagon / hexagon / octagon

ported

right_triangle / trapezoid

ported

star, teardrop2d, egg, glued_circles, supershape, reuleaux_polygon

ported

squircle

ported

squircle() — the default "fg" (Fong-Garcia) style; the "superellipse" / "bezier" styles are not ported

jittered_poly, round2d, shell2d

ported

round2d / shell2d are rounding / shelling operators

arc

ported

lives here but is documented on the Drawing: path generators & renderers page (returns a Path)

text

ported

text()

keyhole

ported

keyhole()

ring

ported

ring() — the full-annulus form (radius1/radius2 or radius + ring_width); the arc / 3-point / corner / width+thickness forms are not ported

API reference

bosl2.shapes2d.Shape2DLike = ForwardRef('Bosl2Shape2D') | ForwardRef('PyOpenSCAD') | bosl2.paths.Path | collections.abc.Sequence[collections.abc.Sequence[float]]

a Bosl2Shape2D, a raw native 2-D handle, a Path / Region, or a [[x, y], ...] point list. _as_native_2d() reduces any of them to a raw native handle.

Type:

Anything the 2-D operators accept as a child

class bosl2.shapes2d.Bosl2Shape2D(shape, size=None, anchor=None)[source]

Bases: Distributable, Colorable

Wraps a native PyOpenSCAD 2-D shape, giving it the same fluent, chainable API that Bosl2Solid gives 3-D solids. Every shape constructor in this file returns one of these, as do polygon() and geometry().

The 2-D specific operations live here rather than being reached for through the raw native handle:

  • fill() – drop every hole, keeping only the outermost outline (OpenSCAD fill()).

  • hull() – the convex hull of this shape, optionally together with more shapes/paths (OpenSCAD hull()).

  • offset() – inset/outset, with BOSL2’s radius=/delta= spelling (the native offset() only understands r=).

  • linear_extrude() / rotate_extrude() – the 2-D -> 3-D operators, which return a Bosl2Solid so the result keeps the 3-D fluent API.

Transforms (translate/rotate/mirror/scale/multmatrix), the CSG operators (|, &, -), the colour operators (from Colorable) and the distributor copiers (from Distributable) all return a new Bosl2Shape2D. Anything else falls through __getattr__ to the native handle, re-wrapped as 2-D when it hands back native geometry.

Like Bosl2Solid this is composition, not a subclass of the native C-extension type: passing one directly into a native function that wants a raw handle needs an explicit .shape (or bosl2._helpers.unwrap()).

Parameters:
  • shape (PyOpenSCAD)

  • size (Sequence[float] | None)

  • anchor (Sequence[float] | str | None)

backend = 'csg'

which realize backend produced this shape – 2-D geometry is exact-CSG only (see bosl2/_backend.py); the SDF backend has no 2-D surface.

size

nominal [x, y] size for the shapes that have a genuine box size, else None

translate(v)[source]

Translate by v ([x, y], or [x, y, 0]).

Parameters:

v (Sequence[float])

Return type:

Bosl2Shape2D

move(v)

Translate by v ([x, y], or [x, y, 0]).

Parameters:

v (Sequence[float])

Return type:

Bosl2Shape2D

rotate(*a, **k)[source]

Rotate about the Z axis. A bare scalar angle is accepted (BOSL2 rot(a)); the native 2-D rotate only takes the 3-vector form.

Parameters:
  • a (Any)

  • k (Any)

Return type:

Bosl2Shape2D

rot(*a, **k)

Rotate about the Z axis. A bare scalar angle is accepted (BOSL2 rot(a)); the native 2-D rotate only takes the 3-vector form.

Parameters:
  • a (Any)

  • k (Any)

Return type:

Bosl2Shape2D

spin(*a, **k)

Rotate about the Z axis. A bare scalar angle is accepted (BOSL2 rot(a)); the native 2-D rotate only takes the 3-vector form.

Parameters:
  • a (Any)

  • k (Any)

Return type:

Bosl2Shape2D

mirror(v)[source]

Mirror across the line through the origin normal to v.

Parameters:

v (Sequence[float])

Return type:

Bosl2Shape2D

scale(v)[source]

Scale by v (a scalar, or [x, y]).

Parameters:

v (float | Sequence[float])

Return type:

Bosl2Shape2D

multmatrix(m)[source]
Parameters:

m (Sequence[Sequence[float]])

Return type:

Bosl2Shape2D

right(x)[source]
Parameters:

x (float)

Return type:

Bosl2Shape2D

left(x)[source]
Parameters:

x (float)

Return type:

Bosl2Shape2D

back(y)[source]
Parameters:

y (float)

Return type:

Bosl2Shape2D

forward(y)[source]
Parameters:

y (float)

Return type:

Bosl2Shape2D

fwd(y)
Parameters:

y (float)

Return type:

Bosl2Shape2D

xflip(x=0.0)[source]

Mirror across the vertical line at x (BOSL2 xflip()).

Parameters:

x (float)

Return type:

Bosl2Shape2D

yflip(y=0.0)[source]

Mirror across the horizontal line at y (BOSL2 yflip()).

Parameters:

y (float)

Return type:

Bosl2Shape2D

offset(radius=None, delta=None, chamfer=False, fn=None, fa=None, fs=None)[source]

Inset (negative) or outset (positive) the outline.

radius rounds the joins it creates, delta keeps them sharp (or bevels them with chamfer=True) – BOSL2’s spelling of OpenSCAD’s r=/delta=. Give exactly one.

Parameters:
  • radius (float | None)

  • delta (float | None)

  • chamfer (bool)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

fill()[source]

This shape with every hole filled in – only the outermost outline survives (OpenSCAD fill()).

Useful for recovering the solid footprint of a shape you have already punched holes in, e.g. to build a backing plate for it, or to close up the interior loops of text().

Examples

plate = s2.square(40) - s2.circle(radius=8)
plate.fill().linear_extrude(height=2).show()

⬇ Download STL mesh

Return type:

Bosl2Shape2D

hull(*others)[source]

The convex hull of this shape (OpenSCAD hull()).

With arguments, the hull of this shape together with each of others – any mix of Bosl2Shape2D, native 2-D shapes, Path / Region, or plain [[x, y], ...] point lists.

Examples

slot = s2.circle(radius=5).hull(s2.circle(radius=5).right(30))
slot.linear_extrude(height=3).show()

⬇ Download STL mesh

Parameters:

others (Shape2DLike)

Return type:

Bosl2Shape2D

linear_extrude(height, center=False, twist=0.0, scale=1, slices=None, convexity=None, **kwargs)[source]

Extrude this 2-D shape height along +Z into a 3-D solid.

Parameters:
  • height (float) – extrusion height

  • center (bool) – centre the result on z=0 rather than starting at z=0 (default False)

  • twist (float) – degrees to rotate the top face relative to the bottom (default 0)

  • scale (float | Sequence[float]) – scale factor of the top face, a scalar or [x, y] (default 1)

  • slices (int | None) – number of intermediate layers (default: from the twist)

  • convexity (int | None) – rendering hint for self-overlapping cross-sections

  • kwargs (Any) – any further native linear_extrude() parameter (origin, fn, …)

Returns:

A Bosl2Solid.

Return type:

Bosl2Solid

Examples

s2.star(n=5, r=30, ir=15).linear_extrude(height=6, twist=45).show()
_images/a80d683a1b93a153.png
rotate_extrude(angle=360.0, convexity=None, fn=None, fa=None, fs=None, **kwargs)[source]

Revolve this 2-D shape about the Y axis into a 3-D solid (OpenSCAD rotate_extrude()).

The shape must lie entirely on one side of the axis. angle sweeps less than a full revolution.

Returns:

A Bosl2Solid.

Parameters:
  • angle (float)

  • convexity (int | None)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

  • kwargs (Any)

Return type:

Bosl2Solid

path_extrude(path, **kwargs)[source]

Sweep this 2-D shape along path (a Path3D or point list), via the native path_extrude().

Returns:

A Bosl2Solid.

Parameters:
  • path (Sequence[Sequence[float]])

  • kwargs (Any)

Return type:

Bosl2Solid

bounds()[source]

This shape’s axis-aligned bounding box as (center, size) – both [x, y] float lists in the shape’s current frame (the 2-D form of bounds()).

Prefers the native bbox, which always reflects the current geometry; falls back to the tracked nominal size/anchor when the native accessors aren’t available (the numeric test mock) and the shape hasn’t been moved since construction.

Return type:

tuple[list[float], list[float]]

bosl2.shapes2d.fill(children)[source]

children with every hole filled in – only the outermost outline survives (OpenSCAD fill(), the module form of Bosl2Shape2D.fill()).

Parameters:

children (Shape2DLike) – the 2-D shape to fill (a Bosl2Shape2D, a native shape, a Path / Region, or a point list)

Return type:

Bosl2Shape2D

bosl2.shapes2d.hull(*children)[source]

The 2-D convex hull of children (OpenSCAD hull(), the module form of Bosl2Shape2D.hull()).

Parameters:

children (Shape2DLike | Sequence[Shape2DLike]) – the 2-D shapes to hull – any mix of Bosl2Shape2D, native shapes, Path / Region, or point lists. A single list/tuple of shapes is also accepted.

Return type:

Bosl2Shape2D

bosl2.shapes2d.square(size=1, center=None, anchor=[0, 0, 0], spin=None)[source]

A rectangle, built with the builtin square(), with BOSL2-style anchor/spin support.

Parameters:
  • size (float | Sequence[float]) – size of the square; a scalar uses the same size for X and Y

  • center (bool | None) – if given, overrides anchor (True -> CENTER, False -> FRONT+LEFT)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float | None) – Z-axis rotation in degrees after anchor (default 0)

Return type:

Bosl2Shape2D

bosl2.shapes2d.rect(size=1, rounding=0, atype='box', chamfer=0, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A rectangle with optional rounded or chamfered corners.

Note: negative rounding/chamfer (BOSL2’s “external roundover spikes”) is not supported here.

Parameters:
  • size (float | Sequence[float]) – size of the rectangle; a scalar uses the same size for X and Y

  • rounding (float | Sequence[float]) – corner rounding radius, or per-corner list [X+Y+,X-Y+,X-Y-,X+Y-] (default 0)

  • atype (str) – anchor type, “box” (bounding box) or “perim” (rounded/chamfered perimeter) (default “box”)

  • chamfer (float | Sequence[float]) – corner chamfer size, or per-corner list [X+Y+,X-Y+,X-Y-,X+Y-] (default 0)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides for rounded corners

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.rect_path(size=1, rounding=0, chamfer=0, anchor=[0, 0, 0], fn=None, fa=None, fs=None)[source]

The points of a (optionally rounded/chamfered) rectangle – BOSL2’s rect() in its function form, as opposed to rect() which returns 2-D geometry (a Bosl2Shape2D).

Use this when the rectangle is an input to further path math (e.g. a profile fed to base_bgtk.PolygonPrism()), not something to draw.

Usage:

rect_path([20, 4], rounding=[-3, -3, 0, 0], anchor=TOP + LEFT)
Parameters:
  • size (float | Sequence[float]) – [x, y] size (or a single number for a square)

  • rounding (float | Sequence[float]) – corner radius; a single value or per-corner list. Negative = concave.

  • chamfer (float | Sequence[float]) – corner chamfer; a single value or per-corner list

  • anchor (Sequence[float]) – BOSL2 anchor the path is translated onto (default CENTER)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

list[list[float]]

Note

For small radii this can emit one more point per corner than the real BOSL2 does (BOSL2 rounds the corner-arc segment count, this rounds up); the arc geometry is identical, only the sampling differs.

bosl2.shapes2d.circle(radius=None, diameter=None, points=None, corner=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A circle, built with the builtin circle(), by radius/diameter, or fit to points.

If corner is given three 2-D points, the circle is centered to be tangent to both segments of that path, on the inside corner. If points is given three 2-D points, the circle is centered and sized to pass through all three points. Anchor/spin are ignored for the corner/points forms, matching BOSL2.

Parameters:
  • radius (float | None) – radius of the circle

  • diameter (float | None) – diameter of the circle

  • points (Sequence[Sequence[float]] | None) – three 2-D points the circle should pass through

  • corner (Sequence[Sequence[float]] | None) – three 2-D points defining a path the circle should be tangent to

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.polygon(path, anchor=[0, 0, 0], spin=0)[source]

A polygon, built with the builtin polygon(), with anchor/spin support.

Parameters:
  • path (Sequence[Sequence[float]]) – polygon path

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

Return type:

Bosl2Shape2D

bosl2.shapes2d.ellipse(radius=None, diameter=None, realign=False, circum=False, uniform=False, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

An ellipse (approximated as a polygon), built directly with polygon().

Note: uniform (equal-length approximating segments) is not implemented; segments are evenly spaced by angle instead.

Parameters:
  • radius (float | Sequence[float] | None) – radius of the circle, or pair of semi-axes of the ellipse

  • diameter (float | Sequence[float] | None) – diameter of the circle, or pair giving the full X/Y axis lengths

  • realign (bool) – shift the first polygon point off the X+ axis (default False)

  • circum (bool) – circumscribe rather than inscribe the ideal ellipse (default False)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides

  • uniform (bool)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.regular_ngon(sides=6, radius=None, diameter=None, outer_radius=None, outer_diameter=None, inner_radius=None, inner_diameter=None, side=None, rounding=0, realign=False, align_tip=None, align_side=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A regular N-gon (equilateral, equiangular polygon), built directly with polygon().

Note: BOSL2’s outer-radius parameter is named or, which collides with the Python keyword or; it is exposed here as outer_radius instead.

Parameters:
  • sides (int) – number of sides (default 6)

  • radius/outer_radius – outside radius, at the points (BOSL2 or)

  • diameter/outer_diameter – outside diameter, at the points

  • inner_radius (float | None) – inside radius, at the center of the sides

  • inner_diameter (float | None) – inside diameter, at the center of the sides

  • side (float | None) – length of each side

  • rounding (float) – rounding radius for the tips of the polygon (default 0)

  • realign (bool) – put the midpoint of the last edge (instead of vertex 0) on the X+ axis (default False)

  • align_tip (Sequence[float] | None) – rotate so the first vertex points in this 2-D direction (applied before spin)

  • align_side (Sequence[float] | None) – rotate so the normal of side 0 points in this 2-D direction (applied before spin)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides for rounded tips

  • radius (float | None)

  • diameter (float | None)

  • outer_radius (float | None)

  • outer_diameter (float | None)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.pentagon(radius=None, diameter=None, outer_radius=None, outer_diameter=None, inner_radius=None, inner_diameter=None, side=None, rounding=0, realign=False, align_tip=None, align_side=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A regular pentagon. See regular_ngon() for argument details.

Parameters:
  • radius (float | None)

  • diameter (float | None)

  • outer_radius (float | None)

  • outer_diameter (float | None)

  • inner_radius (float | None)

  • inner_diameter (float | None)

  • side (float | None)

  • rounding (float)

  • realign (bool)

  • align_tip (Sequence[float] | None)

  • align_side (Sequence[float] | None)

  • anchor (Sequence[float])

  • spin (float)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.hexagon(radius=None, diameter=None, outer_radius=None, outer_diameter=None, inner_radius=None, inner_diameter=None, side=None, rounding=0, realign=False, align_tip=None, align_side=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A regular hexagon. See regular_ngon() for argument details.

Parameters:
  • radius (float | None)

  • diameter (float | None)

  • outer_radius (float | None)

  • outer_diameter (float | None)

  • inner_radius (float | None)

  • inner_diameter (float | None)

  • side (float | None)

  • rounding (float)

  • realign (bool)

  • align_tip (Sequence[float] | None)

  • align_side (Sequence[float] | None)

  • anchor (Sequence[float])

  • spin (float)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.octagon(radius=None, diameter=None, outer_radius=None, outer_diameter=None, inner_radius=None, inner_diameter=None, side=None, rounding=0, realign=False, align_tip=None, align_side=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A regular octagon. See regular_ngon() for argument details.

Parameters:
  • radius (float | None)

  • diameter (float | None)

  • outer_radius (float | None)

  • outer_diameter (float | None)

  • inner_radius (float | None)

  • inner_diameter (float | None)

  • side (float | None)

  • rounding (float)

  • realign (bool)

  • align_tip (Sequence[float] | None)

  • align_side (Sequence[float] | None)

  • anchor (Sequence[float])

  • spin (float)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.right_triangle(size=[1, 1], center=None, anchor=None, spin=0)[source]

A right triangle, built directly with polygon().

Parameters:
  • size (Sequence[float]) – [width, length] of the right triangle

  • center (bool | None) – True forces anchor=CENTER, False forces anchor=[-1,-1] (default: use anchor=)

  • anchor (Sequence[float] | None) – anchor point (default: [-1,-1], the right-angle corner)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

Return type:

Bosl2Shape2D

bosl2.shapes2d.trapezoid(height=None, width1=None, width2=None, angle=None, shift=0, chamfer=0, rounding=0, flip=False, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A trapezoid with parallel front and back sides, built directly with polygon().

Parameters:
  • height (float | None) – Y-axis height of the trapezoid

  • width1 (float | None) – X-axis width of the front end

  • width2 (float | None) – X-axis width of the back end

  • angle (float | None) – if given in place of height/width1/width2, the missing value is derived from this angle

  • shift (float) – X-axis shift of the back of the trapezoid (default 0)

  • rounding (float | Sequence[float]) – corner rounding radius, or per-corner list [X+Y+,X-Y+,X-Y-,X+Y-] (default 0)

  • chamfer (float | Sequence[float]) – corner chamfer length, or per-corner list [X+Y+,X-Y+,X-Y-,X+Y-] (default 0)

  • flip (bool) – point negative roundings/chamfers forward/back instead of left/right (default False)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides for rounded corners

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.star(tips=None, radius=None, inner_radius=None, diameter=None, outer_radius=None, outer_diameter=None, inner_diameter=None, step=None, realign=False, align_tip=None, align_pit=None, anchor=[0, 0, 0], spin=0, atype='hull')[source]

An N-pointed star polygon, built directly with polygon().

Note: BOSL2’s outer-radius parameter is named or, which collides with the Python keyword or; it is exposed here as outer_radius instead.

Parameters:
  • tips (int | None) – number of stellate tips

  • radius/outer_radius – radius to the tips of the star (BOSL2 or)

  • inner_radius (float | None) – radius to the inner corners of the star

  • diameter/outer_diameter – diameter to the tips of the star

  • inner_diameter (float | None) – diameter to the inner corners of the star

  • step (int | None) – compute inner radius by virtually drawing a line step tips around the star (2 <= step <

  • tips/2)

  • realign (bool) – put the midpoint of the last edge (instead of vertex 0) on the X+ axis (default False)

  • align_tip (Sequence[float] | None) – rotate so the first tip points in this 2-D direction (applied before spin)

  • align_pit (Sequence[float] | None) – rotate so the first inner corner points in this 2-D direction (applied before spin)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • atype (str) – anchor method; only “hull” is implemented here (default “hull”)

  • radius (float | None)

  • diameter (float | None)

  • outer_radius (float | None)

  • outer_diameter (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.jittered_poly(path, dist=0.001953125)[source]

Adds tiny random jitter to a path’s points.

Used to work around rendering artifacts from exactly-overlapping coplanar faces.

Parameters:
  • path (Sequence[Sequence[float]]) – the path to add jitter to

  • dist (float) – the amount to jitter points by (default 1/512)

Return type:

list[list[float]]

bosl2.shapes2d.teardrop2d(radius=None, angle=45, cap_height=None, diameter=None, circum=False, realign=False, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A 2-D teardrop shape, useful for 3D-printable horizontal holes, built directly with polygon().

Note: circum is approximated the same way as the inscribed case here (BOSL2’s exact ray-intersection construction for circum=True is not reproduced).

Parameters:
  • radius (float | None) – radius of the circular part (default 1)

  • angle (float) – angle of the hat walls from the Y axis in degrees (default 45)

  • cap_height (float | None) – height above center to truncate the shape (default: no truncation)

  • diameter (float | None) – diameter of the circular portion (alternative to radius)

  • circum (bool) – produce a circumscribing teardrop (default False)

  • realign (bool) – flip whether the bottom is a point or a flat (default False)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.egg(length=None, radius1=None, radius2=None, arc_radius=None, diameter1=None, diameter2=None, arc_diameter=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

An egg-shaped 2-D outline, made of two circles joined by tangent arcs, built directly with polygon().

Parameters:
  • length (float | None) – length of the egg

  • radius1 (float | None) – radius of the left-hand circle

  • radius2 (float | None) – radius of the right-hand circle

  • arc_radius (float | None) – radius of the joining arcs

  • diameter1 (float | None) – diameter of the left-hand circle (alternative to radius1)

  • diameter2 (float | None) – diameter of the right-hand circle (alternative to radius2)

  • arc_diameter (float | None) – diameter of the joining arcs (alternative to arc_radius)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.glued_circles(radius=None, spread=10, tangent=30, diameter=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

Two circles joined by a curved waist, like a dumbbell, built directly with polygon().

Parameters:
  • radius (float | None) – radius of the end circles

  • spread (float) – distance between the centers of the end circles (default 10)

  • tangent (float) – angle in degrees of the tangent point of the joining arcs, from the Y axis (default 30)

  • diameter (float | None) – diameter of the end circles (alternative to radius)

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.supershape(step=0.5, count=None, m1=4, m2=None, n1=None, n2=None, n3=None, a=1, b=None, radius=None, diameter=None, anchor=[0, 0, 0], spin=0, atype='hull')[source]

A 2-D shape from the superformula, built directly with polygon().

Parameters:
  • step (float) – angle step size for sampling the superformula (smaller = slower, more accurate) (default 0.5)

  • count (int | None) – number of output points, an alternative to step

  • m1 (float) – superformula m1 argument (default 4)

  • m2 (float | None) – superformula m2 argument (default: same as m1)

  • n1 (float | None) – superformula n1 argument (default 1)

  • n2 (float | None) – superformula n2 argument (default: same as n1)

  • n3 (float | None) – superformula n3 argument (default: same as n2)

  • a (float) – superformula a argument (default 1)

  • b (float | None) – superformula b argument (default: same as a)

  • radius (float | None) – scale the shape to fit in a circle of this radius

  • diameter (float | None) – scale the shape to fit in a circle of this diameter

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • atype (str) – anchor method; only “hull” is implemented here (default “hull”)

Return type:

Bosl2Shape2D

bosl2.shapes2d.squircle_radius_fg(squareness, radius, angle)[source]

The Fong-Garcia squircle radius at angle degrees for squareness squareness and size radius.

Parameters:
  • squareness (float)

  • radius (float)

  • angle (float)

Return type:

float

bosl2.shapes2d.squircle(size, squareness=0.5, style='fg', anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A squircle – a rounded square that morphs between a square and a circle (BOSL2 squircle()).

squareness runs 0 (a circle) to 1 (a square). Only the default "fg" (Fong-Garcia) style is ported; the "superellipse" and "bezier" styles are not.

Parameters:
  • size – scalar or [x, y] size of the bounding box

  • squareness (float) – 0 (circle) .. 1 (square); default 0.5

  • style (str) – only “fg” is supported

  • anchor/spin – standard BOSL2 2-D anchor / spin

  • fn/fa/fs – smoothness overrides

  • anchor (Sequence[float])

  • spin (float)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

Examples

s2.squircle(40, squareness=0.7).linear_extrude(height=5).show()

⬇ Download STL mesh

bosl2.shapes2d.keyhole(length=None, radius1=None, radius2=None, shoulder_radius=0, diameter1=None, diameter2=None, _length=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A keyhole slot – a small circle joined to a larger one by tangent shoulders (BOSL2 keyhole()).

Parameters:
  • length (float | None) – overall length between the two circle centers (default 15)

  • radius1/diameter1 – radius/diameter of the small (bottom) circle (default 5)

  • radius2/diameter2 – radius/diameter of the large (top) circle (default 10)

  • shoulder_radius (float) – fillet radius where the shoulders meet the circles (default 0)

  • anchor/spin – standard BOSL2 2-D anchor / spin

  • radius1 (float | None)

  • radius2 (float | None)

  • diameter1 (float | None)

  • diameter2 (float | None)

  • anchor (Sequence[float])

  • spin (float)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

Examples

s2.keyhole(length=25, radius1=4, radius2=9, shoulder_radius=2).linear_extrude(height=4).show()

⬇ Download STL mesh

bosl2.shapes2d.ring(sides=None, ring_width=None, radius=None, radius1=None, radius2=None, diameter=None, diameter1=None, diameter2=None, angle=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A 2-D ring (annulus) between two concentric radii (BOSL2 ring(), full-annulus form).

Give either both radii (radius1/radius2 or diameter1/diameter2) or one radius plus ring_width. The arc / 3-point / corner / width+thickness forms of BOSL2 ring() are not ported.

Parameters:
  • radius1/radius2 (or diameter1/diameter2) – the two radii/diameters

  • ring_width (float | None) – one radius plus the wall width

  • sides (int | None) – number of sides (overrides the smoothness overrides)

  • anchor/spin – standard BOSL2 2-D anchor / spin

  • ring_width

  • radius (float | None)

  • radius1 (float | None)

  • radius2 (float | None)

  • diameter (float | None)

  • diameter1 (float | None)

  • diameter2 (float | None)

  • angle (float | None)

  • anchor (Sequence[float])

  • spin (float)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

Examples

s2.ring(radius=20, ring_width=4).linear_extrude(height=5).show()

⬇ Download STL mesh

bosl2.shapes2d.reuleaux_polygon(sides=3, radius=None, diameter=None, anchor=[0, 0, 0], spin=0, fn=None, fa=None, fs=None)[source]

A Reuleaux polygon (constant-width curved-side shape), built directly with polygon().

Parameters:
  • sides (int) – number of “sides”; must be an odd positive number (default 3)

  • radius (float | None) – scale the shape to fit in a circle of this radius

  • diameter (float | None) – scale the shape to fit in a circle of this diameter

  • anchor (Sequence[float]) – anchor point (default CENTER)

  • spin (float) – Z-axis rotation in degrees after anchor (default 0)

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.text(text, size=10, font='Liberation Sans', halign=None, valign=None, spacing=1.0, direction='ltr', language='en', script='latin', anchor='baseline', spin=0)[source]

2-D text, built directly with the builtin text() (which already supports halign/valign).

Parameters:
  • text (str) – text to create

  • size (float) – font size (default 10)

  • font (str) – font to use (default “Liberation Sans”)

  • halign (str | None) – horizontal alignment: “left”, “center”, “right” (default “center”)

  • valign (str | None) – vertical alignment: “top”, “center”, “baseline”, “bottom” (default: anchor)

  • spacing (float) – relative spacing multiplier between characters (default 1.0)

  • direction (str) – text direction: “ltr”, “rtl”, “ttb”, “btt” (default “ltr”)

  • language (str) – language the text is in (default “en”)

  • script (str) – script the text is in (default “latin”)

  • anchor (str) – vertical alignment fallback used when valign isn’t given (default “baseline”)

  • spin (float) – Z-axis rotation in degrees (default 0)

Return type:

Bosl2Shape2D

bosl2.shapes2d.round2d(radius=None, outer_radius=None, inner_radius=None, children=None, fn=None, fa=None, fs=None)[source]

Rounds the concave and/or convex corners of arbitrary 2-D children, via chained .offset() calls.

Giving radius rounds all corners; inner_radius alone rounds only concave corners; outer_radius alone rounds only convex corners; giving both rounds each to a different radius.

Note: BOSL2’s outer-radius parameter is named or, exposed here as outer_radius.

Parameters:
  • radius (float | None) – radius to round all concave and convex corners to

  • outer_radius (float | None) – radius to round only convex (outside) corners to (BOSL2 or)

  • inner_radius (float | None) – radius to round only concave (inside) corners to

  • children (Bosl2Shape2D | PyOpenSCAD | None) – the 2-D solid(s) to round

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D

bosl2.shapes2d.shell2d(thickness=None, outer_radius=0, inner_radius=0, children=None, fn=None, fa=None, fs=None)[source]

Creates a hollow shell from 2-D children, with optional rounding.

Note: BOSL2’s outer-radius parameter is named or, exposed here as outer_radius.

Parameters:
  • thickness (float | Sequence[float] | None) – shell thickness; positive expands outward, negative shrinks inward, or a 2-element list to do both

  • outer_radius (float | Sequence[float]) – rounding radius for outside corners of the shell (BOSL2 or); a [CONVEX,CONCAVE] pair rounds those corner types separately (default 0)

  • inner_radius (float | Sequence[float]) – rounding radius for inside corners of the shell; a [CONVEX,CONCAVE] pair rounds those corner types separately (default 0)

  • children (Bosl2Shape2D | PyOpenSCAD | None) – the 2-D solid(s) to shell

  • fn/fa/fs – arc smoothness overrides

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Shape2D