1# Rounding the Cube
2
3One of the shape primitives you'll use most often in your OpenSCAD designs is the cube. Rounding the edges of cube-like objects impacts both the visual appeal and functional aspects of the final design. The BOSL2 library provides a variety of methods for rounding edges and corners.
4
5There are four different 3d shape primitives that you can use to make cube-like objects:
6
7* [**cuboid()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-cuboid) - Creates a cube with chamfering and roundovers.
8
9* [**cube()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-cube) - An extended version of OpenSCAD's [cube()](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#cube) with anchors for attaching children. (See the [Attachments Tutorial](https://github.com/BelfrySCAD/BOSL2/wiki/Tutorial-Attachments)).
10
11* [**prismoid()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) - Creates a rectangular prismoid shape with optional roundovers and chamfering.
12
13* [**rounded_prism()**](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#functionmodule-rounded_prism) - Makes a rounded 3d object by connecting two polygons with the same vertex count. Rounded_prism supports continuous curvature rounding. (See [Types of Roundovers](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#section-types-of-roundovers)).
14
15BOSL2 provides two different methods for rounding the edges of these cube-like primitives.
16
17* **Built-in Rounding** - The [cuboid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-cuboid), [prismoid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid), and [rounded_prism()](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#functionmodule-rounded_prism) all have built-in arguments for rounding some or all of their edges.
18
19* **Masking** - BOSL2 includes a number of options for masking the edges and corners of objects. Masking can accomplish rounding tasks that are not possible with the built-in rounding arguments. For example with masking you can have a cube with a different rounding radius on the top edges than the rounding radius on the bottom edges.
20
21Cube-like objects have six named faces: **LEFT, RIGHT, TOP, BOT, FWD, BACK**.
22
23
24
25Each of those face names is a vector pointing to the face. e.g. UP is [0,0,1], and FWD is [0,-1,0]. By adding two of those vectors we can specify an edge. For example, TOP + RIGHT is the same as [0,0,1] + [0,1,0] = [0,1,1].
26
27
28
29See [Specifying Edges](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#subsection-specifying-edges) for more details.
30
31## Cuboid Rounding
32
33You can round the edges of a [cuboid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-cuboid) with the `rounding` argument by specifying the radius of curvature:
34
35```openscad-3D
36include <BOSL2/std.scad>
37cuboid(100, rounding=20);
38```
39
40We can round the edges aligned with one of the axes, X, Y, or Z:
41
42```openscad-3D
43include <BOSL2/std.scad>
44cuboid([100,80,60], rounding=20, edges = "Z");
45```
46
47You can round all the edges on one of the faces. Here we're rounding only the top edges:
48
49```openscad-3D
50include <BOSL2/std.scad>
51cuboid([100,80,60], rounding=20, edges = TOP);
52```
53
54...or just the bottom edges. Here we're using the `teardrop` argument to limit the overhang angle to enable 3d printing on FDM printers without requiring supports:
55
56```openscad-3D
57include <BOSL2/std.scad>
58cuboid([100,80,60], rounding=20, teardrop = 45, edges = BOTTOM);
59```
60
61It is possible to round one or more of the edges while leaving others unrounded:
62
63```openscad-3D
64include <BOSL2/std.scad>
65cuboid([100,80,60], rounding=20, edges = TOP+FRONT);
66```
67
68...or exclude the rounding of one or more edges while rounding all the others:
69
70```openscad-3D
71include <BOSL2/std.scad>
72cuboid([100,80,60], rounding=20, except = TOP+FRONT);
73```
74
75Multiple edges can be specified in the form of a list:
76
77```openscad-3D
78include <BOSL2/std.scad>
79cuboid([100,80,60], rounding=20, edges=[FWD,TOP], except=[TOP+LEFT,FWD+RIGHT]);
80```
81
82You can also specify which edges to round using a 3x4 array, where each entry corresponds to one of the 12 edges and is set to 1 if that edge is included and 0 if the edge is not. The edge ordering is:
83
84[
85 [Y-Z-, Y+Z-, Y-Z+, Y+Z+],
86 [X-Z-, X+Z-, X-Z+, X+Z+],
87 [X-Y-, X+Y-, X-Y+, X+Y+]
88]
89
90```openscad-3D
91include <BOSL2/std.scad>
92cuboid([100,80,60], rounding=20, edges = [[1,0,1,0],[0,1,0,1],[1,0,0,1]]);
93```
94
95Similarly, you can use an array to exclude selected edges from rounding:
96
97```openscad-3D
98include <BOSL2/std.scad>
99cuboid([100,80,60], rounding=20, except = [[1,0,1,0],[0,1,0,1],[1,0,0,1]]);
100```
101
102### Negative Rounding
103
104You can fillet top or bottom edges by using negative rounding values. Note that you cannot use negative rounding values on Z-aligned (side) edges. If you need to add a fillet on a Z-aligned edge, use [fillet()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-fillet):
105
106```openscad-3D
107include <BOSL2/std.scad>
108cuboid([100,80,60], rounding=-20, edges = BOTTOM);
109```
110
111### Chamfering
112
113Chamfering the edges of the cuboid() can be done in a manner similar to rounding:
114
115```openscad-3D
116include <BOSL2/std.scad>
117cuboid([100,80,60], chamfer=20);
118```
119
120You can specify edges as with rounding:
121
122```openscad-3D
123include <BOSL2/std.scad>
124cuboid([100,80,60], chamfer=20, edges = "Z", except = FWD+RIGHT);
125```
126
127## Prismoid Rounding
128
129The [prismoid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) differs from the cuboid and cube in that you can only round or chamfer the vertical(ish) edges using the built-in parameters. For those edges, you can specify rounding and/or chamfering for top and bottom separately:
130
131```openscad-3D
132include <BOSL2/std.scad>
133prismoid(size1=[35,50], size2=[20,30], h=20, rounding1 = 8, rounding2 = 1);
134```
135
136You can also specify rounding of the individual vertical(ish) edges on an edge by edge basis by listing the edges in counter-clockwise order starting with the BACK+RIGHT (X+Y+) edge:
137
138```openscad-3D
139include <BOSL2/std.scad>
140prismoid(100, 80, rounding1=[0,50,0,50], rounding2=[40,0,40,0], h=50);
141```
142
143## Masking Edges of the Cuboid, Cube and Prismoid
144
145### 2D Edge Masking with [edge_profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile) and [edge_profile_asym()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile_asym)
146
147One limitation of using rounding arguments in [cuboid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-cuboid) is that all the rounded edges must have the same rounding radius. Using masking we have the flexibility to apply different edge treatments to the same cube. Masking can also be used on the [cube()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-cube) and [prismoid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) shapes.
148
1492D edge masks are attached to edges using [edge_profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile). They have a default tag of "remove" to enable differencing them away from your cube using [diff()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-diff).
150
151We can use a negative rounding value to fillet the bottom of a cuboid and [edge_profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile) to round the top. Here [edge_profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile) applies a 2d roundover mask to the top edges of the cuboid.
152
153```openscad-3D
154include <BOSL2/std.scad>
155diff()
156 cuboid([50,60,70], rounding = -10, edges = BOT)
157 edge_profile(TOP)
158 mask2d_roundover(r=10);
159```
160
161We could also fillet the bottom of the cube using [edge_profile_asym()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile_asym) and [xflip()](https://github.com/BelfrySCAD/BOSL2/wiki/transforms.scad#functionmodule-xflip)
162
163```openscad-3D
164include<BOSL2/std.scad>
165cuboid(50)
166 edge_profile_asym(BOT, corner_type="round")
167 xflip() mask2d_roundover(10);
168```
169
170The flip argumet in [edge_profile_asym()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile_asym) determines whether the fillet flares out or up. The corner_type argument is used to shape the corners of external fillets.
171
172```openscad-3D
173include<BOSL2/std.scad>
174cuboid(50){
175 edge_profile_asym(TOP, flip = true)
176 xflip() mask2d_roundover(10);
177 edge_profile_asym(BOT, corner_type="round")
178 xflip() mask2d_roundover(10);
179 }
180```
181
182See [mask2d_roundover()](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_roundover) for additional mask parameters. Here we use the *inset* parameter to produce a bead.
183
184```openscad-3D
185include <BOSL2/std.scad>
186diff()
187 cube([50,60,70],center=true)
188 edge_profile(TOP, except=[BACK,TOP+LEFT])
189 mask2d_roundover(h=12, inset=4);
190```
191
192You can use [edge-profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile) to round the top or bottom of a [prismoid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid). Because the side faces of a [prismoid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) are not strictly vertical, it's is necessary to increase the length of the masks using the *excess* parameter in [edge_profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile), and to set the mask\_angle to $edge\_angle in [mask2d\_roundover()](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_roundover).
193
194```openscad-3D
195include<BOSL2/std.scad>
196diff()
197 prismoid(size1=[35,50], size2=[30,30], h=20, rounding1 = 8, rounding2 = 0)
198 edge_profile([TOP+LEFT, TOP+RIGHT], excess = 5)
199 mask2d_roundover(r = 15, mask_angle = $edge_angle, $fn = 64);
200```
201
202Instead of specifying the rounding radius, you can specify the height of edge rounding.
203
204```openscad-3D
205include<BOSL2/std.scad>
206diff()
207 cube(30)
208 edge_profile([TOP+LEFT, TOP+RIGHT])
209 mask2d_roundover(h = 12, $fn = 64);
210```
211
212Rounding heights larger than an adjacent edge/2 will produce a ridge line on the top surface.
213
214```openscad-3D
215include<BOSL2/std.scad>
216diff()
217 cube(30)
218 edge_profile([TOP+LEFT, TOP+RIGHT])
219 mask2d_roundover(h = 20, $fn = 64);
220```
221
222The [mask2d_teardrop()](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_teardrop) mask can be used to round the bottom of a cube-like object. It limits the overhang angle to 45° or a value you specify in with the **angle** argument.
223
224```
225include<BOSL2/std.scad>
226diff()
227 prismoid([30,20], [40,30], rounding = 2, h = 20, $fn = 64)
228 edge_profile(BOT, excess = 15)
229 mask2d_teardrop(h = 5, angle = 50, mask_angle = $edge_angle, $fn = 64);
230```
231
232```openscad-3d; ImgOnly VPR=[88.5,0,6.4] VPT=[0,16,10] VPD=110
233include<BOSL2/std.scad>
234diff()
235 prismoid([30,20], [40,30], rounding = 2, h = 20, $fn = 64)
236 edge_profile(BOT, excess = 15)
237 mask2d_teardrop(h = 5, angle = 50, mask_angle = $edge_angle, $fn = 64);
238```
239
240In addition to the simple [roundover](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_roundover) mask, and the [teardrop](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_teardrop) mask, there are masks for [cove](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_cove), [chamfer](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_chamfer), [rabbet](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_rabbet), [dovetail](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_dovetail) and [ogee](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_ogee) edges.
241
242The mask2d_ogee() only works on [cube()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-cube) and [cuboid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-cuboid) shapes, or a [prismoid()](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) where size2 >= size1 in both the X and Y dimensions.
243
244```openscad-3D
245include <BOSL2/std.scad>
246diff()
247 prismoid(size1 = [50,50],size2 = [80,80], rounding1 = 25, height = 80)
248 edge_profile(TOP)
249 mask2d_ogee([
250 "xstep",8, "ystep",5, // Starting shoulder.
251 "fillet",5, "round",5, // S-curve.
252 "ystep",3, "xstep",3 // Ending shoulder.
253 ]);
254```
255
256Prismoids, espcecially prismoids with substantial shift, require careful selection of mask2d_roundover() arguments. Here we're setting radius = 5 and mask_angle = $edge_angle.
257
258```
259include<BOSL2/std.scad>
260diff()
261 prismoid([30,20], [50,60], h=20, shift=[30,40])
262 edge_profile(TOP, excess=35)
263 mask2d_roundover(r=5, mask_angle=$edge_angle, $fn=128);
264```
265
266```openscad-3D; ImgOnly VPT=[16,16,12] VPD=185 VPR=[84,0,82]
267include<BOSL2/std.scad>
268diff()
269 prismoid([30,20], [50,60], h=20, shift=[30,40])
270 edge_profile(TOP, excess=35)
271 mask2d_roundover(r=5, mask_angle=$edge_angle, $fn=128);
272```
273
274Specifying rounding height rather than rounding radius produces a different shape.
275
276```openscad-3D; ImgOnly VPT=[16,16,12] VPD=185 VPR=[84,0,82]
277include<BOSL2/std.scad>
278diff()
279 prismoid([30,20], [50,60], h=20, shift=[30,40])
280 edge_profile(TOP, excess=35)
281 mask2d_roundover(h=5, mask_angle=$edge_angle, $fn=128);
282```
283
284```
285include<BOSL2/std.scad>
286diff()
287 prismoid([30,20], [50,60], h=20, shift=[30,40])
288 edge_profile(TOP, excess=35)
289 mask2d_roundover(h=5, mask_angle=$edge_angle, $fn=128);
290```
291
292The quarter_round argument works well for edges with acute angles, but leaves a ledge on the edges with obtuse angles.
293
294```openscad-3D; ImgOnly VPT=[16,16,12] VPD=185 VPR=[84,0,82]
295include<BOSL2/std.scad>
296diff()
297 prismoid([30,20], [50,60], h=20, shift=[30,40])
298 edge_profile(TOP, excess=35)
299 mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round = true, $fn=128);
300```
301
302```
303include<BOSL2/std.scad>
304diff()
305 prismoid([30,20], [50,60], h=20, shift=[30,40])
306 edge_profile(TOP, excess=35)
307 mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round = true, $fn=128);
308```
309
310A work-around is to use quarter_round only on the edges with acute angles.
311
312```openscad-3D; ImgOnly VPT=[16,16,12] VPD=185 VPR=[84,0,82]
313include<BOSL2/std.scad>
314diff()
315 prismoid([30,20], [50,60], h=20, shift=[30,40])
316 edge_profile(TOP, excess=35)
317 mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round = $edge_angle<90, $fn=128);
318```
319
320```
321include<BOSL2/std.scad>
322diff()
323 prismoid([30,20], [50,60], h=20, shift=[30,40])
324 edge_profile(TOP, excess=35)
325 mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round = $edge_angle<90, $fn=128);
326```
327
328### 3D Edge and Corner Masking
329
330BOSL2 contains a number of 3d edge and corner masks in addition to the 2d edge profiles shown above.
331
332The 3d edge masks have the advantage of being able to vary the rounding radius along the edge. 3d edge masks, such as[rounding_edge_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/masks3d.scad#module-rounding_edge_mask), can be attached using [edge_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_mask). The 3D edge masks have a default tag of "remove" to enable differencing them away from your cube using [diff()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-diff).
333
334```openscad-3D
335include <BOSL2/std.scad>
336diff()
337 cuboid(80)
338 edge_mask(TOP+FWD)
339 rounding_edge_mask(r1 = 40, r2 = 0, l = 80);
340```
341
342While you can specify the length of the mask with the l or h argument, [edge_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_mask) sets a special variable, `$parent_size`, to the size of the parent object. In the case where the parent is not a perfect cube, you need to mask each edge individually:
343
344```openscad-3D
345include <BOSL2/std.scad>
346diff()
347 cuboid([60,80,40]) {
348 edge_mask(TOP+FWD)
349 rounding_edge_mask(r = 10, l = $parent_size.x + 0.1);
350 edge_mask(TOP+RIGHT)
351 rounding_edge_mask(r = 10, l = $parent_size.y + 0.1);
352 edge_mask(RIGHT+FWD)
353 rounding_edge_mask(r = 10, l = $parent_size.z + 0.1);
354 }
355```
356
357As you can see above, using only [rounding\_edge_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/masks3d.scad#module-rounding_edge_mask) to round the top of the cube leaves the corners unrounded. Use [corner_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-corner_mask) and [rounding\_corner_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/masks3d.scad#module-rounding_corner_mask) for a smoother corner.
358
359```openscad-3D
360include <BOSL2/std.scad>
361diff()
362 cuboid([60,80,40]) {
363 edge_mask(TOP+FWD)
364 rounding_edge_mask(r = 10, l = $parent_size.x + 0.1);
365 edge_mask(TOP+RIGHT)
366 rounding_edge_mask(r = 10, l = $parent_size.y + 0.1);
367 edge_mask(RIGHT+FWD)
368 rounding_edge_mask(r = 10, l = $parent_size.z + 0.1);
369 corner_mask(TOP+RIGHT+FWD)
370 rounding_corner_mask(r = 10);
371 }
372
373```
374
375As with the built-in rounding arguments, you can use [edge\_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_mask) and [corner\_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-corner_mask) to apply teardrop roundings using [teardrop\_edge_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/masks3d.scad#module-teardrop_edge_mask) and [teardrop\_corner_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/masks3d.scad#module-teardrop_corner_mask) to limit the overhang angle for better printing on FDM printers. Note that the vertical mask on the RIGHT_FWD edge is a [rounding\_edge\_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/masks3d.scad#module-rounding_edge_mask).
376
377```openscad-3D
378include <BOSL2/std.scad>
379diff()
380 cuboid([60,80,40]) {
381 edge_mask(BOT+FWD)
382 teardrop_edge_mask(r = 10, l = $parent_size.x + 0.1, angle = 40);
383 edge_mask(BOT+RIGHT)
384 teardrop_edge_mask(r = 10, l = $parent_size.y + 0.1, angle = 40);
385 edge_mask(RIGHT+FWD)
386 rounding_edge_mask(r = 10, l = $parent_size.z + 0.1);
387 corner_mask(BOT+RIGHT+FWD)
388 teardrop_corner_mask(r = 10, angle = 40);
389 }
390
391```
392
393## Rounded Prism
394
395You can construct cube-like objects, as well as a variety of other prisms using [rounded_prism()](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#functionmodule-rounded_prism). In this tutorial we're concentrating on rounding cubes, but [rounded_prism()](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#functionmodule-rounded_prism) has capabilities that extend well beyond cube-like objects. See the [rounded_prism()](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#functionmodule-rounded_prism) examples to learn more.
396
397A feature unique to [rounded_prism()](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#functionmodule-rounded_prism) is that it uses continuous curvature rounding. Rather than using constant radius arcs, continuous curvature rounding uses 4th-order Bezier curves. For complete details on how this works see [Types of Roundovers](https://github.com/BelfrySCAD/BOSL2/wiki/rounding.scad#section-types-of-roundovers).
398
399Two parameters control the roundover, k and joint. The joint parameter is the distance from where the rounding starts to the unrounded edge. The k parameter ranges from 0 to 1 with a default of 0.5. Larger values give a more abrupt transition and smaller ones a more gradual transition.
400
401Parameters of a "smooth" roundover, with k=0.75.
402
403
404
405Parameters of a "smooth" roundover, with k=0.15. The transition is so gradual that it appears that the roundover is much smaller than specified. The cut length is much smaller for the same joint length.
406
407
408
409The joint parameter is specified separately for the top, bottom and side edges; joint\_top, joint\_bot, and joint_sides.
410
411 If you want a very smooth roundover, set the joint parameter as large as possible and then adjust the k value down low enough to achieve a sufficiently large roundover. Joint parameters usually need to be < side/2.
412
413```openscad-3D
414include <BOSL2/std.scad>
415include <BOSL2/rounding.scad>
416rounded_prism(rect(20), height=20,
417 joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.5);
418```
419
420Here we're using the same cube size and joint sizes, but varying the k parameter.
421
422```openscad-3D;ImgOnly NoScales Med VPD=170 VPR=[75,0,25]
423include <BOSL2/std.scad>
424include <BOSL2/rounding.scad>
425 left(30) {
426 rounded_prism(rect(20), height=20, joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.15);
427 move([0,-12,-12]) xrot(90) color("black") text3d("k=0.15", size=3, h = 0.01, anchor= CENTER);
428}
429
430right(0){
431 rounded_prism(rect(20), height=20, joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.5);
432 move([0,-12,-12]) xrot(90) color("black") text3d("k=0.5", size=3, h = 0.01, anchor= CENTER);
433}
434
435right(30){
436 rounded_prism(rect(20), height=20, joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.75);
437 move([0,-12,-12]) xrot(90) color("black") text3d("k=0.75", size=3, h = 0.01, anchor= CENTER);
438}
439```
440
441Alternatively, we can keep k constant at k=0.5 and vary the joint length:
442
443```openscad-3D;ImgOnly NoScales Med VPD=170 VPR=[75,0,25]
444include <BOSL2/std.scad>
445include <BOSL2/rounding.scad>
446 left(30) {
447 rounded_prism(rect(20), height=20, joint_top=1, joint_bot=1, joint_sides=1, k = 0.5);
448 move([0,-13,-13]) xrot(90) color("black") text3d("joint=1", size=3, h = 0.01, anchor= CENTER);
449}
450
451right(0){
452 rounded_prism(rect(20), height=20, joint_top=5, joint_bot=5, joint_sides=5, k = 0.5);
453 move([0,-13,-13]) xrot(90) color("black") text3d("joint=5", size=3, h = 0.01, anchor= CENTER);
454}
455
456right(30){
457 rounded_prism(rect(20), height=20, joint_top=9, joint_bot=9, joint_sides=9, k = 0.5);
458 move([0,-13,-13]) xrot(90) color("black") text3d("joint=9", size=3, h = 0.01, anchor= CENTER);
459}
460```
461
462You can match the cicrular roundover of cuboid() by setting the joint values to the rounding used in cuboid() and setting the k value to 0.93:
463
464```openscad-3D: Med, VPR=[75,0,25], VPD=180
465include <BOSL2/std.scad>
466include <BOSL2/rounding.scad>
467left(15)
468 rounded_prism(rect(20), height=20, joint_top=4, joint_bot=4, joint_sides=4, k = 0.93);
469right(15)
470 cuboid(20, rounding = 4, $fn = 72);
471```
472
473Unlike other cube-like objects, the rounded prism smoothness is not affected by the special variable $fn, but by the splinesteps argument. Splinesteps defaults to 16.
474
475```openscad-3D;ImgOnly NoScales, Med, VPD=170, VPR=[75,0,45]
476include <BOSL2/std.scad>
477include <BOSL2/rounding.scad>
478 left(35) {
479 rounded_prism(rect(20), height=20, joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.5, splinesteps = 4 )
480 move([0,-12,-12]) xrot(90) color("black") text3d("splinesteps=4", size=3, h = 0.01, anchor= CENTER);
481}
482
483right(0){
484 rounded_prism(rect(20), height=20, joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.5, splinesteps = 16)
485 move([0,-12,-12]) xrot(90) color("black") text3d("splinesteps=16", size=3, h = 0.01, anchor= CENTER);
486}
487
488right(35){
489 rounded_prism(rect(20), height=20, joint_top=9.99, joint_bot=9.99, joint_sides=9.99, k = 0.5, splinesteps = 64)
490 move([0,-12,-12]) xrot(90) color("black") text3d("splinesteps=64", size=3, h = 0.01, anchor= CENTER);
491}
492```
493
494The joint size can be set to different values for each side of the prism:
495
496```openscad-3D
497include <BOSL2/std.scad>
498include <BOSL2/rounding.scad>
499rounded_prism(rect(20), height=20,
500 joint_top=4, joint_bot=3, joint_sides=[2, 10, 5, 10], k = 0.5);
501```
502
503Likewise, k can be set to different values for each side of the prism:
504
505```openscad-3D
506include <BOSL2/std.scad>
507include <BOSL2/rounding.scad>
508rounded_prism(rect(20), height=20,
509 joint_top=3, joint_bot=3, joint_sides=8,
510 k_top=0.5, k_bot=0.1, k_sides=[0,0.7,0.3,0.7]);
511```
512
513You can specify a 2-vector for the joint distance to produce asymmetric rounding which is different on the two sides of the edge. This may be useful when one one edge in your polygon is much larger than another.
514
515```openscad-3D
516include <BOSL2/std.scad>
517include <BOSL2/rounding.scad>
518rounded_prism(rect([50.1,20.1]), height=6.1,
519 joint_top=[15,3], joint_bot=[15,3],
520 joint_sides=[[10,25],[25,10],[10,25],[25,10]],
521 k_sides=0.3);
522```
523
524For the top and bottom you can specify negative joint distances. If you give a scalar negative value then the roundover will flare outward.
525
526```openscad-3D
527include <BOSL2/std.scad>
528include <BOSL2/rounding.scad>
529rounded_prism(rect(20), height=20,
530 joint_top=5, joint_bot=-5, joint_sides=8, k=0.5);
531```
532
533If you give a 2-vector then if joint\_top[0] is negative the shape will flare outward, but if joint\_top[1] is negative the shape will flare upward. At least one value must be non-negative. The same rules apply for joint\_bot. The joint\_sides parameter must be entirely nonnegative.
534
535Flaring the top upward. The bottom has an asymmetric rounding with a small flare but a large rounding up the side.
536
537```openscad-3D
538include <BOSL2/std.scad>
539include <BOSL2/rounding.scad>
540rounded_prism(rect(20), height=20,
541joint_top=[3,-3], joint_bot=[-3,10], joint_sides=8, k=0.5);
542```