Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Reduce the burden of mathematics when playing OpenSCAD

License

NotificationsYou must be signed in to change notification settings

JustinSDK/dotSCAD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reduce the burden of mathematics/algorithm when playing OpenSCAD.

dotSCAD

Introduction

Some of my3D 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. CheckSetting OPENSCADPATH inOpenSCAD User Manual/Libraries for details.

I setOPENSCADPATH to thesrc folder of dotSCAD so all examples here start searching modules/functions fromsrc.

Every public module/function has the same name as the .scad file. Here's an example using theline2d 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 invoxel directory. Prefix the directory name when usingvx_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. Seeexamples.

examples

API Reference

2D Module

SignatureDescription
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

SignatureDescription
crystal_ball(radius[, theta, phi, thickness])create a crystal ball based onspherical 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 usinghull 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

SignatureDescription
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

SignatureDescription
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 applyingmarching 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

SignatureDescription
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

SignatureDescription
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 usingde Boor's algorithm.
curve(t_step, points[, tightness])create a curved path. An implementation ofCentripetal 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 ofThe (p,q)-torus knot.

Extrusion

SignatureDescription
bend_extrude(size, thickness, angle[, frags])extrude and bend a 2D shape.
box_extrude(height, shell_thickness, bottom_thickness[, offset_mode, chamfer, ...])create a box (container) from a 2D object.
ellipse_extrude(semi_minor_axis, height[, center, convexity, twist, slices])extrude a 2D object along the path of an ellipse from 0 to 180 degrees.
rounded_extrude(size, round_r[, angle, twist, convexity])extrude a 2D object roundly from 0 to 180 degrees.
stereographic_extrude(shadow_side_leng)take a 2D polygon as input and extend it onto a sphere.

2D Shape

SignatureDescription
shape_arc(radius, angle, width[, width_mode])return points on the path of an arc shape.
shape_circle(radius, n)return points on the path of a circle.
shape_cyclicpolygon(sides, circle_r, corner_r)return points on the path of a regular cyclic polygon.
shape_ellipse(axes)return points on the path of an ellipse.
shape_liquid_splitting(radius, centre_dist[, tangent_angle, t_step])return shape points of two splitting liquid shapes, kind of how cells divide.
shape_path_extend(stroke_pts, path_pts[, scale, closed])extend a 2D stroke along a path to create a 2D shape.
shape_pentagram(r)return shape points of a pentagram.
shape_pie(radius, angle)return shape points of a pie (circular sector) shape.
shape_square(size[, corner_r])return shape points of a rounded square or rectangle.
shape_star([outer_radius, inner_radius, n])create a 2D star.
shape_superformula(phi_step, m1, m2, n1, [n2, n3, a, b])return shape points ofSuperformula.
shape_taiwan(h[, distance])return shape points ofTaiwan.
shape_trapezium(length, h[, corner_r])return shape points of an isosceles trapezoid.

2D Shape Extrusion

SignatureDescription
archimedean_spiral_extrude(shape_pts, arm_distance, init_angle, point_distance, num_of_points, ...)extrude a 2D shape along the path of an archimedean spiral.
golden_spiral_extrude(shape_pts, from, to, point_distance, ...)extrude a 2D shape along the path of a golden spiral.
helix_extrude(shape_pts, radius, levels, level_dist, ...)extrude a 2D shape along a helix path.
path_extrude(shape_pts, path_pts, ...)extrude a 2D shape along a path.
ring_extrude(shape_pts, radius[, angle = 360])rotational extrusion spins a 2D shape around the Z-axis.
sphere_spiral_extrude(shape_pts, radius, za_step, ...)extrude a 2D shape along the path of a sphere spiral.

Util

util/list

SignatureDescription
util/binary_search(sorted, target[, lo, hi])search a value in a sorted list.
util/contains(lt, elem)returntrue iflt containselem.
util/find_index(lt, test)return the index of the first element that satisfies the testing function.
util/dedup(lt, ...)eliminate duplicate vectors.
util/flat(lt[, depth])return a new list with all sub-list elements concatenated into it recursively up to the specified depth.
util/reverse(lt)reverse a list.
util/slice(lt, begin, end)return a list selected frombegin toend, or to theend of the list (end not included).
util/sorted(lt[, cmp, key, reverse])sort a list.
util/sum(lt)use+ to sum up all elements in a list.
util/swap(lt, i, j)swap two elements in a list.
util/zip(lts, combine)make a list that aggregates elements from each of the lists.
util/every(lt, test)test whether all elements in the list pass the test implemented by the provided function.
util/some(lt, test)test whether at least one element in the list passes the test implemented by the provided function.
util/count(lt, test)return the number of timestest returntrue in the list.

util/random

SignatureDescription
util/choose(choices, seed)choose an element from the given list.
util/rand([min_value, max_value, seed_value])generate a pseudo random number.
util/shuffle(lt[, seed])randomizes the order of the elements.

util/string

SignatureDescription
util/parse_number(t)parse the string argument as an number.
util/split_str(t, delimiter)split the given string around matches of the given delimiting character.
util/sub_str(t, begin, end)return the part of the string frombegin toend, or to theend of the string (end not included).

util/math

SignatureDescription
util/degrees(radians)convert a radian measurement to the corresponding value in degrees.
util/radians(degrees)convert a degree measurement to the corresponding value in radians.
util/polar_coordinate(point)convert from Cartesian to Polar coordinates.
util/spherical_coordinate(point)convert from Cartesian to Spherical coordinates (used in mathematics).
util/lerp(v1, v2, amt)linear interpolate the vector v1 to v2.
util/fibseq(from, to)generate a Fibonacci sequence.

util/set

SignatureDescription
util/set/hashset(lt, ...)model the mathematical set, backed by a hash table.
util/set/hashset_add(set, elem, ...)add an element to ahashset.
util/set/hashset_has(set, elem, ...)returntrue if ahashset contains the specified element.
util/set/hashset_del(set, elem, ...)del an element from ahashset.
util/set/hashset_len(set)return the length of the elements in ahashset.
util/set/hashset_elems(set)returns a list containing all elements in ahashset. No guarantees to the order.

util/map

SignatureDescription
util/map/hashmap(kv_lt, ...)map keys to values.
util/map/hashmap_put(map, key, value, ...)put a key/value pair to ahashmap.
util/map/hashmap_get(map, key, ...)get the value of the specified key from ahashmap.
util/map/hashmap_del(map, key, ...)delete the mapping for the specified key from ahashmap if present.
util/map/hashmap_len(map)return the length of ahashmap.
util/map/hashmap_keys(map)return a list containing all keys in ahashmap.
util/map/hashmap_values(map)return a list containing all values in ahashmap.
util/map/hashmap_entries(map)return a list containing all[key, value]s in ahashmap.

Matrix

SignatureDescription
matrix/m_determinant(m)calculate a determinant of a square matrix.
matrix/m_mirror(v)generate a transformation matrix which can pass intomultmatrix to mirror the child element on a plane through the origin.
matrix/m_rotation(a, v)Generate a transformation matrix which can pass intomultmatrix to rotate the child element about the axis of the coordinate system or around an arbitrary axis.
matrix/m_scaling(s)generate a transformation matrix which can pass intomultmatrix to scale its child elements using the specified vector.
matrix/m_shearing([sx, sy, sz])generate a transformation matrix which can pass intomultmatrix to shear all child elements along the X-axis, Y-axis, or Z-axis in 3D.
matrix/m_translation(v)generate a transformation matrix which can pass into multmatrix to translates (moves) its child elements along the specified vector.
maxtrix/m_transpose(m)transpose a matrix.
matrix/m_replace(m, i, j, value)replace the aᵢⱼ element of a matrix.

Point Transformation

SignatureDescription
ptf/ptf_bend(size, point, radius, angle)transform a point inside a rectangle to a point of an arc.
ptf/ptf_circle(size, point)transform a point inside a rectangle to a point inside a circle.
ptf/ptf_ring(size, point, radius[, angle, twist])transform a point inside a rectangle to a point of a ring.
ptf/ptf_rotate(point, a, v)rotate a point a degrees around the axis of the coordinate system or an arbitrary axis.
ptf/ptf_sphere(size, point, radius[, angle])transform a point inside a rectangle to a point of a sphere.
ptf/ptf_torus(size, point, radius[, angle, twist])transform a point inside a rectangle to a point of a torus.
ptf/ptf_x_twist(size, point, angle)twist a point along the x-axis.
ptf/ptf_y_twist(size, point, angle)twist a point along the y-axis.

