Create Rounding the Cube.md

This commit is contained in:
Richard Milewski 2024-01-26 00:26:32 -08:00
parent 1fa97ae5aa
commit c7537d5478

View file

@ -0,0 +1,179 @@
# Rounding the Cube
One of the shape primitives you'll use most often in your OpenSCAD creations is the cube. Rounding the edges of cube-like objects impacts both the visual appeal and functional aspects of the final product. The BOSL2 library provides a variety of methods for rounding edges and corners.
There are four different 3d shape primitives that you can use to make cube-like objects:
* [**cuboid()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#module-cuboid) - Creates a cube with chamfering and roundovers.
* [**cube()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-cube) - An extended version of OpenSCAD's cube() with anchors for attaching children. (See the [Attachments Tutorial](https://github.com/BelfrySCAD/BOSL2/wiki/Tutorial-Attachments)).
* [**prismoid()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) - Creates a rectangular prismoid shape with optional roundovers and chamfering.
* [**rounded_prism()**](https://github.com/BelfrySCAD/BOSL2/wiki/shapes3d.scad#functionmodule-prismoid) - 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)).
BOSL2 provides two different methods for rounding the edges of the cube-like primitives above.
* **Built-in Rounding** - Cuboid, prismoid, and rounded_prism all have built-in arguments for rounding some or all of their edges.
* **Masking** - BOSL2 includes a number of options for masking the edges and corners of objects.
## Cuboid Rounding
You can round the edges of a cuboid() with the `rounding=` argument by specifying the radius of curvature:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=20);
```
If you want to round selected edges you can specify which edges using combinations of the named directions **LEFT, RIGHT, TOP, BOT, FWD, BACK**. See [specifying edges](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#subsection-specifying-edges) for more details.
![](https://github.com/BelfrySCAD/BOSL2/wiki/images/attachments/subsection-specifying-edges_fig1.png)
You can round just the top edges:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=20, edges = TOP);
```
...or just the bottom edges. Here we're using the *teardrop* parameter to limit the overhang angle to enable 3d printing without supports:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=20, teardrop = 45, edges = BOTTOM);
```
We can round only the edges aligned with one of the axes, X, Y, or Z:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=20, edges = "Z");
```
It is possible to round one or more of the edges while leaving others unrounded:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=20, edges = TOP+FRONT);
```
...or exclude the rounding of one or more edges while rounding all the others:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=20, except = TOP+FRONT);
```
There is support for filleting edges using negative rounding values:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], rounding=-20, edges = BOTTOM);
```
Chamfering the edges of the cuboid() can be done in a similar fashion:
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], chamfer=20);
```
You can specify edges as with the cuboid():
```openscad-3D
include <BOSL2/std.scad>
cuboid([100,80,60], chamfer=20, edges = "Z");
```
##Prismoid Rounding
The 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 chamferring for top and bottom separately:
```openscad-3D
include <BOSL2/std.scad>
prismoid(size1=[35,50], size2=[20,30], h=20, rounding1 = 8, rounding2 = 1);
```
You can also specify rounding of the 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:
```openscad-3D
include <BOSL2/std.scad>
prismoid(100, 80, rounding1=[0,50,0,50], rounding2=[40,0,40,0], h=50);
```
##Masking Edges of the Cuboid, Cube and Prismoid
###2D Edge Masking with [edge_profile()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_profile)
One 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.
2D 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).
We 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() applies a 2d roundover mask to the top edges of the cuboid.
```openscad-3D
include <BOSL2/std.scad>
diff()
cuboid([50,60,70], rounding = -10, edges = BOT)
edge_profile(TOP)
mask2d_roundover(r=10);
```
See [mask2d_roundover()](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_roundover) for additional mask parameters. Here we use the *inset* parameter in mask2d_roundover:
```openscad-3D
include <BOSL2/std.scad>
diff()
cube([50,60,70],center=true)
edge_profile(TOP, except=[BACK,TOP+LEFT])
mask2d_roundover(h=12, inset=4);
```
In addition to the simple roundover 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), [teardrop](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_teardrop) and [ogee](https://github.com/BelfrySCAD/BOSL2/wiki/masks2d.scad#functionmodule-mask2d_ogee) edges.
The mask2d_ogee() only works on cube() and cuboid() shapes, or a prismoid() where size2 >= size1 in both the X and Y dimensions.
```openscad-3d
include <BOSL2/std.scad>
diff()
prismoid(size1 = [50,50],size2 = [80,80], rounding1 = 25, height = 80)
edge_profile(TOP)
mask2d_ogee([
"xstep",8, "ystep",5, // Starting shoulder.
"fillet",5, "round",5, // S-curve.
"ystep",3, "xstep",3 // Ending shoulder.
]);
```
You can use edge-profile() to round the top or bottom of a prismoid(). Because the side faces of a prismoid() are not strictly vertical, it's is necessary to increase the length of the masks using the *excess* parameter in edge_profile().
```openscad-3D
include<BOSL2/std.scad>
diff()
prismoid(size1=[35,50], size2=[30,30], h=20, rounding1 = 8, rounding2 = 0)
edge_profile([TOP+LEFT, TOP+RIGHT], excess = 5)
mask2d_roundover(r = 15, mask_angle = $edge_angle);
```
###3D Edge and Corner Masking
BOSL2 contains a number of 3d edge and corner masks in addition to the 2d edge profiles shown above.
The 3d edge masks have the advantage of being able to vary the rounding radius along the edge. 3d edge masks can be attached using [edge_mask()](https://github.com/BelfrySCAD/BOSL2/wiki/attachments.scad#module-edge_mask). 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).
```openscad-3D
include <BOSL2/std.scad>
diff()
cuboid(80)
edge_mask(TOP+FWD)
rounding_edge_mask(r1 = 40, r2 = 0, l = 80);
```