DotSCAD
Reduce the burden of mathematics when playing OpenSCAD
Install / Use
/learn @JustinSDK/DotSCADREADME
dotSCAD 3.3
Reduce the burden of mathematics/algorithm when playing OpenSCAD.
Introduction
Some of my 3D models require complex mathematics/algorithm. I extract them into dotSCAD. Hope it helps when you're playing OpenSCAD.
The idea of the name dotSCAD comes from the filename extension ".scad" of OpenSCAD.
Getting started
OpenSCAD uses three library locations, the installation library, built-in library, and user defined libraries. Check Setting OPENSCADPATH in OpenSCAD User Manual/Libraries for details.
I set OPENSCADPATH to the src folder of dotSCAD so all examples here start searching modules/functions from src.
Every public module/function has the same name as the .scad file. Here's an example using the line2d module:
use <line2d.scad>
line2d(p1 = [0, 0], p2 = [5, 0], width = 1);
The library uses directories to categorize some modules/functions. For example, vx_circle.scad exists in voxel directory. Prefix the directory name when using vx_circle.
use <voxel/vx_circle.scad>
points = vx_circle(radius = 10);
for(pt = points) {
translate(pt) square(1);
}
Examples
These examples incubate dotSCAD and dotSCAD refactors these examples. See examples.
API Reference
2D Module
Signature | Description
--|--
arc(radius, angle[, width, width_mode"]) | create an arc.
hexagons(radius, spacing, levels) | create hexagons in a hexagon.
line2d(p1, p2[, width, p1Style, p2Style]) | create a line from two points.
multi_line_text(lines[, line_spacing, size, font, ...]) | create multi-line text from a list of strings.
pie(radius, angle) | create polyline2de a pie (circular sector).
polyline2d(points[, width, startingStyle, endingStyle, ...]) | create a polyline from a list of [x, y] coordinates.
polygon_hull(points) | create a convex polygon by hulling a list of points. It avoids using hull and small 2D primitives to create the polygon.
rounded_square(size, corner_r[, center]) | create a rounded square in the first quadrant.
3D Module
Signature | Description
--|--
crystal_ball(radius[, theta, phi, thickness]) | create a crystal ball based on spherical coordinates (r, θ, φ) used in mathematics.
line3d(p1, p2[, diameter, p1Style, p2Style]) | create a 3D line from two points.
loft(sections[, slices]) | develop a smooth skin between crosssections with different geometries.
polyhedron_hull(points) | create a convex polyhedron by hulling a list of points. It avoids using hull and small 3D primitives to create the polyhedron.
polyline3d(points, diameter[, startingStyle, endingStyle]) | create a polyline from a list of [x, y, z].
rounded_cube(size, corner_r[, center]) | create a cube in the first octant.
rounded_cylinder(radius, h, round_r[, convexity, center]) | create a rounded cylinder.
sweep(sections[, triangles]) | develop a smooth skin from crosssections with the same number of sides.
Transformation
Signature | Description --|-- along_with(points, angles[, twist, scale, method]) | put children along the given path. If there's only one child, put the child for each point. bend(size, angle[, frags]) | bend a 3D object. hollow_out(shell_thickness) | hollow out a 2D object. shear([sx, sy, sz]) | shear all child elements along the X-axis, Y-axis, or Z-axis. select(i) | select module objects. polyline_join(points) | place a join on each point. Hull each pair of joins and union all convex hulls.
2D Function
Signature | Description --|-- bijection_offset(pts, d[, epsilon]) | move 2D outlines outward or inward by a given amount. Each point of the offsetted shape is paired with exactly one point of the original shape. contours(points, threshold) | compute contour polygons by applying marching squares to a rectangular list of numeric values. in_shape(shapt_pts, pt[, include_edge, epsilon]) | check whether a point is inside a shape. trim_shape(shape_pts, from, to[, epsilon]) | trim a tangled-edge shape to a non-tangled shape.
2D/3D Function
Signature | Description
--|--
angle_between(vt1, vt2) | return the angle between two vectors.
bezier_smooth(path_pts, round_d[, t_step, closed, angle_threshold]) | use bezier curves to smooth a path.
cross_sections(shape_pts, path_pts, angles[, twist, scale]) | given a 2D shape, points and angles along the path, this function returns all cross-sections.
in_polyline(line_pts, pt[, epsilon]) | check whether a point is on a line.
lines_intersection(line1, line2[, ext, epsilon]) | find the intersection of two line segments. Return [] if lines don't intersect.
path_scaling_sections(shape_pts, edge_path) | given an edge path with the first point at the outline of a shape, this function uses the path to calculate scaling factors and returns all scaled sections in the reversed order of the edge path.
midpt_smooth(points, n[, closed]) | given a 2D path, this function constructs a mid-point smoothed version by joining the mid-points of the lines of the path.
Path
Signature | Description
--|--
arc_path(radius, angle) | create an arc path.
archimedean_spiral(arm_distance, init_angle, point_distance, num_of_points[, rt_dir]) | get all points and angles on the path of an archimedean spiral.
bauer_spiral(n, radius = 1[, rt_dir]) | create visually even spacing of n points on the surface of the sphere. Successive points will all be approximately the same distance apart.
bezier_curve(t_step, points) | given a set of control points, this function returns points of the Bézier path.
bspline_curve(t_step, degree, points, knots, weights) | B-spline interpolation using de Boor's algorithm.
curve(t_step, points[, tightness]) | create a curved path. An implementation of Centripetal Catmull-Rom spline.
fibonacci_lattice(n, radius = 1[, dir]) | create visually even spacing of n points on the surface of the sphere. Nearest-neighbor points will all be approximately the same distance apart.
golden_spiral(from, to, point_distance[, rt_dir)] | get all points and angles on the path of a golden spiral based on Fibonacci numbers. The distance between two points is almost constant.
helix(radius, levels, level_dist[, vt_dir, rt_dir]) | get all points on the path of a spiral around a cylinder.
sphere_spiral(radius, za_step[, z_circles, begin_angle, end_angle, ...]) | create all points and angles on the path of a spiral around a sphere. It returns a vector of [[x, y, z], [ax, ay, az]].
torus_knot(p, q, phi_step) | generate a path of [The (p,q)-torus knot](https://en.wikipedia.org/wiki
Related Skills
node-connect
331.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
81.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
331.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
81.5kCommit, push, and open a PR