Triangle

SignatureDescription
triangle/tri_circumcenter(shape_pts)return the circumcenter of a triangle.
triangle/tri_incenter(shape_pts)return the incenter of a triangle.
triangle/tri_ear_clipping(shape_pts[, ret, ...])triangulation byear clipping.
triangle/tri_delaunay(points[, ret])Join a set of points to make aDelaunay triangulation.
triangle/tri_delaunay_indices(d)return triangle indices from a delaunay object.
triangle/tri_delaunay_shapes(d)return triangle shapes from a delaunay object.
triangle/tri_delaunay_voronoi(d)returnVoronoi cells from a delaunay object.
triangle/tri_subdivide(shape_pts[, n])subdivide a trianglen times.

Turtle

SignatureDescription
turtle/footprints2(cmds[, start])drive a turtle with["forward", length] or["turn", angle]. This function is intended to use a turtle to imitate freehand drawing.
turtle/footprints3(cmds[, start])a 3D verion offootprint2.
turtle/lsystem2(axiom, rules, n, angle[, leng, heading, ...])2D implementation ofL-system.
turtle/lsystem3(axiom, rules, n, angle[, leng, heading, ...])3D implementation ofL-system.
turtle/t2d(t, cmd, point, angle, leng)an implementation of Turtle Graphics.
turtle/t3d(t, cmd, point, unit_vectors, leng, angle)a 3D version oft2d.

Voxel

SignatureDescription
voxel/vx_ascii(char[, center, invert])generate 8x8 voxel points of printable ASCII characters (codes 32dec to 126dec).
voxel/vx_bezier(p1, p2, p3, p4)return voxel-by-voxel points of Bézier Curve.
voxel/vx_circle(radius[, filled])return points that can be used to draw a voxel-style circle.
voxel/vx_contour(points[, sorted])return the contour which encircles the area.
voxel/vx_curve(points[, tightness])the curve is drawn only from the 2nd control point to the second-last control point.
voxel/vx_cylinder(r, h[, filled, thickness])return points that can be used to draw a voxel-style cylinder.
voxel/vx_difference(points1, points2)create a difference of two lists of points.
voxel/vx_from(binaries[, center, invert])given a list of 0s and 1s that represent a black-and-white image. This function translates them into voxel points.
voxel/vx_gray(levels[, center, invert, normalize])given a list of numbers (0 ~ 255) that represent a gray image. This function translates them into a list of[x, y, level]s.
voxel/vx_intersection(points1, points2)create an intersection of two lists of points.
voxel/vx_line(p1, p2)given two points. it returns points that can be used to draw a voxel-style line.
voxel/vx_polygon(points[, filled])return points that can be used to draw a voxel-style polygon.
voxel/vx_polyline(points)return points that can be used to draw a voxel-style polyline.
voxel/vx_sphere(radius[, filled, thickness])return points that can be used to draw a voxel-style sphere.
voxel/vx_union(points1, points2)create a union of two lists of points.

Part

SignatureDescription
part/cone(radius[, length, spacing, angle, void, ends])create a cone for rotatable models.
part/connector_peg(radius, height[, spacing, void, ends])create a connector peg.
part/joint_T(shaft_r, shaft_h, t_leng, thickness,[ spacing, center])create a joint_T for rotatable models.

Surface

SignatureDescription
surface/sf_bend(levels, radius, thickness, depth[, angle, invert])bend a photo.
surface/sf_ring(levels, radius, thickness, depth[, angle, twist, invert])turn a photo into a ring.
surface/sf_solidify(surface1, surface2[, slicing])solidify two square surfaces.
surface/sf_sphere(levels, radius, thickness, depth[, angle, invert)]map a photo onto a sphere.
surface/sf_square(levels, thickness, depth[, x_twist, y_twist, invert])turn a photo into a twistable square.
surface/sf_torus(levels, radius, thickness, depth[, angle, twist, invert])turn a photo to a torus.
surface/sf_curve(levels, curve_path, ...)curve a photo.
surface/sf_splines(ctrl_pts, row_spline, column_spline)generalized-spline surface.
surface/sf_thicken(points, thickness, ...)thicken a surface.
surface/sf_solidifyT(points1, points2, triangles)solidify two surfaces with triangular mesh.
surface/sf_thickenT(points, thickness, ...)thicken a surface with triangular mesh.

