### Module Documentation Example Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Documents a module, including usage, arguments, and an example. The 'Module' header is used, and it's recommended to include Usage, Arguments, and Example sub-blocks. ```openscad // Module: cross() // Usage: // cross(size); // Description: // Creates a 2D cross/plus shape. // Arguments: // size = The scalar size of the cross. // Example(2D): // cross(size=100); module cross(size=1) { square([size, size/3], center=true); square([size/3, size], center=true); } ``` -------------------------------- ### Function Documentation Example Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Documents a function, including usage, arguments, and an example. The 'Function' header is used, and it's recommended to include Usage, Arguments, and Example sub-blocks. ```openscad // Function: vector_angle() // Usage: // ang = vector_angle(v1, v2); // Description: // Calculates the angle between two vectors in degrees. // Arguments: // v1 = The first vector. // v2 = The second vector. // Example: // v1 = [1,1,0]; // v2 = [1,0,0]; // angle = vector_angle(v1, v2); // // Returns: 45 function vector_angle(v1,v2) = acos(max(-1,min(1,(vecs[0]*vecs[1])/(norm0*norm1)))); ``` -------------------------------- ### Example Block with Multiple Shapes Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Demonstrates a multi-line example script for generating shapes. Images are generated by running the script in OpenSCAD. ```openscad // Example: Example description // cylinder(h=100, d1=75, d2=50); // up(100) cylinder(h=100, d1=50, d2=75); ``` ```openscad // Example(Spin,VPD=444): Animated shape that spins to show all faces. // cube([10,100,50], center=true); // cube([100,10,30], center=true); ``` -------------------------------- ### Constant Documentation Example Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Documents a code constant with a description and an example. The 'Constant' header is used for this purpose. ```openscad // Constant: PHI // Description: The golden ratio phi. PHI = (1+sqrt(5))/2; ``` -------------------------------- ### Function and Module Documentation Example Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Documents a function that also has a related module. Includes usage for both function and module calls, description, arguments, and examples for each. ```openscad // Function&Module: oval() // Topics: 2D Shapes, Geometry // Usage: As a Module // oval(rx,ry); // Usage: As a Function // path = oval(rx,ry); // Description: // When called as a function, returns the perimeter path of the oval. // When called as a module, creates a 2D oval shape. // Arguments: // rx = X axis radius. // ry = Y axis radius. // Example(2D): Called as a Function // path = oval(100,60); // polygon(path); // Example(2D): Called as a Module ``` -------------------------------- ### Torus creation examples Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad Demonstrates multiple ways to create a torus using different combinations of major/minor radius/diameter arguments. The last example shows converting the torus to a VNF polyhedron. ```openscad include // These all produce the same torus. torus(r_maj=22.5, r_min=7.5); torus(d_maj=45, d_min=15); torus(or=30, ir=15); torus(od=60, id=30); torus(d_maj=45, id=30); torus(d_maj=45, od=60); torus(d_min=15, id=30); torus(d_min=15, od=60); vnf_polyhedron(torus(d_min=15, od=60), convexity=4); ``` -------------------------------- ### Examples Block with Basic Shapes Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Shows basic geometric shapes using the Examples block, where each line is treated as a separate example. ```openscad cube(100); ``` ```openscad cylinder(h=100,d=50); ``` ```openscad sphere(d=100); ``` -------------------------------- ### Example: VNF Bounds Calculation Source: https://github.com/belfryscad/bosl2/wiki/vnf.scad Demonstrates how to use vnf_bounds() to get the bounding box of a cube VNF. The output shows the min and max coordinates. ```OpenSCAD include echo(vnf_bounds(cube([2,3,4],center=true))); // Displays [[-1, -1.5, -2], [1, 1.5, 2]] ``` -------------------------------- ### Meshing Worm and Gear Example Source: https://github.com/belfryscad/bosl2/wiki/gears.scad Demonstrates how to create and position a worm and a worm gear to show them meshing. The example uses '$fn' for smoothness and rotates the worm to simulate meshing. ```openscad include include $fn=36; circ_pitch = 5; starts = 4; worm_diam = 30; worm_length = 50; gear_teeth=36; right(worm_diam/2) yrot($t*360/starts) worm( d=worm_diam, ``` -------------------------------- ### Move Function Examples: Point, List of Points, and Matrix Source: https://github.com/belfryscad/bosl2/wiki/transforms.scad Provides examples of move() function usage for translating points, lists of points, and generating transformation matrices. ```openscad include pt1 = move([0,20,30], [15,23,42]); // Returns: [15, 43, 72] pt2 = move([0,3,1], [[1,2,3],[4,5,6]]); // Returns: [[1,5,4], [4,8,7]] mat2d = move([2,3]); // Returns: [[1,0,2],[0,1,3],[0,0,1]] mat3d = move([2,3,4]); // Returns: [[1,0,0,2],[0,1,0,3],[0,0,1,4],[0,0,0,1]] ``` -------------------------------- ### Example: oval() Function Usage Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Demonstrates calling the oval() function to get the path and then using polygon() to render the shape. Ensure $fn is set for accurate rendering. ```openscad path = oval(100,60); polygon(path); ``` -------------------------------- ### Install openscad-test Source: https://github.com/belfryscad/bosl2/blob/master/TESTING.md Install the openscad-test framework using pip. This is a prerequisite for running BOSL2 tests. ```bash pip install openscad-test ``` -------------------------------- ### Create a circle segment using width and thickness Source: https://github.com/belfryscad/bosl2/wiki/drawing.scad This example utilizes the `width` and `thickness` parameters to create a circle segment, where the arc starts and ends on the X axis. ```openscad include arc(width=60, thickness=20); ``` -------------------------------- ### Creating a Valid Polyhedron with vnf_join (Example 4) Source: https://github.com/belfryscad/bosl2/wiki/vnf.scad Shows how to create a valid polyhedron by joining multiple consistent VNF pieces. This example meets CGAL requirements for valid polyhedra. ```openscad include bottom = vnf_vertex_array([path3d(rect(8)), path3d(rect(5),4)],col_wrap=true,cap1=true); triangle = yrot(-90,path3d(regular_ngon(n=3,side=5,anchor=LEFT))); top = up(4,vnf_vertex_array([list_set(right(2.5,triangle),0,[0,0,7]), right(6,triangle) ], col_wrap=true, cap2=true)); full = vnf_join([bottom, for(theta=[0:90:359]) zrot(theta,top) ]); vnf_polyhedron(full); ``` -------------------------------- ### OpenSCAD Example with $slop Source: https://github.com/belfryscad/bosl2/wiki/constants.scad This example shows how to use the $slop constant in OpenSCAD to create a difference between two shapes, effectively defining a gap. It also includes text elements to label the '$slop' and 'gap'. ```openscad include $slop = 0.2; difference() { square([20,12],center=true); back(3) square([10+2*$slop,11],center=true); } back(8) { rect([15,5],anchor=FWD); rect([10,8],anchor=BACK); } color("#000") { arrow_path = [[5.1,6.1], [6.0,7.1], [8,7.1], [10.5,10]]; xflip_copy() stroke(arrow_path, width=0.3, endcap1="arrow2"); xcopies(21) back(10.5) { back(1.8) text("$slop", size=1.5, halign="center"); text("gap", size=1.5, halign="center"); } } ``` -------------------------------- ### Extract Substring from String Source: https://github.com/belfryscad/bosl2/wiki/strings.scad Use substr() to get a portion of a string. Specify start position and length, or just the start position to get the rest of the string. A negative length returns an empty string. ```scad include s1=substr("abcdefg",3,3); // Returns "def" s2=substr("abcdefg",2); // Returns "cdefg" s3=substr("abcdefg",len=3); // Returns "abc" s4=substr("abcdefg",[2,4]); // Returns "cde" s5=substr("abcdefg",len=-2); // Returns "" ``` -------------------------------- ### Stroke Path with Tail and Arrow Endcaps Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-Paths Combine different custom endcap styles for the start and end of the path. This example uses 'tail' for the start and 'arrow' for the end. ```openscad include path = [[0,0], [-10,10], [0,20], [10,20], [10,10]]; stroke(path, endcap1="tail", endcap2="arrow"); ``` -------------------------------- ### Create an arc with a specified start angle Source: https://github.com/belfryscad/bosl2/wiki/drawing.scad This example demonstrates creating a wedge arc that starts at a specific angle (45 degrees) and spans a given angle (75 degrees). ```openscad include arc(r=30, start=45, angle=75, wedge=true); ``` -------------------------------- ### Vaccum connector example using skin() Source: https://github.com/belfryscad/bosl2/wiki/skin.scad Demonstrates creating a vacuum connector shape by skinning a series of 2D paths, including rounded corners and circles. Uses slices=0 for a single surface. ```openscad include include $fn=32; base = round_corners(square([2,4],center=true), radius=0.5); skin([ path3d(base,0), path3d(base,2), path3d(circle(r=0.5),3), path3d(circle(r=0.5),4), for(i=[0:2]) each [path3d(circle(r=0.6), i+4), path3d(circle(r=0.5), i+5)] ],slices=0); ``` -------------------------------- ### substr_match() Example Source: https://github.com/belfryscad/bosl2/wiki/strings.scad Checks if a pattern matches a substring within a larger string starting at a specified index. Returns false if the pattern is too long, the start index is out of bounds, or the pattern does not match. ```openscad include a=substr_match("abcde",2,"cd"); // Returns true b=substr_match("abcde",2,"cx"); // Returns false c=substr_match("abcde",2,"cdef"); // Returns false d=substr_match("abcde",-2,"cd"); // Returns false e=substr_match("abcde",19,"cd"); // Returns false f=substr_match("abc",1,""); // Returns true ``` -------------------------------- ### Create a Cube using vnf_polyhedron() Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-VNF Shows how to create the same cube as the previous example but using the VNF structure with `vnf_polyhedron()`. ```openscad include vnf = [ [ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [-1,-1, 1], [1,-1, 1], [1,1, 1], [-1,1, 1], ], [ [0,1,2], [0,2,3], //BOTTOM [0,4,5], [0,5,1], //FRONT [1,5,6], [1,6,2], //RIGHT [2,6,7], [2,7,3], //BACK [3,7,4], [3,4,0], //LEFT [6,4,7], [6,5,4] //TOP ] ]; vnf_polyhedron(vnf); ``` -------------------------------- ### Create an enveloping worm with multiple starts Source: https://github.com/belfryscad/bosl2/wiki/gears.scad This example demonstrates creating an enveloping worm with multiple lead starts, which affects the helix angle. Ensure BOSL2's std.scad and gears.scad libraries are included. ```openscad include include enveloping_worm(circ_pitch=8, mate_teeth=33, d=30, starts=3, $fn=72); ``` -------------------------------- ### Create a Threaded Nut with Custom Bevels and Blunt Start Source: https://github.com/belfryscad/bosl2/wiki/threading.scad Generates a threaded nut with custom internal and external bevels, and blunt start threads. This example showcases fine-grained control over thread lead-in and end treatments. ```openscad include include threaded_nut(nutwidth=16, id=8, h=8, pitch=1.25, bevel1=true, bevel2=true, ibevel1=true, ibevel2=true, blunt_start1=true, blunt_start2=true, $slop=0.1, $fa=1, $fs=1); ``` -------------------------------- ### path_join() Examples Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad Illustrates the behavior of path_join() with different 'closed' and 'k' parameter settings, showing how paths are joined and rounded. ```APIDOC ## path_join() Example 13 ### Description Demonstrates `closed=true` behavior when the last path doesn't meet the first, resulting in curve-based closure. It highlights that the function fails if segments are parallel and requires intersecting extensions for well-defined rounding. ### Parameters - `paths` (list of paths): The input paths to join. - `closed` (boolean, optional): If true, attempts to close the path with a curve. Defaults to false. - `joint` (number, optional): Specifies the type of joint. Defaults to 3. - `$fn` (integer, optional): Number of fragments for curves. Defaults to 25. ### Code Example ```scad include horiz = [[0,0],[10,0]]; vert = [[0,0],[0,10]]; h2 = [[0,-3],[10,0]]; color("red")stroke( path_join([horiz, vert, -h2],closed=true, joint=3,$fn=25), closed=true,width=.5); stroke(path_join([horiz, vert, -h2]),width=.3); ``` ``` ```APIDOC ## path_join() Example 14 ### Description Shows how `closed=true` rounds the start and end junction when applied to a single path. ### Parameters - `paths` (list of paths): The input paths to join. Expects a single path in this example. - `joint` (number, optional): Specifies the type of joint. Defaults to 3. - `closed` (boolean, optional): If true, rounds the start and end junction. Defaults to false. - `$fn` (integer, optional): Number of fragments for curves. Defaults to 12. ### Code Example ```scad include tri = regular_ngon(n=3, r=7); stroke(path_join([tri], joint=3,closed=true,$fn=12), closed=true,width=.5); ``` ``` ```APIDOC ## path_join() Example 15 ### Description Illustrates joining lines that do not intersect when extended, creating a semi-circular joint. Demonstrates the effect of the `k` parameter on curvature smoothness. ### Parameters - `paths` (list of paths): The input paths to join. - `k` (list of numbers, optional): Curvature smoothness parameter. Defaults to 0.5. - `relocate` (boolean, optional): If true, attempts to relocate paths. Defaults to true. ### Code Example ```scad include p=path_join([ [[1,3],[15,8]], [[17,0],[0,0]], [[0,-8],[15,-3]] ], k=[.5,.9], relocate=false); stroke(p); ``` ``` -------------------------------- ### Example with Hidden Lines Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Illustrates how lines starting with '--' are excluded from the documentation output but included in the image generation script. ```openscad // Example: Multi-line example. // --$fn = 72; // Lines starting with -- aren't shown in docs example text. // lst = [ // "multi-line examples", // "are shown in one block", // "with a single image.", // ]; // foo(lst, 23, "blah"); ``` -------------------------------- ### Create a ring region and path with width and thickness Source: https://github.com/belfryscad/bosl2/wiki/shapes2d.scad This example generates both a 'region' (solid ring) and a 'path' (outline of the ring) using width and thickness parameters. The path is then rendered as a dashed stroke. ```openscad include $fn=128; region = ring(width=5,thickness=1.5,ring_width=2); path = ring(width=5,thickness=1.5,ring_width=2,full=false); stroke(region,width=.25); color("red") dashed_stroke(path,dashpat=[1.5,1.5],closed=true,width=.25); ``` -------------------------------- ### prismoid() Example 16: Gradiant Rounding Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad Applies gradient rounding to the prismoid edges, specifying different rounding values for the start and end. ```openscad include prismoid(100, 80, rounding1=10, rounding2=0, h=30); ``` -------------------------------- ### Creating a Connected Pipe Assembly with prism_connector Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad This example shows how to construct a connected pipe assembly by defining the exterior and then subtracting the interior. It highlights the use of corrective shifts to maintain uniform pipe walls. ```openscad include bigpipe_d=15; smallpipe_d=9; wall=1; h=30; fillet=3; sep=30; shift=5; shift_fix=wall/(sep-bigpipe_d)*shift; $fn=128; back_half() difference(){ // Pipe exterior cyl(d=bigpipe_d,h=h,circum=true) let(leftpipe=parent()) right(sep) cyl(d=bigpipe_d,h=h,circum=true) let(rightpipe=parent()) prism_connector(circle(d=smallpipe_d,$fn=48), leftpipe, RIGHT, rightpipe, LEFT, fillet=fillet, shift2=shift); // Interior that will be removed cyl(d=bigpipe_d-2*wall,h=h+1,circum=true) let(leftpipe=parent()) right(sep) cyl(d=bigpipe_d-2*wall,h=h+1,circum=true) let(rightpipe=parent()) prism_connector(circle(d=smallpipe_d-2*wall,$fn=48), leftpipe, RIGHT, rightpipe, LEFT, fillet=fillet, shift1=-shift_fix,shift2=shift+shift_fix); } ``` -------------------------------- ### join_prism() with Cylinder Base Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad Demonstrates the usage of join_prism() with a cylinder as the base shape. This example shows the basic setup for attaching a prism to a cylinder. ```openscad include flower = [for(theta=lerpn(0,360,180,endpoint=false)) (15+1.3*sin(6*theta))*[cos(theta),sin(theta)]]; join_prism(flower,base="cylinder",length=18, fillet=3, n=12); cylinder(h=5,r=25); ``` -------------------------------- ### Slop Calibration Part Example Source: https://github.com/belfryscad/bosl2/wiki/constants.scad This example demonstrates how to generate a calibration part to determine the optimal $slop value for your 3D printer. Adjust the 'holesize' and 'gap' variables to test different tolerances. The comments within the code suggest modifications for testing cylinders instead of cubes. ```openscad include min_slop = 0.00; slop_step = 0.05; holes = 6; holesize = [10,10,10]; gap = 5; ``` -------------------------------- ### Path Join with Single Path and Closed=true (Example 14) Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad Shows how `closed=true` rounds the start and end junction when a single path is provided to `path_join`. ```OpenSCAD include tri = regular_ngon(n=3, r=7); stroke(path_join([tri], joint=3,closed=true,$fn=12), closed=true,width=.5); ``` -------------------------------- ### Using worm_gear() as a Function Source: https://github.com/belfryscad/bosl2/wiki/gears.scad This example shows how to call worm_gear() as a function to get its geometry, which can then be used for further operations like creating a polyhedron. The output of worm_gear() is a 2D profile that can be extruded or used in other ways. ```openscad include include vnf = worm_gear(circ_pitch=8, teeth=30, worm_diam=30, worm_starts=1); vnf_polyhedron(vnf); ``` -------------------------------- ### Create a Standard Rack Source: https://github.com/belfryscad/bosl2/wiki/gears.scad Generates a standard rack using pitch, teeth, and thickness parameters. The backing parameter controls the rack's thickness. ```OpenSCAD include include rack(pitch=5, teeth=10, thickness=5, backing=5, helical=30); ``` -------------------------------- ### Call enveloping_worm() as a function and use vnf_polyhedron() Source: https://github.com/belfryscad/bosl2/wiki/gears.scad This example shows how to call enveloping_worm() as a function to get a VNF (Vectorized Numerical Format) and then render it using vnf_polyhedron(). Ensure BOSL2's std.scad and gears.scad libraries are included. ```openscad include include vnf = enveloping_worm(circ_pitch=8, mate_teeth=37, d=35, starts=2, left_handed=true, pressure_angle=20, $fn=72); vnf_polyhedron(vnf); ``` -------------------------------- ### Create a sphere with custom orientation Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad This example demonstrates creating a sphere, setting its anchor and spin, and then orienting its 'top' towards a specified direction. Ensure BOSL2 std library is included. ```openscad include sphere(d=100, anchor=FRONT, spin=45, orient=FWD); ``` -------------------------------- ### mask2d_smooth() Example 2: Mask defined by joint length Source: https://github.com/belfryscad/bosl2/wiki/masks.scad Creates a 2D mask shape defined by the 'joint' parameter, specifying the distance from the edge where the roundover starts. A larger 'excess' value is used to better visualize the mask's extent. Ensure BOSL2 std library is included. ```openscad include mask2d_smooth(joint=10,excess=0.5); ``` -------------------------------- ### OpenSCAD Usage Block Example Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Illustrates a Usage block for documenting typical ways to use a function or module, including different parameter forms. ```openscad // Usage: Typical Usage // x = foo(a, b, c); // x = foo([a, b, c, ...]); ``` -------------------------------- ### Create Arc Path with Starting Angle Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-Paths Creates an arc path starting at a specified angle using the 'start' argument. Include BOSL2's std.scad. ```openscad include path = arc(start=45, r=30, angle=120); stroke(path, endcap2="arrow2"); ``` -------------------------------- ### Create a threaded rod with detailed specifications Source: https://github.com/belfryscad/bosl2/wiki/threading.scad Demonstrates creating a threaded rod using detailed specifications for diameter, length, and pitch. This example highlights the flexibility in defining thread parameters. ```openscad include include threaded_rod(d=[10, 1.5, 12], length=20, pitch=1.5); ``` -------------------------------- ### Create a sphere with custom anchoring Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad This example demonstrates creating a sphere and positioning its anchor point to the front. Ensure BOSL2 std library is included. ```openscad include sphere(d=100, anchor=FRONT); ``` -------------------------------- ### Create Meshing Crown and Spur Gears Source: https://github.com/belfryscad/bosl2/wiki/gears.scad This example demonstrates how to create a crown gear and a spur gear that mesh together. It calculates pitch radii and sets appropriate orientations and positions for meshing. Ensure BOSL2 libraries are included. ```openscad include include mod=1; cteeth=40; ppr=17; backing=3; PA=20; face=5; cpr = pitch_radius(mod=mod, teeth=cteeth); ppr = pitch_radius(mod=mod, teeth=pteeth); crown_gear(mod=mod, teeth=cteeth, backing=backing, face_width=face, pressure_angle=PA); back(cpr+face/2) up(ppr) spur_gear(mod=mod, teeth=pteeth, pressure_angle=PA, thickness=face, orient=BACK, gear_spin=180/pteeth, ``` -------------------------------- ### snap_pin_socket() - Integrated into a Cube Source: https://github.com/belfryscad/bosl2/wiki/joiners.scad Demonstrates integrating snap_pin_socket() into a larger object, such as a cube. This example shows how to difference the socket from a solid and position multiple sockets. ```openscad include include $fn=40; diff("socket") cuboid([20,20,20]) tag("socket"){ attach(TOP) snap_pin_socket("standard"); position(TOP+FRONT)snap_pin_socket("standard"); } ``` -------------------------------- ### Create 5 copies spaced 20 units apart along the Y axis starting at [0,0,0] Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-Distributors Use the `sp=` argument with `ycopies()` to specify a starting point. For `ycopies()`, the line extends to the back of the starting point. ```openscad include ycopies(20, n=5, sp=[0,0,0]) sphere(d=10); ``` -------------------------------- ### join_prism() with Scaling Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad Demonstrates how to scale the prism using the scale parameter. ```openscad include flower = [for(theta=lerpn(0,360,180,endpoint=false)) (15+1.3*sin(6*theta))*[cos(theta),sin(theta)]]; join_prism(flower,base="cylinder",base_r=30, length=18, fillet=4, n=12,scale=.5); xcyl(r=30,l=75,circum=true,$fn=64); ``` -------------------------------- ### Create 5 copies spaced 20 units apart along the Z axis starting at [0,0,0] Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-Distributors Use the `sp=` argument with `zcopies()` to specify a starting point. For `zcopies()`, the line extends upwards from the starting point. ```openscad include zcopies(20, n=5, sp=[0,0,0]) sphere(d=10); ``` -------------------------------- ### Create a sphere with custom anchoring and spin Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad This example shows how to create a sphere, set its anchor point to the front, and then rotate it around the Z-axis. Ensure BOSL2 std library is included. ```openscad include sphere(d=100, anchor=FRONT, spin=45); ``` -------------------------------- ### Create 5 copies spaced 20 units apart along the X axis starting at [0,0,0] Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-Distributors Use the `sp=` argument with `xcopies()` to specify a starting point. For `xcopies()`, the line extends to the right of the starting point. ```openscad include xcopies(20, n=5, sp=[0,0,0]) sphere(d=10); ``` -------------------------------- ### Create a Cube using polyhedron() Source: https://github.com/belfryscad/bosl2/wiki/Tutorial-VNF Demonstrates the basic usage of the `polyhedron()` module with explicit vertex and face lists to create a cube. ```openscad include verts = [ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [-1,-1, 1], [1,-1, 1], [1,1, 1], [-1,1, 1] ]; faces = [ [0,1,2], [0,2,3], //BOTTOM [0,4,5], [0,5,1], //FRONT [1,5,6], [1,6,2], //RIGHT [2,6,7], [2,7,3], //BACK [3,7,4], [3,4,0], //LEFT [6,4,7], [6,5,4] //TOP ]; polyhedron(verts, faces); ``` -------------------------------- ### path_join() Example 1: Joining simple paths Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad Connects three simple paths end-to-end. This is a basic usage without explicit rounding parameters. ```OpenSCAD include horiz = [[0,0],[10,0]]; vert = [[0,0],[0,10]]; stroke(path_join([horiz, vert, -horiz])); ``` -------------------------------- ### grid_copies() Function Usage (Getting Matrices) Source: https://github.com/belfryscad/bosl2/wiki/distributors.scad Demonstrates how to use grid_copies() as a function to get a list of transformation matrices. ```APIDOC ## grid_copies() Function (Getting Matrices) ### Description When called as a function, *without* a `p=` argument, returns a list of transformation matrices, one for each copy. ### Synopsis - mats = grid_copies(spacing, size=, [stagger=], [scale=], [inside=], [axes=]); - mats = grid_copies(n=, size=, [stagger=], [scale=], [inside=], [axes=]); - mats = grid_copies(spacing, [n], [stagger=], [scale=], [inside=], [axes=]); - mats = grid_copies(n=, inside=, [stagger], [scale], [axes=]); ### Arguments (See Arguments section for module usage. The `p=` argument should not be provided for this usage.) ### Example (Example not provided in source, but would show the retrieval of transformation matrices.) ``` -------------------------------- ### Create a partial ring using points, control points, and ring_width Source: https://github.com/belfryscad/bosl2/wiki/shapes2d.scad This example demonstrates creating a partial ring (full=false) using a combination of points, control points (cp), and ring_width. ```openscad include ring(32,-2, cp=[1,1], points=[[4,4],[-3,6]], full=false); ``` -------------------------------- ### ycyl() Example: By Diameter Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad Creates a cylinder oriented along the Y axis using diameter. Shows examples with uniform and tapered diameters. ```openscad include xdistribute(50) { ycyl(l=35, d=20); ycyl(l=35, d1=30, d2=10); } ``` -------------------------------- ### Display anchors for a centered wedge Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad This example demonstrates how to visualize the standard anchors of a wedge when `center=true`. The `show_anchors()` function helps in understanding the positioning points. ```openscad include wedge([40, 80, 30], center=true) show_anchors(custom=false); color([0.5,0.5,0.5,0.1]) cube([40, 80, 30], center=true); ``` -------------------------------- ### zcyl() Example: By Diameter Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad Creates a cylinder oriented along the Z axis using diameter. Shows examples with uniform and tapered diameters. ```openscad include xdistribute(50) { zcyl(l=35, d=20); zcyl(l=35, d1=30, d2=10); } ``` -------------------------------- ### starts_with() Example Source: https://github.com/belfryscad/bosl2/wiki/strings.scad Determines if a string begins with a specified pattern. Handles empty patterns correctly by returning true. Returns false if the string is not a string or list. ```openscad include b1=starts_with("abcdef","abc"); // Returns true b2=starts_with("abcdef","def"); // Returns false b3=starts_with("abcdef",""); // Returns true ``` -------------------------------- ### substr() Source: https://github.com/belfryscad/bosl2/wiki/strings.scad Returns a substring from a string, starting at a specified position and with a specified length. If length is omitted, it returns the rest of the string from the starting position. ```APIDOC ## substr() ### Description Returns a substring from a string, starting at a specified position and with a specified length. If length is omitted, it returns the rest of the string from the starting position. ### Synopsis `newstr = substr(str, [pos], [len]);` ### Parameters #### Positional Parameters - `str` (string) - The string to operate on. - `pos` (integer or vector) - The starting index of the substring. Defaults to 0. Can also be a vector of [first, last] positions. - `len` (integer) - The length of the substring. If omitted, the rest of the string is returned. If zero or less, an empty string is returned. ### Examples ``` include s1=substr("abcdefg",3,3); // Returns "def" s2=substr("abcdefg",2); // Returns "cdefg" s3=substr("abcdefg",len=3); // Returns "abc" s4=substr("abcdefg",[2,4]); // Returns "cde" s5=substr("abcdefg",len=-2); // Returns "" ``` ``` -------------------------------- ### join_prism() with basic attachments Source: https://github.com/belfryscad/bosl2/wiki/rounding.scad This example demonstrates the basic usage of join_prism() to create a prism with a flower-shaped profile, attached to a base and an end object, with transformations applied. The linear_sweep function is used to create a secondary object for visualization. ```openscad include flower = [for(theta=lerpn(0,360,180,endpoint=false)) (15+1.3*sin(6*theta))*[cos(theta),sin(theta)]]; join_prism(flower,base=1.4*flower, length=20, prism_end_T=yrot(20),aux_T=xrot(10), fillet=3, n=25); linear_sweep(1.4*flower,height=60,center=true, convexity=10,orient=RIGHT); ``` -------------------------------- ### Create a flat partition path Source: https://github.com/belfryscad/bosl2/wiki/partitions.scad Generates a basic flat partition path. Ensure BOSL2 std library is included. ```openscad include stroke(partition_path(["flat"]), width=3); ``` -------------------------------- ### Start Cubic Bezier Segment Source: https://github.com/belfryscad/bosl2/wiki/CheatSheet Constructs the control points for the start of a cubic Bezier segment. Can use absolute points or vectors for direction and radius. ```openscad pts = [bez_begin](beziers.scad#function-bez_begin)(pt, a, r, [p=]); ``` ```openscad pts = [bez_begin](beziers.scad#function-bez_begin)(pt, VECTOR, [r], [p=]); ``` -------------------------------- ### Create a basic arc segment Source: https://github.com/belfryscad/bosl2/wiki/drawing.scad This example demonstrates creating a basic arc segment using radius and angle. The `wedge=true` parameter creates a pie slice shape. ```openscad include arc(r=30, angle=30, wedge=true); ``` -------------------------------- ### Create Trapezoidal Threaded Nut (Blunt Start) Source: https://github.com/belfryscad/bosl2/wiki/threading.scad Generates a trapezoidal threaded nut with a blunt start to the threads. Set `blunt_start=false` to disable this feature. ```openscad include include trapezoidal_threaded_nut(nutwidth=17.4, id=10, h=10, pitch=2, starts=3, $fa=1, $fs=1, $slop=0.15, blunt_start=false); ``` -------------------------------- ### Threaded rod with blunt start disabled Source: https://github.com/belfryscad/bosl2/wiki/threading.scad Generates a threaded rod where the blunt start feature is explicitly disabled. Requires including std.scad and threading.scad. ```openscad include include threaded_rod(d=25, l=20, pitch=2, $fa=1, $fs=1, blunt_start=false); ``` -------------------------------- ### Create a Worm Gear with Multiple Starts Source: https://github.com/belfryscad/bosl2/wiki/gears.scad Generates a worm gear designed to mesh with a worm having multiple starts. Adjust the 'worm_starts' parameter accordingly. ```openscad include include worm_gear(circ_pitch=5, teeth=36, worm_diam=30, worm_starts=4); ``` -------------------------------- ### prismoid() Example 10: Specifying top, height and angle Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad Demonstrates specifying the top dimensions, height, and asymmetric X/Y angles. ```openscad include prismoid(size2=[100,75], h=30, xang=[50,60], yang=[70,40]); ``` -------------------------------- ### line_copies() with start and end points Source: https://github.com/belfryscad/bosl2/wiki/distributors.scad Distributes copies between two specified points (p1 and p2). Use when the exact start and end locations are critical. ```OpenSCAD include line_copies(p1=[0,0,0], p2=[5,5,20], n=6) cuboid([3,2,1]); ``` -------------------------------- ### Install BOSL2 on Fedora Source: https://github.com/belfryscad/bosl2/blob/master/README.md Use this command to install the BOSL2 library on Fedora Linux. Note that the repository version might be older than the latest release. ```bash sudo dnf install openscad-bosl2 ``` -------------------------------- ### Demonstrate All UTS Screw Head Types (Fast Preview) Source: https://github.com/belfryscad/bosl2/wiki/screws.scad Provides a comprehensive demonstration of all available head types for UTS screws. Uses `thread=0` for a faster preview, making it ideal for quickly visualizing head geometry. Anchored to the top for consistent placement. ```openscad include include xdistribute(spacing=15){ ydistribute(spacing=15){ screw("1/4", thread=0,length=8, anchor=TOP, head="none", drive="hex"); screw("1/4", thread=0,length=8, anchor=TOP, head="none", drive="torx"); screw("1/4", thread=0,length=8, anchor=TOP, head="none", drive="slot"); screw("1/4", thread=0,length=8, anchor=TOP, head="none"); } screw("1/4", thread=0, length=8, anchor=TOP, head="hex"); ydistribute(spacing=15){ screw("1/4", thread=0,length=8, anchor=TOP, head="socket", drive="hex"); screw("1/4", thread=0,length=8, anchor=TOP, head="socket", drive="torx"); screw("1/4", thread=0,length=8, anchor=TOP, head="socket"); } ydistribute(spacing=15){ screw("1/4", thread=0,length=8, anchor=TOP, head="socket ribbed", drive="hex",$fn=32); screw("1/4", thread=0,length=8, anchor=TOP, head="socket ribbed", drive="torx",$fn=32); screw("1/4", thread=0,length=8, anchor=TOP, head="socket ribbed",$fn=24); } ydistribute(spacing=15){ screw("1/4", thread=0,length=8, anchor=TOP, head="button", drive="hex"); screw("1/4", thread=0,length=8, anchor=TOP, head="button", drive="torx"); screw("1/4", thread=0,length=8, anchor=TOP, head="button"); } ydistribute(spacing=15){ screw("1/4", thread=0,length=8, anchor=TOP, head="round", drive="slot"); screw("1/4", thread=0,length=8, anchor=TOP, head="round", drive="phillips"); screw("1/4", thread=0,length=8, anchor=TOP, head="round"); } ydistribute(spacing=15){ screw("1/4", thread=0,length=8, anchor=TOP, head="pan", drive="slot"); screw("1/4", thread=0,length=8, anchor=TOP, head="pan", drive="phillips"); screw("1/4", thread=0,length=8, anchor=TOP, head="pan"); } ydistribute(spacing=15){ ``` -------------------------------- ### prismoid() Example 7: Right Prism Source: https://github.com/belfryscad/bosl2/wiki/shapes3d.scad Demonstrates creating a right prism by setting the top size to zero. ```openscad include prismoid(size1=[30,60], size2=[0,60], shift=[-15,0], h=30); ``` -------------------------------- ### Example: Gear Shortening Restores Clearance Source: https://github.com/belfryscad/bosl2/wiki/gears.scad This example demonstrates how applying the `gear_shorten` factor restores the normal tooth clearance between two profile-shifted spur gears. ```openscad include include teeth1=25; teeth2=19; mod=4; ps1 = 0.75; ps2 = 0.75; d = gear_dist(mod=mod, teeth1,teeth2,0,ps1,ps2); shorten=gear_shorten(teeth1,teeth2,0,ps1,ps2); color("lightblue") spur_gear2d(mod=mod,teeth=teeth1,profile_shift=ps1,shorten=shorten,gear_spin=-90); right(d) spur_gear2d(mod=mod,teeth=teeth2,profile_shift=ps2,shorten=shorten,gear_spin=-90); ``` -------------------------------- ### Create a ring segment with specified start and end angles Source: https://github.com/belfryscad/bosl2/wiki/shapes2d.scad Use the angle parameter to define a segment of a ring by specifying start and end angles in degrees. ```openscad include ring(r1=5,r2=7, angle=[33,110], n=32); ``` -------------------------------- ### OpenSCAD Description Block Example Source: https://github.com/belfryscad/bosl2/blob/master/WRITING_DOCS.md Shows a multi-line Description block for providing detailed explanations of code functionality. ```openscad // Description: // This is a description. // It can be multiple lines in length. ``` -------------------------------- ### rot_copies() with translation and start angle Source: https://github.com/belfryscad/bosl2/wiki/distributors.scad Illustrates creating 6 rotated copies with a translation and a starting angle (sa=45). Use this to control the initial orientation of the copies. ```OpenSCAD include rot_copies(n=6, v=UP+FWD, delta=[10,0,0], sa=45) yrot(90) cylinder(h=20, r1=5, r2=0); color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0); ```