mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-01 14:00:30 +02:00
colors and 2d rounding flee mutators.scad
This commit is contained in:
@@ -1429,4 +1429,75 @@ function reuleaux_polygon(N=3, r, d, anchor=CENTER, spin=0) =
|
||||
) reorient(anchor,spin, two_d=true, path=path, extent=false, anchors=anchors, p=path);
|
||||
|
||||
|
||||
|
||||
// Section: Rounding 2D shapes
|
||||
|
||||
// Module: round2d()
|
||||
// Usage:
|
||||
// round2d(r) ...
|
||||
// round2d(or) ...
|
||||
// round2d(ir) ...
|
||||
// round2d(or, ir) ...
|
||||
// Description:
|
||||
// Rounds arbitrary 2D objects. Giving `r` rounds all concave and convex corners. Giving just `ir`
|
||||
// rounds just concave corners. Giving just `or` rounds convex corners. Giving both `ir` and `or`
|
||||
// can let you round to different radii for concave and convex corners. The 2D object must not have
|
||||
// any parts narrower than twice the `or` radius. Such parts will disappear.
|
||||
// Arguments:
|
||||
// r = Radius to round all concave and convex corners to.
|
||||
// or = Radius to round only outside (convex) corners to. Use instead of `r`.
|
||||
// ir = Radius to round only inside (concave) corners to. Use instead of `r`.
|
||||
// Examples(2D):
|
||||
// round2d(r=10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// round2d(or=10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// round2d(ir=10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// round2d(or=16,ir=8) {square([40,100], center=true); square([100,40], center=true);}
|
||||
module round2d(r, or, ir)
|
||||
{
|
||||
or = get_radius(r1=or, r=r, dflt=0);
|
||||
ir = get_radius(r1=ir, r=r, dflt=0);
|
||||
offset(or) offset(-ir-or) offset(delta=ir,chamfer=true) children();
|
||||
}
|
||||
|
||||
|
||||
// Module: shell2d()
|
||||
// Usage:
|
||||
// shell2d(thickness, [or], [ir], [fill], [round])
|
||||
// Description:
|
||||
// Creates a hollow shell from 2D children, with optional rounding.
|
||||
// Arguments:
|
||||
// thickness = Thickness of the shell. Positive to expand outward, negative to shrink inward, or a two-element list to do both.
|
||||
// or = Radius to round corners on the outside of the shell. If given a list of 2 radii, [CONVEX,CONCAVE], specifies the radii for convex and concave corners separately. Default: 0 (no outside rounding)
|
||||
// ir = Radius to round corners on the inside of the shell. If given a list of 2 radii, [CONVEX,CONCAVE], specifies the radii for convex and concave corners separately. Default: 0 (no inside rounding)
|
||||
// Examples(2D):
|
||||
// shell2d(10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(-10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d([-10,10]) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(10,or=10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(10,ir=10) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(10,or=[10,0]) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(10,or=[0,10]) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(10,ir=[10,0]) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(10,ir=[0,10]) {square([40,100], center=true); square([100,40], center=true);}
|
||||
// shell2d(8,or=[16,8],ir=[16,8]) {square([40,100], center=true); square([100,40], center=true);}
|
||||
module shell2d(thickness, or=0, ir=0)
|
||||
{
|
||||
thickness = is_num(thickness)? (
|
||||
thickness<0? [thickness,0] : [0,thickness]
|
||||
) : (thickness[0]>thickness[1])? (
|
||||
[thickness[1],thickness[0]]
|
||||
) : thickness;
|
||||
orad = is_finite(or)? [or,or] : or;
|
||||
irad = is_finite(ir)? [ir,ir] : ir;
|
||||
difference() {
|
||||
round2d(or=orad[0],ir=orad[1])
|
||||
offset(delta=thickness[1])
|
||||
children();
|
||||
round2d(or=irad[1],ir=irad[0])
|
||||
offset(delta=thickness[0])
|
||||
children();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||
|
Reference in New Issue
Block a user