mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-04 03:09:45 +00:00
Added rounding= option to various 2D Ngons.
This commit is contained in:
parent
5a9d15c1a5
commit
ab66cb5788
2 changed files with 31 additions and 16 deletions
|
@ -582,6 +582,7 @@ function _turtle_command(command, parm, parm2, state, index) =
|
||||||
// ir = Inside radius, at center of sides.
|
// ir = Inside radius, at center of sides.
|
||||||
// id = Inside diameter, at center of sides.
|
// id = Inside diameter, at center of sides.
|
||||||
// side = Length of each side.
|
// side = Length of each side.
|
||||||
|
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
|
||||||
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
||||||
// 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 after anchor. See [spin](attachments.scad#spin). Default: `0`
|
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
|
||||||
|
@ -597,15 +598,26 @@ function _turtle_command(command, parm, parm2, state, index) =
|
||||||
// regular_ngon(n=8, side=20, realign=true);
|
// regular_ngon(n=8, side=20, realign=true);
|
||||||
// Example(2D): Called as Function
|
// Example(2D): Called as Function
|
||||||
// stroke(closed=true, regular_ngon(n=6, or=30));
|
// stroke(closed=true, regular_ngon(n=6, or=30));
|
||||||
function regular_ngon(n=6, r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0) =
|
function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
|
||||||
let(
|
let(
|
||||||
sc = 1/cos(180/n),
|
sc = 1/cos(180/n),
|
||||||
r = get_radius(r1=ir*sc, r2=or, r=r, d1=id*sc, d2=od, d=d, dflt=side/2/sin(180/n)),
|
r = get_radius(r1=ir*sc, r2=or, r=r, d1=id*sc, d2=od, d=d, dflt=side/2/sin(180/n)),
|
||||||
path = circle(r=r, realign=realign, spin=90, $fn=n)
|
path = rounding==0? circle(r=r, realign=realign, spin=90, $fn=n) :
|
||||||
|
let(
|
||||||
|
steps = floor(segs(r)/n),
|
||||||
|
step = 360/n/steps
|
||||||
|
) [
|
||||||
|
for (i=[0:1:n-1], j=[0:1:steps]) let(
|
||||||
|
a = 90 - (realign? 180/n : 0) - i*360/n,
|
||||||
|
b = a + 180/n - j*step
|
||||||
|
)
|
||||||
|
(r-rounding*sc)*[cos(a),sin(a)] +
|
||||||
|
rounding*[cos(b),sin(b)]
|
||||||
|
]
|
||||||
) rot(spin, p=move(-r*normalize(anchor), p=path));
|
) rot(spin, p=move(-r*normalize(anchor), p=path));
|
||||||
|
|
||||||
|
|
||||||
module regular_ngon(n=6, r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0) {
|
module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) {
|
||||||
sc = 1/cos(180/n);
|
sc = 1/cos(180/n);
|
||||||
r = get_radius(r1=ir*sc, r2=or, r=r, d1=id*sc, d2=od, d=d, dflt=side/2/sin(180/n));
|
r = get_radius(r1=ir*sc, r2=or, r=r, d1=id*sc, d2=od, d=d, dflt=side/2/sin(180/n));
|
||||||
orient_and_anchor([2*r,2*r,0], UP, anchor, spin=spin, geometry="cylinder", two_d=true, chain=true) {
|
orient_and_anchor([2*r,2*r,0], UP, anchor, spin=spin, geometry="cylinder", two_d=true, chain=true) {
|
||||||
|
@ -631,6 +643,7 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, realign=false, anchor=CENTE
|
||||||
// ir = Inside radius, at center of sides.
|
// ir = Inside radius, at center of sides.
|
||||||
// id = Inside diameter, at center of sides.
|
// id = Inside diameter, at center of sides.
|
||||||
// side = Length of each side.
|
// side = Length of each side.
|
||||||
|
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
|
||||||
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
||||||
// 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 after anchor. See [spin](attachments.scad#spin). Default: `0`
|
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
|
||||||
|
@ -646,12 +659,12 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, realign=false, anchor=CENTE
|
||||||
// pentagon(side=20, realign=true);
|
// pentagon(side=20, realign=true);
|
||||||
// Example(2D): Called as Function
|
// Example(2D): Called as Function
|
||||||
// stroke(closed=true, pentagon(or=30));
|
// stroke(closed=true, pentagon(or=30));
|
||||||
function pentagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0) =
|
function pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
|
||||||
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, realign=realign, anchor=anchor, spin=spin);
|
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin);
|
||||||
|
|
||||||
|
|
||||||
module pentagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0)
|
module pentagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0)
|
||||||
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, realign=realign, anchor=anchor, spin=spin) children();
|
regular_ngon(n=5, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin) children();
|
||||||
|
|
||||||
|
|
||||||
// Function&Module: hexagon()
|
// Function&Module: hexagon()
|
||||||
|
@ -668,6 +681,7 @@ module pentagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0
|
||||||
// ir = Inside radius, at center of sides.
|
// ir = Inside radius, at center of sides.
|
||||||
// id = Inside diameter, at center of sides.
|
// id = Inside diameter, at center of sides.
|
||||||
// side = Length of each side.
|
// side = Length of each side.
|
||||||
|
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
|
||||||
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
||||||
// 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 after anchor. See [spin](attachments.scad#spin). Default: `0`
|
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
|
||||||
|
@ -683,12 +697,12 @@ module pentagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0
|
||||||
// hexagon(side=20, realign=true);
|
// hexagon(side=20, realign=true);
|
||||||
// Example(2D): Called as Function
|
// Example(2D): Called as Function
|
||||||
// stroke(closed=true, hexagon(or=30));
|
// stroke(closed=true, hexagon(or=30));
|
||||||
function hexagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0) =
|
function hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
|
||||||
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, realign=realign, anchor=anchor, spin=spin);
|
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin);
|
||||||
|
|
||||||
|
|
||||||
module hexagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0)
|
module hexagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0)
|
||||||
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, realign=realign, anchor=anchor, spin=spin) children();
|
regular_ngon(n=6, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin) children();
|
||||||
|
|
||||||
|
|
||||||
// Function&Module: octagon()
|
// Function&Module: octagon()
|
||||||
|
@ -705,6 +719,7 @@ module hexagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0)
|
||||||
// ir = Inside radius, at center of sides.
|
// ir = Inside radius, at center of sides.
|
||||||
// id = Inside diameter, at center of sides.
|
// id = Inside diameter, at center of sides.
|
||||||
// side = Length of each side.
|
// side = Length of each side.
|
||||||
|
// rounding = Radius of rounding for the tips of the polygon. Default: 0 (no rounding)
|
||||||
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
// realign = If false, a tip is aligned with the Y+ axis. If true, the midpoint of a side is aligned with the Y+ axis. Default: false
|
||||||
// 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 after anchor. See [spin](attachments.scad#spin). Default: `0`
|
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
|
||||||
|
@ -720,12 +735,12 @@ module hexagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0)
|
||||||
// octagon(side=20, realign=true);
|
// octagon(side=20, realign=true);
|
||||||
// Example(2D): Called as Function
|
// Example(2D): Called as Function
|
||||||
// stroke(closed=true, octagon(or=30));
|
// stroke(closed=true, octagon(or=30));
|
||||||
function octagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0) =
|
function octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) =
|
||||||
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, realign=realign, anchor=anchor, spin=spin);
|
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin);
|
||||||
|
|
||||||
|
|
||||||
module octagon(r, d, or, od, ir, id, side, realign=false, anchor=CENTER, spin=0)
|
module octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0)
|
||||||
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, realign=realign, anchor=anchor, spin=spin) children();
|
regular_ngon(n=8, r=r, d=d, or=or, od=od, ir=ir, id=id, side=side, rounding=rounding, realign=realign, anchor=anchor, spin=spin) children();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,84];
|
BOSL_VERSION = [2,0,85];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue