mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Added teardrop= to cyl()
This commit is contained in:
parent
737bd9aac8
commit
062c172716
2 changed files with 40 additions and 5 deletions
|
@ -665,8 +665,8 @@ module dashed_stroke(path, dashpat=[3,3], width=1, closed=false, fit=true, round
|
||||||
// Section: Computing paths
|
// Section: Computing paths
|
||||||
|
|
||||||
// Function&Module: arc()
|
// Function&Module: arc()
|
||||||
// Synopsis: Draws a 2d pie-slice or returns 2D or 3D path forming an arc.
|
// Synopsis: Draws a 2D pie-slice or returns 2D or 3D path forming an arc.
|
||||||
// Topics: Shapes (2D), Path Generators (2D)
|
// Topics: Paths (2D), Paths (3D), Shapes (2D), Path Generators
|
||||||
//
|
//
|
||||||
// Usage: 2D arc from 0º to `angle` degrees.
|
// Usage: 2D arc from 0º to `angle` degrees.
|
||||||
// path=arc(n, r|d=, angle);
|
// path=arc(n, r|d=, angle);
|
||||||
|
@ -684,7 +684,6 @@ module dashed_stroke(path, dashpat=[3,3], width=1, closed=false, fit=true, round
|
||||||
// path=arc(n, corner=[P0,P1,P2], r=);
|
// path=arc(n, corner=[P0,P1,P2], r=);
|
||||||
// Usage: as module
|
// Usage: as module
|
||||||
// arc(...) [ATTACHMENTS];
|
// arc(...) [ATTACHMENTS];
|
||||||
// Topics: Paths (2D), Paths (3D), Shapes (2D), Path Generators
|
|
||||||
// Description:
|
// Description:
|
||||||
// If called as a function, returns a 2D or 3D path forming an arc.
|
// If called as a function, returns a 2D or 3D path forming an arc.
|
||||||
// If called as a module, creates a 2D arc polygon or pie slice shape.
|
// If called as a module, creates a 2D arc polygon or pie slice shape.
|
||||||
|
|
|
@ -604,7 +604,7 @@ function cuboid(
|
||||||
// chamfer = The chamfer size for the vertical-ish edges of the prismoid. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. Default: 0 (no chamfer)
|
// chamfer = The chamfer size for the vertical-ish edges of the prismoid. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. Default: 0 (no chamfer)
|
||||||
// chamfer1 = The chamfer size for the bottom of the vertical-ish edges of the prismoid. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
|
// chamfer1 = The chamfer size for the bottom of the vertical-ish edges of the prismoid. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
|
||||||
// chamfer2 = The chamfer size for the top of the vertical-ish edges of the prismoid. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
|
// chamfer2 = The chamfer size for the top of the vertical-ish edges of the prismoid. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
|
||||||
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
|
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `BOTTOM`
|
||||||
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
|
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
|
||||||
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
|
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
|
||||||
//
|
//
|
||||||
|
@ -1286,6 +1286,8 @@ function cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP) =
|
||||||
// cyl(l|h|length|height, r1=, r2=, texture=, [tex_size=]|[tex_counts=], [tex_scale=], [tex_rot=], [tex_samples=], [tex_style=], [tex_taper=], [tex_inset=], ...);
|
// cyl(l|h|length|height, r1=, r2=, texture=, [tex_size=]|[tex_counts=], [tex_scale=], [tex_rot=], [tex_samples=], [tex_style=], [tex_taper=], [tex_inset=], ...);
|
||||||
// cyl(l|h|length|height, d1=, d2=, texture=, [tex_size=]|[tex_counts=], [tex_scale=], [tex_rot=], [tex_samples=], [tex_style=], [tex_taper=], [tex_inset=], ...);
|
// cyl(l|h|length|height, d1=, d2=, texture=, [tex_size=]|[tex_counts=], [tex_scale=], [tex_rot=], [tex_samples=], [tex_style=], [tex_taper=], [tex_inset=], ...);
|
||||||
//
|
//
|
||||||
|
// Usage: Caled as a function to get a VNF
|
||||||
|
// vnf = cyl(...);
|
||||||
//
|
//
|
||||||
// Description:
|
// Description:
|
||||||
// Creates cylinders in various anchorings and orientations, with optional rounding, chamfers, or textures.
|
// Creates cylinders in various anchorings and orientations, with optional rounding, chamfers, or textures.
|
||||||
|
@ -1348,6 +1350,7 @@ function cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP) =
|
||||||
// rounding1 = The radius of the rounding on the bottom end of the cylinder.
|
// 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.
|
// rounding2 = The radius of the rounding on the top end of the cylinder.
|
||||||
// realign = If true, rotate the cylinder by half the angle of one face.
|
// realign = If true, rotate the cylinder by half the angle of one face.
|
||||||
|
// teardrop = If given as a number, rounding around the bottom edge of the cylinder won't exceed this many degrees from vertical. If true, the limit angle is 45 degrees. Default: `false`
|
||||||
// texture = A texture name string, or a rectangular array of scalar height values (0.0 to 1.0), or a VNF tile that defines the texture to apply to vertical surfaces. See {{texture()}} for what named textures are supported.
|
// texture = A texture name string, or a rectangular array of scalar height values (0.0 to 1.0), or a VNF tile that defines the texture to apply to vertical surfaces. See {{texture()}} for what named textures are supported.
|
||||||
// tex_size = An optional 2D target size for the textures. Actual texture sizes will be scaled somewhat to evenly fit the available surface. Default: `[5,5]`
|
// tex_size = An optional 2D target size for the textures. Actual texture sizes will be scaled somewhat to evenly fit the available surface. Default: `[5,5]`
|
||||||
// tex_counts = If given instead of tex_size, gives the tile repetition counts for textures over the surface length and height.
|
// tex_counts = If given instead of tex_size, gives the tile repetition counts for textures over the surface length and height.
|
||||||
|
@ -1385,6 +1388,9 @@ function cylinder(h, r1, r2, center, r, d, d1, d2, anchor, spin=0, orient=UP) =
|
||||||
// Example: Rounding
|
// Example: Rounding
|
||||||
// cyl(l=40, d=40, rounding=10);
|
// cyl(l=40, d=40, rounding=10);
|
||||||
//
|
//
|
||||||
|
// Example: Teardrop Bottom Rounding
|
||||||
|
// cyl(l=40, d=40, rounding=10, teardrop=true);
|
||||||
|
//
|
||||||
// Example: Heterogenous Chamfers and Rounding
|
// Example: Heterogenous Chamfers and Rounding
|
||||||
// ydistribute(80) {
|
// ydistribute(80) {
|
||||||
// // Shown Front to Back.
|
// // Shown Front to Back.
|
||||||
|
@ -1490,6 +1496,7 @@ function cyl(
|
||||||
chamfang, chamfang1, chamfang2,
|
chamfang, chamfang1, chamfang2,
|
||||||
rounding, rounding1, rounding2,
|
rounding, rounding1, rounding2,
|
||||||
circum=false, realign=false, shift=[0,0],
|
circum=false, realign=false, shift=[0,0],
|
||||||
|
teardrop=false,
|
||||||
from_end, from_end1, from_end2,
|
from_end, from_end1, from_end2,
|
||||||
texture, tex_size=[5,5], tex_counts,
|
texture, tex_size=[5,5], tex_counts,
|
||||||
tex_inset=false, tex_rot=false,
|
tex_inset=false, tex_rot=false,
|
||||||
|
@ -1559,6 +1566,12 @@ function cyl(
|
||||||
dy1 = abs(_chamf1 ? chamf1l : round1 ? roundlen1 : 0),
|
dy1 = abs(_chamf1 ? chamf1l : round1 ? roundlen1 : 0),
|
||||||
dy2 = abs(_chamf2 ? chamf2l : round2 ? roundlen2 : 0),
|
dy2 = abs(_chamf2 ? chamf2l : round2 ? roundlen2 : 0),
|
||||||
|
|
||||||
|
teardrop = teardrop == true? 45 :
|
||||||
|
teardrop == false? 90 :
|
||||||
|
assert(is_finite(teardrop))
|
||||||
|
assert(teardrop>=0 && teardrop<=90)
|
||||||
|
teardrop,
|
||||||
|
|
||||||
checks2 =
|
checks2 =
|
||||||
assert(is_finite(round1), "rounding1 must be a number if given.")
|
assert(is_finite(round1), "rounding1 must be a number if given.")
|
||||||
assert(is_finite(round2), "rounding2 must be a number if given.")
|
assert(is_finite(round2), "rounding2 must be a number if given.")
|
||||||
|
@ -1570,14 +1583,18 @@ function cyl(
|
||||||
undef,
|
undef,
|
||||||
path = [
|
path = [
|
||||||
if (texture==undef) [0,-l/2],
|
if (texture==undef) [0,-l/2],
|
||||||
|
|
||||||
if (!approx(chamf1r,0))
|
if (!approx(chamf1r,0))
|
||||||
each [
|
each [
|
||||||
[r1, -l/2] + polar_to_xy(chamf1r,180),
|
[r1, -l/2] + polar_to_xy(chamf1r,180),
|
||||||
[r1, -l/2] + polar_to_xy(chamf1l,90+vang),
|
[r1, -l/2] + polar_to_xy(chamf1l,90+vang),
|
||||||
]
|
]
|
||||||
else if (!approx(round1,0))
|
else if (!approx(round1,0) && teardrop < 90)
|
||||||
|
each _teardrop_corner(corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]], r=abs(round1), teardrop)
|
||||||
|
else if (!approx(round1,0) && teardrop >= 90)
|
||||||
each arc(r=abs(round1), corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]])
|
each arc(r=abs(round1), corner=[[max(0,r1-2*roundlen1),-l/2],[r1,-l/2],[r2,l/2]])
|
||||||
else [r1,-l/2],
|
else [r1,-l/2],
|
||||||
|
|
||||||
if (is_finite(chamf2r) && !approx(chamf2r,0))
|
if (is_finite(chamf2r) && !approx(chamf2r,0))
|
||||||
each [
|
each [
|
||||||
[r2, l/2] + polar_to_xy(chamf2l,270+vang),
|
[r2, l/2] + polar_to_xy(chamf2l,270+vang),
|
||||||
|
@ -1586,6 +1603,7 @@ function cyl(
|
||||||
else if (is_finite(round2) && !approx(round2,0))
|
else if (is_finite(round2) && !approx(round2,0))
|
||||||
each arc(r=abs(round2), corner=[[r1,-l/2],[r2,l/2],[max(0,r2-2*roundlen2),l/2]])
|
each arc(r=abs(round2), corner=[[r1,-l/2],[r2,l/2],[max(0,r2-2*roundlen2),l/2]])
|
||||||
else [r2,l/2],
|
else [r2,l/2],
|
||||||
|
|
||||||
if (texture==undef) [0,l/2],
|
if (texture==undef) [0,l/2],
|
||||||
]
|
]
|
||||||
) rotate_sweep(path,
|
) rotate_sweep(path,
|
||||||
|
@ -1603,6 +1621,22 @@ function cyl(
|
||||||
reorient(anchor,spin,orient, r1=r1, r2=r2, l=l, shift=shift, p=ovnf);
|
reorient(anchor,spin,orient, r1=r1, r2=r2, l=l, shift=shift, p=ovnf);
|
||||||
|
|
||||||
|
|
||||||
|
function _teardrop_corner(corner, r, ang=45) =
|
||||||
|
let(
|
||||||
|
cp = circle_2tangents(r, corner)[0],
|
||||||
|
path1 = arc(r=r, corner=corner),
|
||||||
|
path2 = [
|
||||||
|
for (p = select(path1,0,-2))
|
||||||
|
if (v_theta(p-cp) >= -ang) p,
|
||||||
|
last(path1)
|
||||||
|
],
|
||||||
|
path = [
|
||||||
|
line_intersection([corner[0],corner[1]],[path2[0],path2[0]+polar_to_xy(1,-90-ang)]),
|
||||||
|
each path2
|
||||||
|
]
|
||||||
|
) path;
|
||||||
|
|
||||||
|
|
||||||
module cyl(
|
module cyl(
|
||||||
h, r, center,
|
h, r, center,
|
||||||
l, r1, r2,
|
l, r1, r2,
|
||||||
|
@ -1611,6 +1645,7 @@ module cyl(
|
||||||
chamfang, chamfang1, chamfang2,
|
chamfang, chamfang1, chamfang2,
|
||||||
rounding, rounding1, rounding2,
|
rounding, rounding1, rounding2,
|
||||||
circum=false, realign=false, shift=[0,0],
|
circum=false, realign=false, shift=[0,0],
|
||||||
|
teardrop=false,
|
||||||
from_end, from_end1, from_end2,
|
from_end, from_end1, from_end2,
|
||||||
texture, tex_size=[5,5], tex_counts,
|
texture, tex_size=[5,5], tex_counts,
|
||||||
tex_inset=false, tex_rot=false,
|
tex_inset=false, tex_rot=false,
|
||||||
|
@ -1640,6 +1675,7 @@ module cyl(
|
||||||
chamfang=chamfang, chamfang1=chamfang1, chamfang2=chamfang2,
|
chamfang=chamfang, chamfang1=chamfang1, chamfang2=chamfang2,
|
||||||
rounding=rounding, rounding1=rounding1, rounding2=rounding2,
|
rounding=rounding, rounding1=rounding1, rounding2=rounding2,
|
||||||
from_end=from_end, from_end1=from_end1, from_end2=from_end2,
|
from_end=from_end, from_end1=from_end1, from_end2=from_end2,
|
||||||
|
teardrop=teardrop,
|
||||||
texture=texture, tex_size=tex_size,
|
texture=texture, tex_size=tex_size,
|
||||||
tex_counts=tex_counts, tex_scale=tex_scale,
|
tex_counts=tex_counts, tex_scale=tex_scale,
|
||||||
tex_inset=tex_inset, tex_rot=tex_rot,
|
tex_inset=tex_inset, tex_rot=tex_rot,
|
||||||
|
|
Loading…
Reference in a new issue