1//////////////////////////////////////////////////////////////////////
2// LibFile: sliders.scad
3// Simple V-groove based sliders and rails.
4// To use, add these lines to the beginning of your file:
5// ```
6// include <BOSL/constants.scad>
7// use <BOSL/sliders.scad>
8// ```
9//////////////////////////////////////////////////////////////////////
10
11/*
12BSD 2-Clause License
13
14Copyright (c) 2017, Revar Desmera
15All rights reserved.
16
17Redistribution and use in source and binary forms, with or without
18modification, are permitted provided that the following conditions are met:
19
20* Redistributions of source code must retain the above copyright notice, this
21 list of conditions and the following disclaimer.
22
23* Redistributions in binary form must reproduce the above copyright notice,
24 this list of conditions and the following disclaimer in the documentation
25 and/or other materials provided with the distribution.
26
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37*/
38
39use <transforms.scad>
40use <shapes.scad>
41include <compat.scad>
42include <constants.scad>
43
44
45// Section: Modules
46
47
48// Module: slider()
49// Description:
50// Creates a slider to match a V-groove rail.
51// Usage:
52// slider(l, w, h, [base], [wall], [ang], [slop], [orient], [align])
53// Arguments:
54// l = Length (long axis) of slider.
55// w = Width of slider.
56// h = Height of slider.
57// chamfer = Size of chamfer
58// base = Height of slider base.
59// wall = Width of wall behind each side of the slider.
60// ang = Overhang angle for slider, to facilitate supportless printig.
61// slop = Printer-specific slop value to make parts fit exactly.
62// orient = Orientation of the slider. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
63// align = Alignment of the slider. Use the `V_` constants from `constants.scad`. Default: `V_UP`.
64// Example:
65// slider(l=30, base=10, wall=4, slop=0.2, orient=ORIENT_Y);
66module slider(l=30, w=10, h=10, chamfer=2, base=10, wall=5, ang=30, slop=PRINTER_SLOP, orient=ORIENT_Y, align=V_UP)
67{
68 full_width = w + 2*wall;
69 full_height = h + base;
70
71 orient_and_align([full_width, l, h+2*base], orient, align, orig_orient=ORIENT_Y) {
72 down(base+h/2) {
73 // Base
74 cuboid([full_width, l, base-slop], chamfer=chamfer, edges=EDGE_TOP_FR+EDGE_TOP_BK+EDGES_Z_ALL, align=V_UP);
75
76 // Wall
77 xflip_copy(offset=w/2+slop) {
78 cuboid([wall, l, full_height], chamfer=chamfer, edges=EDGE_TOP_RT+EDGE_FR_RT+EDGE_BK_RT, align=V_UP+V_RIGHT);
79 }
80
81 // Sliders
82 up(base+h/2) {
83 xflip_copy(offset=w/2+slop+0.02) {
84 bev_h = h/2*tan(ang);
85 prismoid([l, h], [l-w, 0], h=bev_h+0.01, orient=ORIENT_XNEG, align=V_LEFT);
86 }
87 }
88 }
89 }
90}
91
92
93
94// Module: rail()
95// Description:
96// Creates a V-groove rail.
97// Usage:
98// rail(l, w, h, [chamfer], [ang], [orient], [align])
99// Arguments:
100// l = Length (long axis) of slider.
101// w = Width of slider.
102// h = Height of slider.
103// chamfer = Size of chamfer at end of rail.
104// ang = Overhang angle for slider, to facilitate supportless printig.
105// orient = Orientation of the rail. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
106// align = Alignment of the rail. Use the `V_` constants from `constants.scad`. Default: `V_UP`.
107// Example:
108// rail(l=100, w=10, h=10);
109module rail(l=30, w=10, h=10, chamfer=1.0, ang=30, orient=ORIENT_Y, align=V_UP)
110{
111 attack_ang = 30;
112 attack_len = 2;
113
114 fudge = 1.177;
115 chamf = sqrt(2) * chamfer;
116 cosa = cos(ang*fudge);
117 sina = sin(ang*fudge);
118
119 z1 = h/2;
120 z2 = z1 - chamf * cosa;
121 z3 = z1 - attack_len * sin(attack_ang);
122 z4 = 0;
123
124 x1 = w/2;
125 x2 = x1 - chamf * sina;
126 x3 = x1 - chamf;
127 x4 = x1 - attack_len * sin(attack_ang);
128 x5 = x2 - attack_len * sin(attack_ang);
129 x6 = x1 - z1 * sina;
130 x7 = x4 - z1 * sina;
131
132 y1 = l/2;
133 y2 = y1 - attack_len * cos(attack_ang);
134
135 orient_and_align([w, l, h], orient, align, orig_orient=ORIENT_Y) {
136 polyhedron(
137 convexity=4,
138 points=[
139 [-x5, -y1, z3],
140 [ x5, -y1, z3],
141 [ x7, -y1, z4],
142 [ x4, -y1, -z1-0.05],
143 [-x4, -y1, -z1-0.05],
144 [-x7, -y1, z4],
145
146 [-x3, -y2, z1],
147 [ x3, -y2, z1],
148 [ x2, -y2, z2],
149 [ x6, -y2, z4],
150 [ x1, -y2, -z1-0.05],
151 [-x1, -y2, -z1-0.05],
152 [-x6, -y2, z4],
153 [-x2, -y2, z2],
154
155 [ x5, y1, z3],
156 [-x5, y1, z3],
157 [-x7, y1, z4],
158 [-x4, y1, -z1-0.05],
159 [ x4, y1, -z1-0.05],
160 [ x7, y1, z4],
161
162 [ x3, y2, z1],
163 [-x3, y2, z1],
164 [-x2, y2, z2],
165 [-x6, y2, z4],
166 [-x1, y2, -z1-0.05],
167 [ x1, y2, -z1-0.05],
168 [ x6, y2, z4],
169 [ x2, y2, z2],
170 ],
171 faces=[
172 [0, 1, 2],
173 [0, 2, 5],
174 [2, 3, 4],
175 [2, 4, 5],
176
177 [0, 13, 6],
178 [0, 6, 7],
179 [0, 7, 1],
180 [1, 7, 8],
181 [1, 8, 9],
182 [1, 9, 2],
183 [2, 9, 10],
184 [2, 10, 3],
185 [3, 10, 11],
186 [3, 11, 4],
187 [4, 11, 12],
188 [4, 12, 5],
189 [5, 12, 13],
190 [5, 13, 0],
191
192 [14, 15, 16],
193 [14, 16, 19],
194 [16, 17, 18],
195 [16, 18, 19],
196
197 [14, 27, 20],
198 [14, 20, 21],
199 [14, 21, 15],
200 [15, 21, 22],
201 [15, 22, 23],
202 [15, 23, 16],
203 [16, 23, 24],
204 [16, 24, 17],
205 [17, 24, 25],
206 [17, 25, 18],
207 [18, 25, 26],
208 [18, 26, 19],
209 [19, 26, 27],
210 [19, 27, 14],
211
212 [6, 21, 20],
213 [6, 20, 7],
214 [7, 20, 27],
215 [7, 27, 8],
216 [8, 27, 26],
217 [8, 26, 9],
218 [9, 26, 25],
219 [9, 25, 10],
220 [10, 25, 24],
221 [10, 24, 11],
222 [11, 24, 23],
223 [11, 23, 12],
224 [12, 23, 22],
225 [12, 22, 13],
226 [13, 22, 21],
227 [13, 21, 6],
228 ]
229 );
230 }
231}
232
233
234
235// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap