mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Fixed rounding examples.
This commit is contained in:
parent
639d3ff2ae
commit
94a5943d24
2 changed files with 263 additions and 247 deletions
128
rounding.scad
128
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
|
// squareind = [for(i=[0:9]) each [i,i,i,i]]; // Index of the square for each point
|
||||||
// z = list_range(40)*.2+squareind;
|
// z = list_range(40)*.2+squareind;
|
||||||
// path3d = zip(spiral,z); // 3D spiral
|
// path3d = zip(spiral,z); // 3D spiral
|
||||||
// // Rounding parameters get larger up the spiral; delete last point because
|
// rounding = squareind/20;
|
||||||
// rounding = select(squareind/20,0,-2); // the path is not closed, so there are only len(path)-1 corners
|
|
||||||
// // Setting k=1 means curvature won't be continuous, but curves are as round as possible
|
// // Setting k=1 means curvature won't be continuous, but curves are as round as possible
|
||||||
// // Try changing the value to see the effect.
|
// // Try changing the value to see the effect.
|
||||||
// rpath = round_corners(path3d, size=rounding, k=1, curve="smooth", measure="joint",closed=false);
|
// 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(
|
str(
|
||||||
"Input `size` has length ", len(size),
|
"Input `size` has length ", len(size),
|
||||||
". Length must be ",
|
". 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")
|
) : str("Input `size` is ",size," which is not a number")
|
||||||
)
|
)
|
||||||
|
@ -610,7 +609,6 @@ function smooth_path(path, tangents, k, splinesteps=10, closed=false) =
|
||||||
// curve="smooth", measure="cut", size=4, $fn=36);
|
// curve="smooth", measure="cut", size=4, $fn=36);
|
||||||
// offset_sweep(offset(hole, r=-thickness, closed=true,check_valid=false),
|
// 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));
|
// height=48, steps=22, check_valid=false, bottom=os_circle(r=4), top=os_circle(r=-1,extra=1));
|
||||||
//
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// Example: Star shaped box
|
// Example: Star shaped box
|
||||||
|
@ -1015,7 +1013,6 @@ module convex_offset_extrude(
|
||||||
else
|
else
|
||||||
offset(delta=r[i+1][0],chamfer=dochamfer)
|
offset(delta=r[i+1][0],chamfer=dochamfer)
|
||||||
children(j);
|
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
|
// 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
|
// convexity = convexity parameter for polyhedron(), only for module version. Default: 10
|
||||||
// Example: Uniformly rounded pentagonal prism
|
// 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.
|
// Example: Maximum possible rounding.
|
||||||
// rounded_prism(pentagon(3), height=3, joint_top=1.5, joint_bot=1.5, joint_sides=1.5);
|
// 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.
|
// 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,97 +1700,110 @@ function _circle_mask(r) =
|
||||||
// Example: The mask as long pointed ends because this was the most efficient way to close off those ends.
|
// 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);
|
// 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.
|
// Example: An elliptical hole. Note the thickness is slightly increased to 1.05 compared to the actual thickness of 1.
|
||||||
|
// rot(-90) {
|
||||||
// $fn=128;
|
// $fn=128;
|
||||||
// rot(-90)
|
|
||||||
// difference(){
|
// difference(){
|
||||||
// cyl(r=10.5, h=10);
|
// cyl(r=10.5, h=10);
|
||||||
// cyl(r=9.5, h=11);
|
// cyl(r=9.5, h=11);
|
||||||
// bent_cutout_mask(10, 1.05, apply(xscale(3),circle(r=3)),$fn=64);
|
// bent_cutout_mask(10, 1.05, apply(xscale(3),circle(r=3)),$fn=64);
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
// Example: An elliptical hole in a thick cylinder
|
// Example: An elliptical hole in a thick cylinder
|
||||||
|
// rot(-90) {
|
||||||
// $fn=128;
|
// $fn=128;
|
||||||
// rot(-90)
|
|
||||||
// difference(){
|
// difference(){
|
||||||
// cyl(r=14.5, h=15);
|
// cyl(r=14.5, h=15);
|
||||||
// cyl(r=9.5, h=16);
|
// cyl(r=9.5, h=16);
|
||||||
// bent_cutout_mask(12, 5.1, apply(xscale(3),circle(r=3)));
|
// bent_cutout_mask(12, 5.1, apply(xscale(3),circle(r=3)));
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
// Example: Complex shape example
|
// Example: Complex shape example
|
||||||
// rot(-90)
|
// rot(-90) {
|
||||||
|
// $fn=128;
|
||||||
// difference(){
|
// difference(){
|
||||||
// cyl(r=10.5, h=10, $fn=128);
|
// cyl(r=10.5, h=10, $fn=128);
|
||||||
// cyl(r=9.5, h=11, $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);
|
// 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
|
// Example: this shape is invalid to to self-intersections at the inner corners
|
||||||
|
// rot(-90) {
|
||||||
// $fn=128;
|
// $fn=128;
|
||||||
// rot(-90)
|
|
||||||
// difference(){
|
// difference(){
|
||||||
// cylinder(r=10.5, h=10,center=true);
|
// cylinder(r=10.5, h=10,center=true);
|
||||||
// cylinder(r=9.5, h=11,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);
|
// 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
|
// Example: this shape is invalid due to self-intersections at the inner corners
|
||||||
|
// rot(-90) {
|
||||||
// $fn=128;
|
// $fn=128;
|
||||||
// rot(-90)
|
|
||||||
// difference(){
|
// difference(){
|
||||||
// cylinder(r=10.5, h=10,center=true);
|
// cylinder(r=10.5, h=10,center=true);
|
||||||
// cylinder(r=9.5, h=11,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);
|
// 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.
|
// Example: increasing the step gives a valid shape, but the shape looks terrible with so few points.
|
||||||
|
// rot(-90) {
|
||||||
// $fn=128;
|
// $fn=128;
|
||||||
// rot(-90)
|
|
||||||
// difference(){
|
// difference(){
|
||||||
// cylinder(r=10.5, h=10,center=true);
|
// cylinder(r=10.5, h=10,center=true);
|
||||||
// cylinder(r=9.5, h=11,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);
|
// 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.
|
// 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.
|
||||||
|
// rot(-90) {
|
||||||
// $fn=128;
|
// $fn=128;
|
||||||
// rot(-90)
|
|
||||||
// difference(){
|
// difference(){
|
||||||
// cylinder(r=10.5, h=10,center=true);
|
// cylinder(r=10.5, h=10,center=true);
|
||||||
// cylinder(r=9.5, h=11,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);
|
// 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.
|
// 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
|
// r=2.6; // Don't make this much smaller or it will fail
|
||||||
// rot(-90)
|
// rot(-90) {
|
||||||
|
// $fn=128;
|
||||||
// difference(){
|
// difference(){
|
||||||
// tube(or=r, wall=1, h=10, anchor=CENTER);
|
// 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);
|
// 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.
|
// 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;
|
// r=25;
|
||||||
// rot(-90)
|
// rot(-90) {
|
||||||
|
// $fn=128;
|
||||||
// difference(){
|
// difference(){
|
||||||
// tube(or=r, wall=2, h=45);
|
// tube(or=r, wall=2, h=45);
|
||||||
// bent_cutout_mask(r-1, 2.1, back(5,p=square([18,18])));
|
// bent_cutout_mask(r-1, 2.1, back(5,p=square([18,18])));
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
// Example: Adding additional points fixed this problem
|
// Example: Adding additional points fixed this problem
|
||||||
// $fn=128;
|
|
||||||
// r=25;
|
// r=25;
|
||||||
// rot(-90)
|
// rot(-90) {
|
||||||
|
// $fn=128;
|
||||||
// difference(){
|
// difference(){
|
||||||
// tube(or=r, wall=2, h=45);
|
// 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));
|
// 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.
|
// 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;
|
// r=25;
|
||||||
// rot(-90)
|
// rot(-90) {
|
||||||
|
// $fn=128;
|
||||||
// difference(){
|
// difference(){
|
||||||
// tube(or=r, wall=2, h=45);
|
// 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)));
|
// 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.
|
// 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) =
|
// function slot(slotwidth, slotheight, slotradius) = let(
|
||||||
// let( angle = 85,
|
// angle = 85,
|
||||||
// slot = round_corners(
|
// slot = round_corners(
|
||||||
// turtle(["right",
|
// turtle([
|
||||||
|
// "right",
|
||||||
// "move", slotwidth,
|
// "move", slotwidth,
|
||||||
// "left", angle,
|
// "left", angle,
|
||||||
// "move", 2*slotwidth,
|
// "move", 2*slotwidth,
|
||||||
|
@ -1806,40 +1816,46 @@ function _circle_mask(r) =
|
||||||
// "right", angle,
|
// "right", angle,
|
||||||
// "move", 2*slotwidth,
|
// "move", 2*slotwidth,
|
||||||
// "left", angle,
|
// "left", angle,
|
||||||
// "move", slotwidth]),
|
// "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);
|
// 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));
|
// stroke(slot(15,29,7));
|
||||||
// Example: A cylindrical container with rounded edges and a rounded finger slot.
|
// Example: A cylindrical container with rounded edges and a rounded finger slot.
|
||||||
function slot(slotwidth, slotheight, slotradius) =
|
// function slot(slotwidth, slotheight, slotradius) = let(
|
||||||
let( angle = 85,
|
// angle = 85,
|
||||||
slot = round_corners(
|
// slot = round_corners(
|
||||||
turtle(["right",
|
// turtle([
|
||||||
"move", slotwidth,
|
// "right",
|
||||||
"left", angle,
|
// "move", slotwidth,
|
||||||
"move", 2*slotwidth,
|
// "left", angle,
|
||||||
"right", angle,
|
// "move", 2*slotwidth,
|
||||||
"move", slotheight,
|
// "right", angle,
|
||||||
"left",
|
// "move", slotheight,
|
||||||
"move", slotwidth,
|
// "left",
|
||||||
"left",
|
// "move", slotwidth,
|
||||||
"move", slotheight,
|
// "left",
|
||||||
"right", angle,
|
// "move", slotheight,
|
||||||
"move", 2*slotwidth,
|
// "right", angle,
|
||||||
"left", angle,
|
// "move", 2*slotwidth,
|
||||||
"move", slotwidth]),
|
// "left", angle,
|
||||||
measure="radius", size=[0,0,each repeat(slotradius,4),0,0], closed=false))
|
// "move", slotwidth
|
||||||
apply(left(max(subindex(slot,0))/2)*fwd(min(subindex(slot,1))), slot);
|
// ]),
|
||||||
$fn=128;
|
// measure="radius", size=[0,0,each repeat(slotradius,4),0,0], closed=false
|
||||||
diam = 80;
|
// )
|
||||||
wall = 4;
|
// ) apply(left(max(subindex(slot,0))/2)*fwd(min(subindex(slot,1))), slot);
|
||||||
height = 40;
|
// diam = 80;
|
||||||
rot(-90)
|
// wall = 4;
|
||||||
difference(){
|
// height = 40;
|
||||||
cyl(d=diam, rounding=wall/2, h=height, anchor=BOTTOM);
|
// rot(-90) {
|
||||||
up(wall)cyl(d=diam-2*wall, rounding1=wall, rounding2=-wall/2, h=height-wall+.01, anchor=BOTTOM);
|
// $fn=128;
|
||||||
bent_cutout_mask(diam/2-wall/2, wall+.1, subdivide_path(apply(back(10),slot(15, 29, 7)),250));
|
// 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)
|
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
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue