mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Fixed rounding examples.
This commit is contained in:
parent
639d3ff2ae
commit
94a5943d24
2 changed files with 263 additions and 247 deletions
252
rounding.scad
252
rounding.scad
|
@ -198,8 +198,7 @@ include <skin.scad>
|
|||
// squareind = [for(i=[0:9]) each [i,i,i,i]]; // Index of the square for each point
|
||||
// z = list_range(40)*.2+squareind;
|
||||
// path3d = zip(spiral,z); // 3D spiral
|
||||
// // Rounding parameters get larger up the spiral; delete last point because
|
||||
// rounding = select(squareind/20,0,-2); // the path is not closed, so there are only len(path)-1 corners
|
||||
// rounding = squareind/20;
|
||||
// // Setting k=1 means curvature won't be continuous, but curves are as round as possible
|
||||
// // Try changing the value to see the effect.
|
||||
// rpath = round_corners(path3d, size=rounding, k=1, curve="smooth", measure="joint",closed=false);
|
||||
|
@ -238,7 +237,7 @@ function round_corners(path, curve="circle", measure="cut", size=undef, k=0.5,
|
|||
str(
|
||||
"Input `size` has length ", len(size),
|
||||
". Length must be ",
|
||||
(curve=="smooth"?"2 or ":""), len(path)-(closed?0:1)
|
||||
(curve=="smooth"?"2 or ":""), len(path)
|
||||
)
|
||||
) : str("Input `size` is ",size," which is not a number")
|
||||
)
|
||||
|
@ -260,8 +259,8 @@ function round_corners(path, curve="circle", measure="cut", size=undef, k=0.5,
|
|||
default_curvature
|
||||
)
|
||||
(!closed && (i==0 || i==len(points)-1))? [0,0] :
|
||||
(curve=="chamfer" && measure=="joint") ? [parm0] :
|
||||
(curve=="chamfer" && measure=="cut") ? [parm0/cos(angle)] :
|
||||
(curve=="chamfer" && measure=="joint") ? [parm0] :
|
||||
(curve=="chamfer" && measure=="cut") ? [parm0/cos(angle)] :
|
||||
(curve=="circle")? [k/tan(angle), k] :
|
||||
(curve=="smooth" && measure=="joint")? [parm0,k] :
|
||||
[8*parm0/cos(angle)/(1+4*k),k]
|
||||
|
@ -281,7 +280,7 @@ function round_corners(path, curve="circle", measure="cut", size=undef, k=0.5,
|
|||
for(i=[0:1:len(points)-1]) each
|
||||
(dk[i][0] == 0)? [points[i]] :
|
||||
(curve=="smooth")? _bezcorner(select(points,i-1,i+1), dk[i]) :
|
||||
(curve=="chamfer") ? _chamfcorner(select(points,i-1,i+1), dk[i]) :
|
||||
(curve=="chamfer") ? _chamfcorner(select(points,i-1,i+1), dk[i]) :
|
||||
_circlecorner(select(points,i-1,i+1), dk[i])
|
||||
];
|
||||
|
||||
|
@ -610,7 +609,6 @@ function smooth_path(path, tangents, k, splinesteps=10, closed=false) =
|
|||
// curve="smooth", measure="cut", size=4, $fn=36);
|
||||
// offset_sweep(offset(hole, r=-thickness, closed=true,check_valid=false),
|
||||
// height=48, steps=22, check_valid=false, bottom=os_circle(r=4), top=os_circle(r=-1,extra=1));
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// Example: Star shaped box
|
||||
|
@ -1015,7 +1013,6 @@ module convex_offset_extrude(
|
|||
else
|
||||
offset(delta=r[i+1][0],chamfer=dochamfer)
|
||||
children(j);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1457,7 +1454,7 @@ function patch_transform(transform,patch) =
|
|||
// debug = turn on debug mode which displays illegal polyhedra and shows the bezier corner patches for troubleshooting purposes. Default: False
|
||||
// convexity = convexity parameter for polyhedron(), only for module version. Default: 10
|
||||
// Example: Uniformly rounded pentagonal prism
|
||||
rounded_prism(pentagon(3), height=3, joint_top=0.5, joint_bot=0.5, joint_sides=0.5);
|
||||
// rounded_prism(pentagon(3), height=3, joint_top=0.5, joint_bot=0.5, joint_sides=0.5);
|
||||
// Example: Maximum possible rounding.
|
||||
// rounded_prism(pentagon(3), height=3, joint_top=1.5, joint_bot=1.5, joint_sides=1.5);
|
||||
// Example: Decreasing k from the default of 0.5 to 0.3 gives a smoother round over which takes up more space, so it appears less rounded.
|
||||
|
@ -1703,143 +1700,162 @@ function _circle_mask(r) =
|
|||
// Example: The mask as long pointed ends because this was the most efficient way to close off those ends.
|
||||
// bent_cutout_mask(10, 1, apply(xscale(3),circle(r=3)),$fn=64);
|
||||
// Example: An elliptical hole. Note the thickness is slightly increased to 1.05 compared to the actual thickness of 1.
|
||||
// $fn=128;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cyl(r=10.5, h=10);
|
||||
// cyl(r=9.5, h=11);
|
||||
// bent_cutout_mask(10, 1.05, apply(xscale(3),circle(r=3)),$fn=64);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cyl(r=10.5, h=10);
|
||||
// cyl(r=9.5, h=11);
|
||||
// bent_cutout_mask(10, 1.05, apply(xscale(3),circle(r=3)),$fn=64);
|
||||
// }
|
||||
// }
|
||||
// Example: An elliptical hole in a thick cylinder
|
||||
// $fn=128;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cyl(r=14.5, h=15);
|
||||
// cyl(r=9.5, h=16);
|
||||
// bent_cutout_mask(12, 5.1, apply(xscale(3),circle(r=3)));
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cyl(r=14.5, h=15);
|
||||
// cyl(r=9.5, h=16);
|
||||
// bent_cutout_mask(12, 5.1, apply(xscale(3),circle(r=3)));
|
||||
// }
|
||||
// }
|
||||
// Example: Complex shape example
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cyl(r=10.5, h=10, $fn=128);
|
||||
// cyl(r=9.5, h=11, $fn=128);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=2,m1=5, n1=0.3,n2=1.7)),$fn=32);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cyl(r=10.5, h=10, $fn=128);
|
||||
// cyl(r=9.5, h=11, $fn=128);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=2,m1=5, n1=0.3,n2=1.7)),$fn=32);
|
||||
// }
|
||||
// }
|
||||
// Example: this shape is invalid to to self-intersections at the inner corners
|
||||
// $fn=128;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=2,m1=5, n1=0.1,n2=1.7)),$fn=32);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=2,m1=5, n1=0.1,n2=1.7)),$fn=32);
|
||||
// }
|
||||
// }
|
||||
// Example: this shape is invalid due to self-intersections at the inner corners
|
||||
// $fn=128;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=12,m1=5, n1=0.1,n2=1.7)),$fn=32);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=12,m1=5, n1=0.1,n2=1.7)),$fn=32);
|
||||
// }
|
||||
// }
|
||||
// Example: increasing the step gives a valid shape, but the shape looks terrible with so few points.
|
||||
// $fn=128;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=12,m1=5, n1=0.1,n2=1.7)),$fn=32);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),supershape(step=12,m1=5, n1=0.1,n2=1.7)),$fn=32);
|
||||
// }
|
||||
// }
|
||||
// Example: uniform resampling produces a somewhat better result, but room remains for improvement. The lesson is that concave corners in your cutout cause trouble. To get a very good result we need to non-uniformly sample the supershape with more points at the star tips and few points at the inner corners.
|
||||
// $fn=128;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),resample_path(supershape(step=1,m1=5, n1=0.10,n2=1.7),60,closed=true)),$fn=32);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cylinder(r=10.5, h=10,center=true);
|
||||
// cylinder(r=9.5, h=11,center=true);
|
||||
// bent_cutout_mask(10, 1.05, apply(scale(3),resample_path(supershape(step=1,m1=5, n1=0.10,n2=1.7),60,closed=true)),$fn=32);
|
||||
// }
|
||||
// }
|
||||
// Example: The cutout spans 177 degrees. If you decrease the tube radius to 2.5 the cutout spans over 180 degrees and the calculation fails.
|
||||
// $fn=128;
|
||||
// r=2.6; // Don't make this much smaller or it will fail
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// tube(or=r, wall=1, h=10, anchor=CENTER);
|
||||
// bent_cutout_mask(r-0.5, 1.05, apply(scale(3),supershape(step=1,m1=5, n1=0.15,n2=1.7)),$fn=32);
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// tube(or=r, wall=1, h=10, anchor=CENTER);
|
||||
// bent_cutout_mask(r-0.5, 1.05, apply(scale(3),supershape(step=1,m1=5, n1=0.15,n2=1.7)),$fn=32);
|
||||
// }
|
||||
// }
|
||||
// Example: A square hole is not as simple as it seems. The model valid, but wrong, because the square didn't have enough samples to follow the curvature of the cylinder.
|
||||
// $fn=128;
|
||||
// r=25;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// tube(or=r, wall=2, h=45);
|
||||
// bent_cutout_mask(r-1, 2.1, back(5,p=square([18,18])));
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// tube(or=r, wall=2, h=45);
|
||||
// bent_cutout_mask(r-1, 2.1, back(5,p=square([18,18])));
|
||||
// }
|
||||
// }
|
||||
// Example: Adding additional points fixed this problem
|
||||
// $fn=128;
|
||||
// r=25;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// tube(or=r, wall=2, h=45);
|
||||
// bent_cutout_mask(r-1, 2.1, subdivide_path(back(5,p=square([18,18])),64,closed=true));
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// tube(or=r, wall=2, h=45);
|
||||
// bent_cutout_mask(r-1, 2.1, subdivide_path(back(5,p=square([18,18])),64,closed=true));
|
||||
// }
|
||||
// }
|
||||
// Example: Rounding just the exterior corners of this star avoids the problems we had above with concave corners of the supershape, as long as we don't oversample the star.
|
||||
// $fn=128;
|
||||
// r=25;
|
||||
// rot(-90)
|
||||
// difference(){
|
||||
// tube(or=r, wall=2, h=45);
|
||||
// bent_cutout_mask(r-1, 2.1, apply(back(15),subdivide_path(round_corners(star(n=7,ir=5,or=10), size=0.5*[1,0,1,0,1,0,1,0,1,0,1,0,1,0]),14*15,closed=true)));
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// tube(or=r, wall=2, h=45);
|
||||
// bent_cutout_mask(r-1, 2.1, apply(back(15),subdivide_path(round_corners(star(n=7,ir=5,or=10), size=0.5*[1,0,1,0,1,0,1,0,1,0,1,0,1,0]),14*15,closed=true)));
|
||||
// }
|
||||
// }
|
||||
// Example(2D): Cutting a slot in a cylinder is tricky if you want rounded corners at the top. This slot profile has slightly angled top edges to blend into the top edge of the cylinder.
|
||||
// function slot(slotwidth, slotheight, slotradius) =
|
||||
// let( angle = 85,
|
||||
// slot = round_corners(
|
||||
// turtle(["right",
|
||||
// "move", slotwidth,
|
||||
// "left", angle,
|
||||
// "move", 2*slotwidth,
|
||||
// "right", angle,
|
||||
// "move", slotheight,
|
||||
// "left",
|
||||
// "move", slotwidth,
|
||||
// "left",
|
||||
// "move", slotheight,
|
||||
// "right", angle,
|
||||
// "move", 2*slotwidth,
|
||||
// "left", angle,
|
||||
// "move", slotwidth]),
|
||||
// measure="radius", size=[0,0,each repeat(slotradius,4),0], closed=false))
|
||||
// apply(left(max(subindex(slot,0))/2)*fwd(min(subindex(slot,1))), slot);
|
||||
// function slot(slotwidth, slotheight, slotradius) = let(
|
||||
// angle = 85,
|
||||
// slot = round_corners(
|
||||
// turtle([
|
||||
// "right",
|
||||
// "move", slotwidth,
|
||||
// "left", angle,
|
||||
// "move", 2*slotwidth,
|
||||
// "right", angle,
|
||||
// "move", slotheight,
|
||||
// "left",
|
||||
// "move", slotwidth,
|
||||
// "left",
|
||||
// "move", slotheight,
|
||||
// "right", angle,
|
||||
// "move", 2*slotwidth,
|
||||
// "left", angle,
|
||||
// "move", slotwidth
|
||||
// ]),
|
||||
// measure="radius", size=[0,0,each repeat(slotradius,5),0], closed=false
|
||||
// )
|
||||
// ) apply(left(max(subindex(slot,0))/2)*fwd(min(subindex(slot,1))), slot);
|
||||
// stroke(slot(15,29,7));
|
||||
// Example: A cylindrical container with rounded edges and a rounded finger slot.
|
||||
function slot(slotwidth, slotheight, slotradius) =
|
||||
let( angle = 85,
|
||||
slot = round_corners(
|
||||
turtle(["right",
|
||||
"move", slotwidth,
|
||||
"left", angle,
|
||||
"move", 2*slotwidth,
|
||||
"right", angle,
|
||||
"move", slotheight,
|
||||
"left",
|
||||
"move", slotwidth,
|
||||
"left",
|
||||
"move", slotheight,
|
||||
"right", angle,
|
||||
"move", 2*slotwidth,
|
||||
"left", angle,
|
||||
"move", slotwidth]),
|
||||
measure="radius", size=[0,0,each repeat(slotradius,4),0,0], closed=false))
|
||||
apply(left(max(subindex(slot,0))/2)*fwd(min(subindex(slot,1))), slot);
|
||||
$fn=128;
|
||||
diam = 80;
|
||||
wall = 4;
|
||||
height = 40;
|
||||
rot(-90)
|
||||
difference(){
|
||||
cyl(d=diam, rounding=wall/2, h=height, anchor=BOTTOM);
|
||||
up(wall)cyl(d=diam-2*wall, rounding1=wall, rounding2=-wall/2, h=height-wall+.01, anchor=BOTTOM);
|
||||
bent_cutout_mask(diam/2-wall/2, wall+.1, subdivide_path(apply(back(10),slot(15, 29, 7)),250));
|
||||
}
|
||||
// function slot(slotwidth, slotheight, slotradius) = let(
|
||||
// angle = 85,
|
||||
// slot = round_corners(
|
||||
// turtle([
|
||||
// "right",
|
||||
// "move", slotwidth,
|
||||
// "left", angle,
|
||||
// "move", 2*slotwidth,
|
||||
// "right", angle,
|
||||
// "move", slotheight,
|
||||
// "left",
|
||||
// "move", slotwidth,
|
||||
// "left",
|
||||
// "move", slotheight,
|
||||
// "right", angle,
|
||||
// "move", 2*slotwidth,
|
||||
// "left", angle,
|
||||
// "move", slotwidth
|
||||
// ]),
|
||||
// measure="radius", size=[0,0,each repeat(slotradius,4),0,0], closed=false
|
||||
// )
|
||||
// ) apply(left(max(subindex(slot,0))/2)*fwd(min(subindex(slot,1))), slot);
|
||||
// diam = 80;
|
||||
// wall = 4;
|
||||
// height = 40;
|
||||
// rot(-90) {
|
||||
// $fn=128;
|
||||
// difference(){
|
||||
// cyl(d=diam, rounding=wall/2, h=height, anchor=BOTTOM);
|
||||
// up(wall)cyl(d=diam-2*wall, rounding1=wall, rounding2=-wall/2, h=height-wall+.01, anchor=BOTTOM);
|
||||
// bent_cutout_mask(diam/2-wall/2, wall+.1, subdivide_path(apply(back(10),slot(15, 29, 7)),250));
|
||||
// }
|
||||
// }
|
||||
|
||||
module bent_cutout_mask(r, thickness, path, convexity=10)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,311];
|
||||
BOSL_VERSION = [2,0,312];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue