1//////////////////////////////////////////////////////////////////////
  2// LibFile: sliders.scad
  3//   Simple V-groove based sliders and rails.
  4// Includes:
  5//   include <BOSL2/std.scad>
  6//   include <BOSL2/sliders.scad>
  7// FileGroup: Parts
  8// FileSummary: Simple sliders and rails.
  9//////////////////////////////////////////////////////////////////////
 10
 11
 12// Section: Modules
 13
 14
 15// Module: slider()
 16// Synopsis: Creates a V-groove slider.
 17// SynTags: Geom
 18// Topics: Parts, Sliders
 19// See Also: rail()
 20// Usage:
 21//   slider(l, w, h, [base=], [wall=], [ang=], [$slop=]) [ATTACHMENTS];
 22// Description:
 23//   Creates a slider to match a V-groove rail.
 24// Arguments:
 25//   l = Length (long axis) of slider.
 26//   w = Width of slider.
 27//   h = Height of slider.
 28//   ---
 29//   base = Height of slider base.
 30//   wall = Width of wall behind each side of the slider.
 31//   ang = Overhang angle for slider, to facilitate supportless printig.
 32//   anchor = Translate so anchor point is at origin (0,0,0).  See [anchor](attachments.scad#subsection-anchor).  Default: `CENTER`
 33//   spin = Rotate this many degrees around the Z axis after anchor.  See [spin](attachments.scad#subsection-spin).  Default: `0`
 34//   orient = Vector to rotate top towards, after spin.  See [orient](attachments.scad#subsection-orient).  Default: `UP`
 35//   $slop = The printer-specific slop value to make parts fit just right.
 36// Example:
 37//   slider(l=30, base=10, wall=4, $slop=0.2, spin=90);
 38function slider(l=30, w=10, h=10, base=10, wall=5, ang=30, anchor=BOTTOM, spin=0, orient=UP) = no_function("slider");
 39module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, anchor=BOTTOM, spin=0, orient=UP)
 40{
 41    full_width = w + 2*wall;
 42    full_height = h + base;
 43
 44    attachable(anchor,spin,orient, size=[full_width, l, h+2*base]) {
 45        zrot(90)
 46        down(base+h/2) {
 47            // Base
 48            cuboid([full_width, l, base-get_slop()], chamfer=2, edges=[FRONT,BACK], except_edges=BOT, anchor=BOTTOM);
 49
 50            // Wall
 51            xflip_copy(offset=w/2+get_slop()) {
 52                cuboid([wall, l, full_height], chamfer=2, edges=RIGHT, except_edges=BOT, anchor=BOTTOM+LEFT);
 53            }
 54
 55            // Sliders
 56            up(base+h/2) {
 57                xflip_copy(offset=w/2+get_slop()+0.02) {
 58                    bev_h = h/2*tan(ang);
 59                    prismoid([h, l], [0, l-w], h=bev_h+0.01, orient=LEFT, anchor=BOT);
 60                }
 61            }
 62        }
 63        children();
 64    }
 65}
 66
 67
 68
 69// Module: rail()
 70// Synopsis: Creates a V-groove rail.
 71// SynTags: Geom
 72// Topics: Parts, Sliders
 73// See Also: slider()
 74// Usage:
 75//   rail(l, w, h, [chamfer=], [ang=]) [ATTACHMENTS];
 76// Description:
 77//   Creates a V-groove rail.
 78// Arguments:
 79//   l = Length (long axis) of slider.
 80//   w = Width of slider.
 81//   h = Height of slider.
 82//   chamfer = Size of chamfer at end of rail.
 83//   ang = Overhang angle for slider, to facilitate supportless printing.
 84//   ---
 85//   anchor = Translate so anchor point is at origin (0,0,0).  See [anchor](attachments.scad#subsection-anchor).  Default: `BOTTOM`
 86//   spin = Rotate this many degrees around the Z axis after anchor.  See [spin](attachments.scad#subsection-spin).  Default: `0`
 87//   orient = Vector to rotate top towards, after spin.  See [orient](attachments.scad#subsection-orient).  Default: `UP`
 88// Example:
 89//   rail(l=100, w=10, h=10);
 90function rail(l=30, w=10, h=10, chamfer=1.0, ang=30, anchor=BOTTOM, spin=0, orient=UP) = no_function("rail");
 91module rail(l=30, w=10, h=10, chamfer=1.0, ang=30, anchor=BOTTOM, spin=0, orient=UP)
 92{
 93    attack_ang = 30;
 94    attack_len = 2;
 95
 96    fudge = 1.177;
 97    chamf = sqrt(2) * chamfer;
 98    cosa = cos(ang*fudge);
 99    sina = sin(ang*fudge);
100
101    z1 = h/2;
102    z2 = z1 - chamf * cosa;
103    z3 = z1 - attack_len * sin(attack_ang);
104    z4 = 0;
105
106    x1 = w/2;
107    x2 = x1 - chamf * sina;
108    x3 = x1 - chamf;
109    x4 = x1 - attack_len * sin(attack_ang);
110    x5 = x2 - attack_len * sin(attack_ang);
111    x6 = x1 - z1 * sina;
112    x7 = x4 - z1 * sina;
113
114    y1 = l/2;
115    y2 = y1 - attack_len * cos(attack_ang);
116
117    attachable(anchor,spin,orient, size=[w, l, h]) {
118        polyhedron(
119            convexity=4,
120            points=[
121                [-x5, -y1,  z3],
122                [ x5, -y1,  z3],
123                [ x7, -y1,  z4],
124                [ x4, -y1, -z1-0.05],
125                [-x4, -y1, -z1-0.05],
126                [-x7, -y1,  z4],
127
128                [-x3, -y2,  z1],
129                [ x3, -y2,  z1],
130                [ x2, -y2,  z2],
131                [ x6, -y2,  z4],
132                [ x1, -y2, -z1-0.05],
133                [-x1, -y2, -z1-0.05],
134                [-x6, -y2,  z4],
135                [-x2, -y2,  z2],
136
137                [ x5,  y1,  z3],
138                [-x5,  y1,  z3],
139                [-x7,  y1,  z4],
140                [-x4,  y1, -z1-0.05],
141                [ x4,  y1, -z1-0.05],
142                [ x7,  y1,  z4],
143
144                [ x3,  y2,  z1],
145                [-x3,  y2,  z1],
146                [-x2,  y2,  z2],
147                [-x6,  y2,  z4],
148                [-x1,  y2, -z1-0.05],
149                [ x1,  y2, -z1-0.05],
150                [ x6,  y2,  z4],
151                [ x2,  y2,  z2],
152            ],
153            faces=[
154                [0, 1, 2],
155                [0, 2, 5],
156                [2, 3, 4],
157                [2, 4, 5],
158
159                [0, 13, 6],
160                [0, 6, 7],
161                [0, 7, 1],
162                [1, 7, 8],
163                [1, 8, 9],
164                [1, 9, 2],
165                [2, 9, 10],
166                [2, 10, 3],
167                [3, 10, 11],
168                [3, 11, 4],
169                [4, 11, 12],
170                [4, 12, 5],
171                [5, 12, 13],
172                [5, 13, 0],
173
174                [14, 15, 16],
175                [14, 16, 19],
176                [16, 17, 18],
177                [16, 18, 19],
178
179                [14, 27, 20],
180                [14, 20, 21],
181                [14, 21, 15],
182                [15, 21, 22],
183                [15, 22, 23],
184                [15, 23, 16],
185                [16, 23, 24],
186                [16, 24, 17],
187                [17, 24, 25],
188                [17, 25, 18],
189                [18, 25, 26],
190                [18, 26, 19],
191                [19, 26, 27],
192                [19, 27, 14],
193
194                [6, 21, 20],
195                [6, 20, 7],
196                [7, 20, 27],
197                [7, 27, 8],
198                [8, 27, 26],
199                [8, 26, 9],
200                [9, 26, 25],
201                [9, 25, 10],
202                [10, 25, 24],
203                [10, 24, 11],
204                [11, 24, 23],
205                [11, 23, 12],
206                [12, 23, 22],
207                [12, 22, 13],
208                [13, 22, 21],
209                [13, 21, 6],
210            ]
211        );
212        children();
213    }
214}
215
216
217
218// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap