dotSCAD 3.0
Reduce the burden of mathematics/algorithm when playing OpenSCAD.
Introduction
This version Breaks Backward Compatibility and requires OpenSCAD 2021.01 or later!! Please see Release Notes. You can still download v2.5 or older versions from Releases.
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.
Get Started
OpenSCAD uses three library locations, the installation library, built-in library, and user defined libraries. It's convenient to set OPENSCADPATH
. 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 or functions from src
.
Every module or function is located in the file which has the same name as the module or the function. For example, if you want to use the line2d
module to draw a line, use <line2d.scad>;
first.
use <line2d.scad>;
line2d(p1 = [0, 0], p2 = [5, 0], width = 1);
Some module files are organized in a directory. For example, px_circle.scad exists in pixel
directory. You have to prefix the directory name when including px_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.
Documentation
2D Module
arc(radius, angle, width = 1, width_mode = "LINE_CROSS")
hexagons(radius, spacing, levels)
hull_polyline2d(points, width = 1)
line2d(p1, p2, width = 1, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE")
multi_line_text(lines, line_spacing = 15, size = 10, font = "Arial", ...)
pie(radius, angle)
polyline2d(points, width = 1, startingStyle = "CAP_SQUARE", endingStyle = "CAP_SQUARE", ...)
polygon_hull(points)
rounded_square(size, corner_r, center = false)
3D Module
crystal_ball(radius, theta = 360, phi = 180, thickness = undef)
function_grapher(points, thickness = 1, style = "FACES")
hull_polyline3d(points, diameter = 1)
line3d(p1, p2, diameter = 1, p1Style = "CAP_CIRCLE", p2Style = "CAP_CIRCLE")
loft(sections, slices = 1)
polyhedron_hull(points)
polyline3d(points, diameter, startingStyle = "CAP_CIRCLE", endingStyle = "CAP_CIRCLE")
rounded_cube(size, corner_r, center = false)
rounded_cylinder(radius, h, round_r, convexity = 2, center = false)
starburst(r1, r2, n, height)
sweep(sections, triangles = "SOLID")
Transformation
along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE")
bend(size, angle, frags = 24)
hollow_out(shell_thickness)
shear(sx = [0, 0], sy = [0, 0], sz = [0, 0])
2D Function
bijection_offset(pts, d, epsilon = 0.0001)
contours(points, threshold)
in_shape(shapt_pts, pt, include_edge = false, epsilon = 0.0001)
trim_shape(shape_pts, from, to, epsilon = 0.0001)
2D/3D Function
angle_between(vt1, vt2)
bezier_surface(t_step, ctrl_pts)
bezier_smooth(path_pts, round_d, t_step = 0.1, closed = false, angle_threshold = 0)
cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0)
in_polyline(line_pts, pt, epsilon = 0.0001)
lines_intersection(line1, line2, ext = false, epsilon = 0.0001)
paths2sections(paths)
path_scaling_sections(shape_pts, edge_path)
midpt_smooth(points, n, closed = false)
Path
arc_path(radius, angle)
archimedean_spiral(arm_distance, init_angle, point_distance, num_of_points, rt_dir = "CT_CLK")
bauer_spiral(n, radius = 1, rt_dir = "CT_CLK")
bezier_curve(t_step, points)
bspline_curve(t_step, degree, points, knots, weights)
curve(t_step, points, tightness = 0)
fibonacci_lattice(n, radius = 1, dir = "CT_CLK")
golden_spiral(from, to, point_distance, rt_dir = "CT_CLK")
helix(radius, levels, level_dist, vt_dir = "SPI_DOWN", rt_dir = "CT_CLK")
sphere_spiral(radius, za_step, z_circles = 1, begin_angle = 0, end_angle = 0, ...)
torus_knot(p, q, phi_step)
Extrusion
bend_extrude(size, thickness, angle, frags = 24)
box_extrude(height, shell_thickness, bottom_thickness, offset_mode = "delta", chamfer = false, ...)
ellipse_extrude(semi_minor_axis, height, center = false, convexity = 10, twist = 0, slices = 20)
rounded_extrude(size, round_r, angle = 90, twist = 0, convexity = 10)
stereographic_extrude(shadow_side_leng)
2D Shape
shape_arc(radius, angle, width, width_mode = "LINE_CROSS")
shape_circle(radius, n)
shape_cyclicpolygon(sides, circle_r, corner_r)
shape_ellipse(axes)
shape_liquid_splitting(radius, centre_dist, tangent_angle = 30, t_step = 0.1)
shape_path_extend(stroke_pts, path_pts, scale = 1.0, closed = false)
shape_pentagram(r)
shape_pie(radius, angle)
shape_square(size, corner_r = 0)
shape_starburst(r1, r2, n)
shape_superformula(phi_step, m1, m2, n1, n2 = 1, n3 = 1, a = 1, b = 1)
shape_taiwan(h, distance = 0)
shape_trapezium(length, h, corner_r = 0)
2D Shape Extrusion
archimedean_spiral_extrude(shape_pts, arm_distance, init_angle, point_distance, num_of_points, ...)
golden_spiral_extrude(shape_pts, from, to, point_distance, ...)
helix_extrude(shape_pts, radius, levels, level_dist, ...)
path_extrude(shape_pts, path_pts, ...)
ring_extrude(shape_pts, radius, angle = 360, ...)
sphere_spiral_extrude(shape_pts, radius, za_step, ...)
Util
- list
util/bsearch(sorted, target)
util/has(lt, elem, sorted = false)
util/find_index(lt, test)
util/dedup(lt, ...)
util/flat(lt, depth = 1)
util/reverse(lt)
util/slice(lt, begin, end)
util/sort(lt, by = "idx", idx = 0)
util/sum(lt)
util/swap(lt, i, j)
util/zip(lts, combine)
util/every(lt, test)
util/some(lt, test)
- random
- string
- math
- set
- map
Matrix
matrix/m_determinant(m)
matrix/m_mirror(v)
matrix/m_rotation(a, v)
matrix/m_scaling(s)
matrix/m_shearing(sx = [0, 0], sy = [0, 0], sz = [0, 0])
matrix/m_translation(v)
Point Transformation
ptf/ptf_bend(size, point, radius, angle)
ptf/ptf_circle(size, point)
ptf/ptf_ring(size, point, radius, angle = 360, twist = 0)
ptf/ptf_rotate(point, a, v)
ptf/ptf_sphere(size, point, radius, angle = [180, 360])
ptf/ptf_torus(size, point, radius, angle = [360, 360], twist = 0)
ptf/ptf_x_twist(size, point, angle)
ptf/ptf_y_twist(size, point, angle)
Turtle
turtle/footprints2(cmds, start = [0, 0])
turtle/footprints3(cmds, start = [0, 0, 0])
turtle/lsystem2(axiom, rules, n, angle, leng = 1, heading = 0, ...)
turtle/lsystem3(axiom, rules, n, angle, leng = 1, heading = 0, ...)
turtle/t2d(t, cmd, point, angle, leng)
turtle/t3d(t, cmd, point, unit_vectors, leng, angle)
Voxel
voxel/vx_ascii(char, center = false, invert = false)
voxel/vx_bezier(p1, p2, p3, p4)
voxel/vx_circle(radius, filled = false)
voxel/vx_contour(points, sorted = false)
voxel/vx_curve(points, tightness = 0)
voxel/vx_cylinder(r, h, filled = false, thickness = 1)
voxel/vx_difference(points1, points2)
voxel/vx_from(binaries, center = false, invert = false)
voxel/vx_gray(levels, center = false, invert = false, normalize = false)
voxel/vx_intersection(points1, points2)
voxel/vx_line(p1, p2)
voxel/vx_polygon(points, filled = false)
voxel/vx_polyline(points)
voxel/vx_sphere(radius, filled = false, thickness = 1)
voxel/vx_union(points1, points2)
Part
part/cone(radius, length = 0, spacing = 0.5, angle = 50, void = false, ends = false)
part/connector_peg(radius, height, spacing = 0.5, void = false, ends = false)
part/joint_T(shaft_r, shaft_h, t_leng, thickness, spacing = 0.5, center = false)
Surface
surface/sf_bend(levels, radius, thickness, depth, angle = 180, invert = false)
surface/sf_ring(levels, radius, thickness, depth, angle = 360, twist = 0, invert = false)
surface/sf_solidify(surface1, surface2, slicing = "SLASH")
surface/sf_sphere(levels, radius, thickness, depth, angle = [180, 360], invert = false)
surface/sf_square(levels, thickness, depth, x_twist = 0, y_twist = 0, invert = false)
surface/sf_torus(levels, radius, thickness, depth, angle = [360, 360], twist = 0, invert = false)
Noise
noise/nz_cell(points, p, dist = "euclidean")
noise/nz_perlin1(x, seed = undef)
noise/nz_perlin1s(xs, seed = undef)
noise/nz_perlin2(x, y, seed = undef)
noise/nz_perlin2s(points, seed = undef)
noise/nz_perlin3(x, y, z, seed = undef)
noise/nz_perlin3s(points, seed = undef)
noise/nz_worley2(x, y, seed = undef, grid_w = 10, dist = "euclidean")
noise/nz_worley2s(points, seed = undef, grid_w = 10, dist = "euclidean")
noise/nz_worley3(x, y, z, seed = undef, tile_w = 10, dist = "euclidean")
noise/nz_worley3s(points, seed = undef, tile_w = 10, dist = "euclidean")
Voronoi
voronoi/vrn2_cells_from(points)
voronoi/vrn2_cells_space(size, grid_w, seed = undef)
voronoi/vrn2_from(points, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square")
voronoi/vrn2_space(size, grid_w, seed = undef, spacing = 1, r = 0, delta = 0, chamfer = false, region_type = "square")
voronoi/vrn3_from(points, spacing = 1)
voronoi/vrn3_space(size, grid_w, seed = undef, spacing = 1)
Maze
maze/mz_square_cells(rows, columns, start = [0, 0], ...)
maze/mz_square_get(cell, query)
maze/mz_square_walls(cells, rows, columns, cell_width, left_border = true, bottom_border = true)
maze/mz_hex_walls(cells, rows, columns, cell_radius, left_border = true, bottom_border = true)
maze/mz_square_initialize(rows, columns, mask)
maze/mz_hamiltonian(rows, columns, start = [0, 0], seed = undef)
maze/mz_theta_cells(rows, beginning_number, start = [0, 0], seed = undef)
maze/mz_theta_get(cell, query)