This commit is contained in:
Revar Desmera 2023-08-19 00:59:46 -07:00
parent 6a42df748b
commit 6eb2bb9689

View file

@ -8,61 +8,72 @@ The BOSL2 library provides a number of ways to do this:
```openscad-3D
include <BOSL2/std.scad>
left_half() sphere(d=100);
left_half()
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
right_half() sphere(d=100);
right_half()
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
front_half() sphere(d=100);
front_half()
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
back_half() sphere(d=100);
back_half()
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
bottom_half() sphere(d=100);
bottom_half()
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
top_half() sphere(d=100);
top_half()
sphere(d=100);
```
You can use the `half_of()` module if you want to split space in a way not aligned with an axis:
```openscad-3D
include <BOSL2/std.scad>
half_of([-1,0,-1]) sphere(d=100);
half_of([-1,0,-1])
sphere(d=100);
```
The plane of dissection can be shifted along the axis of any of these operators:
```openscad-3D
include <BOSL2/std.scad>
left_half(x=20) sphere(d=100);
left_half(x=20)
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
back_half(y=-20) sphere(d=100);
back_half(y=-20)
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
bottom_half(z=20) sphere(d=100);
bottom_half(z=20)
sphere(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
half_of([-1,0,-1], cp=[20,0,20]) sphere(d=100);
half_of([-1,0,-1], cp=[20,0,20])
sphere(d=100);
```
By default, these operators can be applied to objects that fit in a cube 1000 on a side. If you need
@ -71,7 +82,8 @@ argument:
```openscad-3D
include <BOSL2/std.scad>
bottom_half(s=2000) sphere(d=1500);
bottom_half(s=2000)
sphere(d=1500);
```
## 2D Plane Halving
@ -79,22 +91,26 @@ To cut 2D shapes in half, you will need to add the `planar=true` argument:
```openscad-3D
include <BOSL2/std.scad>
left_half(planar=true) circle(d=100);
left_half(planar=true)
circle(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
right_half(planar=true) circle(d=100);
right_half(planar=true)
circle(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
front_half(planar=true) circle(d=100);
front_half(planar=true)
circle(d=100);
```
```openscad-3D
include <BOSL2/std.scad>
back_half(planar=true) circle(d=100);
back_half(planar=true)
circle(d=100);
```
## Chained Mutators
@ -103,10 +119,10 @@ If you have a set of shapes that you want to do pair-wise hulling of, you can us
```openscad-3D
include <BOSL2/std.scad>
chain_hull() {
cube(5, center=true);
translate([30, 0, 0]) sphere(d=15);
translate([60, 30, 0]) cylinder(d=10, h=20);
translate([60, 60, 0]) cube([10,1,20], center=false);
cube(5, center=true);
translate([30, 0, 0]) sphere(d=15);
translate([60, 30, 0]) cylinder(d=10, h=20);
translate([60, 60, 0]) cube([10,1,20], center=false);
}
```
@ -115,14 +131,18 @@ The OpenSCAD `linear_extrude()` module can take a 2D shape and extrude it vertic
```openscad-3D
include <BOSL2/std.scad>
linear_extrude(height=30) zrot(45) square(40,center=true);
linear_extrude(height=30)
zrot(45)
square(40,center=true);
```
The `rotate_extrude()` module can take a 2D shape and rotate it around the Z axis.
```openscad-3D
include <BOSL2/std.scad>
linear_extrude(height=30) left(30) zrot(45) square(40,center=true);
rotate_extrude()
left(50) zrot(45)
square(40,center=true);
```
In a similar manner, the BOSL2 `cylindrical_extrude()` module can take a 2d shape and extrude it
@ -131,7 +151,7 @@ out radially from the center of a cylinder:
```openscad-3D
include <BOSL2/std.scad>
cylindrical_extrude(or=40, ir=35)
text(text="Hello World!", size=10, halign="center", valign="center");
text(text="Hello World!", size=10, halign="center", valign="center");
```
@ -143,12 +163,12 @@ Openscad provides the `minkowski()` module to trace a shape over the entire surf
```openscad-3D
include <BOSL2/std.scad>
minkowski() {
union() {
union() {
cube([100,33,33], center=true);
cube([33,100,33], center=true);
cube([33,33,100], center=true);
}
sphere(r=8);
}
sphere(r=8);
}
```
@ -158,12 +178,12 @@ of another object. For this, the BOSL2 library provides the `minkowski_differen
```openscad-3D
include <BOSL2/std.scad>
minkowski_difference() {
union() {
cube([100,33,33], center=true);
cube([33,100,33], center=true);
cube([33,33,100], center=true);
}
sphere(r=8);
union() {
cube([100,33,33], center=true);
cube([33,100,33], center=true);
cube([33,33,100], center=true);
}
sphere(r=8);
}
```
@ -172,11 +192,11 @@ To perform a `minkowski_difference()` on 2D shapes, you need to supply the `plan
```openscad-2D
include <BOSL2/std.scad>
minkowski_difference(planar=true) {
union() {
square([100,33], center=true);
square([33,100], center=true);
}
circle(r=8);
union() {
square([100,33], center=true);
square([33,100], center=true);
}
circle(r=8);
}
```
@ -185,24 +205,28 @@ The `round2d()` module lets you take a 2D shape and round inside and outside cor
```openscad-2D
include <BOSL2/std.scad>
round2d(or=8) star(6, step=2, d=100);
round2d(or=8)
star(6, step=2, d=100);
```
```openscad-2D
include <BOSL2/std.scad>
round2d(ir=12) star(6, step=2, d=100);
round2d(ir=12)
star(6, step=2, d=100);
```
```openscad-2D
include <BOSL2/std.scad>
round2d(or=8,ir=12) star(6, step=2, d=100);
round2d(or=8,ir=12)
star(6, step=2, d=100);
```
You can use `r=` to effectively set both `ir=` and `or=` to the same value:
```openscad-2D
include <BOSL2/std.scad>
round2d(r=8) star(6, step=2, d=100);
round2d(r=8)
star(6, step=2, d=100);
```
### Shell2d
@ -211,71 +235,84 @@ With a positive thickness, the shell is offset outwards from the original shape:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=5) star(5,step=2,d=100);
color("blue") stroke(star(5,step=2,d=100),closed=true);
shell2d(thickness=5)
star(5,step=2,d=100);
color("blue")
stroke(star(5,step=2,d=100),closed=true);
```
With a negative thickness, the shell if inset from the original shape:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5) star(5,step=2,d=100);
color("blue") stroke(star(5,step=2,d=100),closed=true);
shell2d(thickness=-5)
star(5,step=2,d=100);
color("blue")
stroke(star(5,step=2,d=100),closed=true);
```
You can give a pair of thickness values if you want it both inset and outset from the original shape:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=[-5,5]) star(5,step=2,d=100);
color("blue") stroke(star(5,step=2,d=100),closed=true);
shell2d(thickness=[-5,5])
star(5,step=2,d=100);
color("blue")
stroke(star(5,step=2,d=100),closed=true);
```
You can add rounding to the outside by passing a radius to the `or=` argument.
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,or=5) star(5,step=2,d=100);
shell2d(thickness=-5,or=5)
star(5,step=2,d=100);
```
If you need to pass different radii for the convex and concave corners of the outside, you can pass them as `or=[CONVEX,CONCAVE]`:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,or=[5,10]) star(5,step=2,d=100);
shell2d(thickness=-5,or=[5,10])
star(5,step=2,d=100);
```
A radius of 0 can be used to specify no rounding:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,or=[5,0]) star(5,step=2,d=100);
shell2d(thickness=-5,or=[5,0])
star(5,step=2,d=100);
```
You can add rounding to the inside by passing a radius to the `ir=` argument.
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,ir=5) star(5,step=2,d=100);
shell2d(thickness=-5,ir=5)
star(5,step=2,d=100);
```
If you need to pass different radii for the convex and concave corners of the inside, you can pass them as `ir=[CONVEX,CONCAVE]`:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,ir=[8,3]) star(5,step=2,d=100);
shell2d(thickness=-5,ir=[8,3])
star(5,step=2,d=100);
```
You can use `or=` and `ir=` together to get nice combined rounding effects:
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,or=[7,2],ir=[7,2]) star(5,step=2,d=100);
shell2d(thickness=-5,or=[7,2],ir=[7,2])
star(5,step=2,d=100);
```
```openscad-2D
include <BOSL2/std.scad>
shell2d(thickness=-5,or=[5,0],ir=[5,0]) star(5,step=2,d=100);
shell2d(thickness=-5,or=[5,0],ir=[5,0])
star(5,step=2,d=100);
```
@ -293,10 +330,10 @@ color scheme with the `hsl()` module:
include <BOSL2/std.scad>
n = 10; size = 100/n;
for (a=count(n), b=count(n), c=count(n)) {
let( h=360*a/n, s=1-b/(n-1), l=c/(n-1))
translate(size*[a,b,c]) {
hsl(h,s,l) cube(size);
}
let( h=360*a/n, s=1-b/(n-1), l=c/(n-1))
translate(size*[a,b,c]) {
hsl(h,s,l) cube(size);
}
}
```
@ -306,10 +343,10 @@ You can use the HSV or Hue-Saturation-Value color scheme with the `hsv()` module
include <BOSL2/std.scad>
n = 10; size = 100/n;
for (a=count(n), b=count(n), c=count(n)) {
let( h=360*a/n, s=1-b/(n-1), v=c/(n-1))
translate(size*[a,b,c]) {
hsv(h,s,v) cube(size);
}
let( h=360*a/n, s=1-b/(n-1), v=c/(n-1))
translate(size*[a,b,c]) {
hsv(h,s,v) cube(size);
}
}
```