Noise

SignatureDescription
noise/nz_cell(points, p[, dist])an implementation ofWorley noise.
noise/nz_perlin1(x[, seed])return the 1DPerlin noise value at the x coordinate.
noise/nz_perlin1s(xs[, seed])return 1DPerlin noise values at x coordinates.
noise/nz_perlin2(x, y[, seed])return the 2DPerlin noise value at the (x, y) coordinate.
noise/nz_perlin2s(points[, seed])return 2DPerlin noise values at (x, y) coordinates.
noise/nz_perlin3(x, y, z[, seed])return the 3DPerlin noise value at the (x, y, z) coordinate.
noise/nz_perlin3s(points[, seed])return 3DPerlin noise values at (x, y, z) coordinates.
noise/nz_worley2(x, y[, seed, grid_w, dist])return the 2DWorley noise value at the (x, y) coordinate.
noise/nz_worley2s(points[, seed, grid_w, dist])return 2DWorley noise values at (x, y) coordinates.
noise/nz_worley3(x, y, z[, seed, grid_w, dist])return the 3DWorley noise value at the (x, y, z) coordinate.
noise/nz_worley3s(points[, seed, grid_w, dist])return 3DWorley noise values at (x, y, z) coordinates.

Voronoi

SignatureDescription
voronoi/vrn2_cells_from(points)create cell shapes ofVoronoi from a list of points.
voronoi/vrn2_cells_space(size, grid_w[, seed])create cell shapes ofVoronoi in the first quadrant.
voronoi/vrn2_from(points[, spacing, ...])create aVoronoi from a list of points.
voronoi/vrn2_space(size, grid_w[, seed, spacing, ...])create aVoronoi in the first quadrant.
voronoi/vrn3_from(points[, spacing])create a 3D version ofVoronoi.
voronoi/vrn3_space(size, grid_w[, seed, spacing])create aVoronoi in the first octant.

Maze

SignatureDescription
maze/mz_square([rows, columns, start, init_cells, x_wrapping, y_wrapping, seed])return cell data of a square maze.
maze/mz_square_get(cell, query)a helper for getting data from a square-maze cell.
maze/mz_squarewalls(cells, cell_width[, left_border, bottom_border])a helper for creating square wall data from maze cells.
maze/mz_hexwalls(cells, cell_radius[, left_border, bottom_border])a helper for creating hex wall data from maze cells.
maze/mz_square_initialize(rows, columns, mask)a helper for initializing cell data of a maze.
maze/mz_hamiltonian(rows, columns[, start, seed])create a hamiltonian path from a maze.
maze/mz_theta_cells(rows, beginning_number[, start, seed])return cell data of a theta maze.
maze/mz_theta(rings, beginning_number[, start, seed])return cell data of a theta maze.
maze/mz_tiles(cells[, left_border, bottom_border])turn maze cells into tiles.

Polyhedra

SignatureDescription
polyhedra/star([outerRadius, innerRadius, height, n])create a 3D star.
polyhedra/polar_zonohedra(n[, theta])create apolar zonohedra.
polyhedra/tetrahedron(radius[, detail])create a tetrahedron.
polyhedra/hexahedron(radius[, detail])create a hexahedron.
polyhedra/octahedron(radius[, detail])create a octahedron.
polyhedra/dodecahedron(radius[, detail])create a dodecahedron.
polyhedra/icosahedron(radius[, detail])create a icosahedron.
polyhedra/superellipsoid(radius[, detail])create a superellipsoid.

Point Picking

SignatureDescription
pp/pp_disk(radius, value_count[, seed])generate random points over a disk.
pp/pp_sphere(radius, value_count[, seed])pick random points on the surface of a sphere.
pp/pp_poisson2(size, r[, start, k, seed])perform poisson sampling over a rectangle area.
pp/pp_poisson3(size, r[, start, k, seed])perform poisson sampling over a cube space.


[8]ページ先頭

©2009-2025 Movatter.jp