mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-06 04:09:47 +00:00
Massive speedups for knurling. Added chamfering and rounding options.
This commit is contained in:
parent
c127a2c72e
commit
1020d1d659
1 changed files with 67 additions and 9 deletions
|
@ -30,18 +30,33 @@
|
||||||
// count = The number of grooves to have around the surface of the cylinder. Default: 30
|
// count = The number of grooves to have around the surface of the cylinder. Default: 30
|
||||||
// profile = The angle of the bottom of the groove, in degrees. Default 120
|
// profile = The angle of the bottom of the groove, in degrees. Default 120
|
||||||
// helix = The helical angle of the grooves, in degrees. Default: 30
|
// helix = The helical angle of the grooves, in degrees. Default: 30
|
||||||
|
// chamfer = The size of the chamfers on the ends of the cylinder. Default: none.
|
||||||
|
// chamfer1 = The size of the chamfer on the bottom end of the cylinder. Default: none.
|
||||||
|
// chamfer2 = The size of the chamfer on the top end of the cylinder. Default: none.
|
||||||
|
// chamfang = The angle in degrees of the chamfers on the ends of the cylinder.
|
||||||
|
// chamfang1 = The angle in degrees of the chamfer on the bottom end of the cylinder.
|
||||||
|
// chamfang2 = The angle in degrees of the chamfer on the top end of the cylinder.
|
||||||
|
// from_end = If true, chamfer is measured from the end of the cylinder, instead of inset from the edge. Default: `false`.
|
||||||
|
// rounding = The radius of the rounding on the ends of the cylinder. Default: none.
|
||||||
|
// rounding1 = The radius of the rounding on the bottom end of the cylinder.
|
||||||
|
// rounding2 = The radius of the rounding on the top end of the cylinder.
|
||||||
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
|
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
|
||||||
// spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#spin). Default: `0`
|
// spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#spin). Default: `0`
|
||||||
// orient = Vector to rotate top towards. See [orient](attachments.scad#orient). Default: `UP`
|
// orient = Vector to rotate top towards. See [orient](attachments.scad#orient). Default: `UP`
|
||||||
// Examples:
|
// Examples:
|
||||||
// knurled_cylinder(l=30, r=20, profile=120, helix=45);
|
// knurled_cylinder(l=30, r=20, count=30, profile=120, helix=45);
|
||||||
// knurled_cylinder(l=30, r=20, profile=120, helix=30);
|
// knurled_cylinder(l=30, r=20, count=30, profile=120, helix=30);
|
||||||
// knurled_cylinder(l=30, r=20, profile=90, helix=30);
|
// knurled_cylinder(l=30, r=20, count=30, profile=90, helix=30);
|
||||||
|
// knurled_cylinder(l=30, r=20, count=20, profile=120, helix=30);
|
||||||
module knurled_cylinder(
|
module knurled_cylinder(
|
||||||
l=20,
|
l=20,
|
||||||
r=undef, r1=undef, r2=undef,
|
r=undef, r1=undef, r2=undef,
|
||||||
d=undef, d1=undef, d2=undef,
|
d=undef, d1=undef, d2=undef,
|
||||||
count=30, profile=120, helix=30,
|
count=30, profile=120, helix=30,
|
||||||
|
chamfer=undef, chamfer1=undef, chamfer2=undef,
|
||||||
|
chamfang=undef, chamfang1=undef, chamfang2=undef,
|
||||||
|
from_end=false,
|
||||||
|
rounding=undef, rounding1=undef, rounding2=undef,
|
||||||
anchor=CENTER, spin=0, orient=UP
|
anchor=CENTER, spin=0, orient=UP
|
||||||
) {
|
) {
|
||||||
r1 = get_radius(r1=r1,r=r,d1=d1,d=d,dflt=10);
|
r1 = get_radius(r1=r1,r=r,d1=d1,d=d,dflt=10);
|
||||||
|
@ -53,14 +68,57 @@ module knurled_cylinder(
|
||||||
path = [for (i=idx(c1)) each [c1[i],c2[i]]];
|
path = [for (i=idx(c1)) each [c1[i],c2[i]]];
|
||||||
knob_w = 2*PI*r1/count;
|
knob_w = 2*PI*r1/count;
|
||||||
knob_h = knob_w / tan(helix);
|
knob_h = knob_w / tan(helix);
|
||||||
|
layers = ceil(l/knob_h);
|
||||||
|
plen = len(path);
|
||||||
|
vertices = concat(
|
||||||
|
[
|
||||||
|
for (layer = [0:1:layers], pt=path)
|
||||||
|
(layer%2)? [pt.x, pt.y, layer*knob_h-layers*knob_h/2] :
|
||||||
|
rot(180/count, p=[pt.x, pt.y, layer*knob_h-layers*knob_h/2])
|
||||||
|
], [
|
||||||
|
[0,0,-layers*knob_h/2],
|
||||||
|
[0,0, layers*knob_h/2]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
faces = concat(
|
||||||
|
[
|
||||||
|
for (layer = [0:1:layers-1], i=idx(path)) let(
|
||||||
|
loff = (layer%2)? 2 : 0,
|
||||||
|
i1 = layer*plen+i,
|
||||||
|
i2 = layer*plen+((i+1)%plen),
|
||||||
|
i3 = (layer+1)*plen+posmod(i+0+loff,plen),
|
||||||
|
i4 = (layer+1)*plen+posmod(i+1+loff,plen),
|
||||||
|
i5 = (layer+1)*plen+posmod(i-1+loff,plen),
|
||||||
|
i6 = (layer+1)*plen+posmod(i-2+loff,plen)
|
||||||
|
) each [
|
||||||
|
[i1, i2, ((i%2)? i5 : i3)],
|
||||||
|
[i3, i5, ((i%2)? i2 : i1)]
|
||||||
|
]
|
||||||
|
], [
|
||||||
|
for (i=[0:1:count-1]) let(
|
||||||
|
i1 = posmod(i*2+1,plen),
|
||||||
|
i2 = posmod(i*2+2,plen),
|
||||||
|
i3 = posmod(i*2+3,plen),
|
||||||
|
loff = layers*plen
|
||||||
|
) each [
|
||||||
|
[i1,i3,i2],
|
||||||
|
[i1+loff,i2+loff,i3+loff],
|
||||||
|
[i3,i1,len(vertices)-2],
|
||||||
|
[i1+loff,i3+loff,len(vertices)-1]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
orient_and_anchor([2*r1,2*r1,l], size2=[2*r2,2*r2], anchor=anchor, spin=spin, orient=orient, geometry="cylinder", chain=true) {
|
orient_and_anchor([2*r1,2*r1,l], size2=[2*r2,2*r2], anchor=anchor, spin=spin, orient=orient, geometry="cylinder", chain=true) {
|
||||||
intersection() {
|
intersection() {
|
||||||
linear_extrude(height=l, center=true, convexity=10, twist=twist, scale=r2/r1, slices=l/knob_h*2) {
|
polyhedron(points=vertices, faces=faces, convexity=2*layers);
|
||||||
polygon(path);
|
cyl(
|
||||||
}
|
r1=r1, r2=r2, l=l,
|
||||||
linear_extrude(height=l, center=true, convexity=10, twist=-twist, scale=r2/r1, slices=l/knob_h*2) {
|
chamfer=chamfer, chamfer1=chamfer1, chamfer2=chamfer2,
|
||||||
polygon(path);
|
chamfang=chamfang, chamfang1=chamfang1, chamfang2=chamfang2,
|
||||||
}
|
from_end=from_end,
|
||||||
|
rounding=rounding, rounding1=rounding1, rounding2=rounding2,
|
||||||
|
$fn=count*2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
children();
|
children();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue