From c8a1e14f057aeb93f69564862b5a8f62b7af18d5 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Mon, 6 Sep 2021 19:07:18 -0400 Subject: [PATCH] Expand top text, and reorder some modules for docs --- shapes2d.scad | 276 ++++++++++++++++++++++++++------------------------ 1 file changed, 143 insertions(+), 133 deletions(-) diff --git a/shapes2d.scad b/shapes2d.scad index 724bab9..34133c3 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -1,11 +1,21 @@ ////////////////////////////////////////////////////////////////////// // LibFile: shapes2d.scad -// Common useful 2D shapes. +// This file includes stroke(), which converts a path +// into a geometric object, like drawing with a pen. You +// can make a dashed line or add arrow heads. The turtle() function +// provides a turtle graphics style approach for producing paths. +// You can create regular polygons with optional rounded corners and +// alignment features not available with circle(). The file also +// provides teardrop2d, which is useful for 3d printable holes. +// Lastly you can use the masks to produce edge treatments common in +// furniture from the simple roundover or cove molding to the more +// elaborate ogee. Many of the commands have module forms that +// produce geometry and function forms that produce a path. // Includes: // include ////////////////////////////////////////////////////////////////////// -// Section: 2D Drawing Helpers +// Section: Line Drawing // Module: stroke() // Usage: @@ -1055,8 +1065,7 @@ function oval(r, d, realign=false, circum=false, anchor=CENTER, spin=0) = ) reorient(anchor,spin, two_d=true, r=[rx,ry], p=pts); - -// Section: 2D N-Gons +// Section: Polygons // Function&Module: regular_ngon() // Usage: @@ -1377,10 +1386,6 @@ module octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, align_tip=align_tip, align_side=align_side, anchor=anchor, spin=spin) children(); - -// Section: Other 2D Shapes - - // Function&Module: trapezoid() // Usage: As Module // trapezoid(h, w1, w2, [shift=], [rounding=], [chamfer=], ...); @@ -1486,6 +1491,136 @@ module trapezoid(h, w1, w2, angle, shift=0, chamfer=0, rounding=0, anchor=CENTER } + +// Function&Module: star() +// Usage: As Module +// star(n, r/or, ir, [realign=], [align_tip=], [align_pit=], ...); +// star(n, r/or, step=, ...); +// Usage: With Attachments +// star(n, r/or, ir, ...) { attachments } +// Usage: As Function +// path = star(n, r/or, ir, [realign=], [align_tip=], [align_pit=], ...); +// path = star(n, r/or, step=, ...); +// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable +// See Also: circle(), oval() +// Description: +// When called as a function, returns the path needed to create a star polygon with N points. +// When called as a module, creates a star polygon with N points. +// Arguments: +// n = The number of stellate tips on the star. +// r/or = The radius to the tips of the star. +// ir = The radius to the inner corners of the star. +// --- +// d/od = The diameter to the tips of the star. +// id = The diameter to the inner corners of the star. +// step = Calculates the radius of the inner star corners by virtually drawing a straight line `step` tips around the star. 2 <= step < n/2 +// realign = If false, a tip is aligned with the Y+ axis. If true, an inner corner is aligned with the Y+ axis. Default: false +// align_tip = If given as a 2D vector, rotates the whole shape so that the first star tip points in that direction. This occurs before spin. +// align_pit = If given as a 2D vector, rotates the whole shape so that the first inner corner is pointed towards that direction. This occurs before spin. +// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` +// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` +// Extra Anchors: +// "tip0" ... "tip4" = Each tip has an anchor, pointing outwards. +// "pit0" ... "pit4" = The inside corner between each tip has an anchor, pointing outwards. +// "midpt0" ... "midpt4" = The center-point between each pair of tips has an anchor, pointing outwards. +// Examples(2D): +// star(n=5, r=50, ir=25); +// star(n=5, r=50, step=2); +// star(n=7, r=50, step=2); +// star(n=7, r=50, step=3); +// Example(2D): Realigned +// star(n=7, r=50, step=3, realign=true); +// Example(2D): Alignment by Tip +// star(n=5, ir=15, or=30, align_tip=BACK+RIGHT) +// attach("tip0", FWD) color("blue") +// stroke([[0,0],[0,7]], endcap2="arrow2"); +// Example(2D): Alignment by Pit +// star(n=5, ir=15, or=30, align_pit=BACK+RIGHT) +// attach("pit0", FWD) color("blue") +// stroke([[0,0],[0,7]], endcap2="arrow2"); +// Example(2D): Called as Function +// stroke(closed=true, star(n=5, r=50, ir=25)); +function star(n, r, ir, d, or, od, id, step, realign=false, align_tip, align_pit, anchor=CENTER, spin=0, _mat, _anchs) = + assert(is_undef(align_tip) || is_vector(align_tip)) + assert(is_undef(align_pit) || is_vector(align_pit)) + assert(is_undef(align_tip) || is_undef(align_pit), "Can only specify one of align_tip and align_pit") + let( + r = get_radius(r1=or, d1=od, r=r, d=d), + count = num_defined([ir,id,step]), + stepOK = is_undef(step) || (step>1 && step1 && step