This commit is contained in:
Adrian Mariano 2020-12-11 19:01:40 -05:00
commit 00415796ba
5 changed files with 194 additions and 4 deletions

View file

@ -171,7 +171,11 @@ module line_of(spacing, n, l, p1, p2)
module xcopies(spacing, n, l, sp)
{
sp = is_finite(sp)? [sp,0,0] : sp;
line_of(l=l*RIGHT, spacing=spacing*RIGHT, n=n, p1=sp) children();
line_of(
l=u_mul(l,RIGHT),
spacing=u_mul(spacing,RIGHT),
n=n, p1=sp
) children();
}
@ -207,7 +211,11 @@ module xcopies(spacing, n, l, sp)
module ycopies(spacing, n, l, sp)
{
sp = is_finite(sp)? [0,sp,0] : sp;
line_of(l=l*BACK, spacing=spacing*BACK, n=n, p1=sp) children();
line_of(
l=u_mul(l,BACK),
spacing=u_mul(spacing,BACK),
n=n, p1=sp
) children();
}
@ -243,7 +251,11 @@ module ycopies(spacing, n, l, sp)
module zcopies(spacing, n, l, sp)
{
sp = is_finite(sp)? [0,0,sp] : sp;
line_of(l=l*UP, spacing=spacing*UP, n=n, p1=sp) children();
line_of(
l=u_mul(l,UP),
spacing=u_mul(spacing,UP),
n=n, p1=sp
) children();
}

53
examples/BOSL2logo.scad Normal file
View file

@ -0,0 +1,53 @@
include <BOSL2/std.scad>
include <BOSL2/involute_gears.scad>
include <BOSL2/beziers.scad>
include <BOSL2/screws.scad>
include <BOSL2/cubetruss.scad>
$fa=1;
$fs=1;
xdistribute(50) {
recolor("#f77")
diff("hole")
cuboid([45,45,10], chamfer=10, edges=[RIGHT+BACK,RIGHT+FRONT], anchor=FRONT) {
cuboid([30,30,11], chamfer=5, edges=[RIGHT+BACK,RIGHT+FRONT], $tags="hole");
attach(FRONT,BACK, overlap=5) {
diff("hole")
cuboid([45,45,10], rounding=15, edges=[RIGHT+BACK,RIGHT+FRONT]) {
cuboid([30,30,11], rounding=10, edges=[RIGHT+BACK,RIGHT+FRONT], $tags="hole");
}
}
}
recolor("#7f7")
bevel_gear(pitch=8, teeth=20, face_width=12, shaft_diam=25, pitch_angle=45, slices=12, spiral_angle=30);
x = 18;
y = 20;
s1 = 25;
s2 = 20;
sbez = [
[-x,-y], [-x,-y-s1],
[ x,-y-s1], [ x,-y], [ x,-y+s2],
[-x, y-s2], [-x, y], [-x, y+s1],
[ x, y+s1], [ x, y]
];
recolor("#99f")
path_sweep(regular_ngon(n=3,d=10,spin=90), bezier_path(sbez));
recolor("#0bf")
translate([-15,-35,0])
cubetruss_corner(size=10, strut=1, h=1, bracing=false, extents=[3,8,0,0,0], clipthick=0);
recolor("#777")
xdistribute(24) {
screw("M12,70", head="hex", anchor="origin", orient=BACK)
attach(BOT,CENTER)
nut("M12", thickness=10, diameter=20, details=true);
screw("M12,70", head="hex", anchor="origin", orient=BACK)
attach(BOT,CENTER)
nut("M12", thickness=10, diameter=20, details=true);
}
}

View file

@ -169,6 +169,63 @@ function lerp(a,b,u) =
// Section: Undef Safe Math
// Function: u_add()
// Usage:
// x = u_add(a, b);
// Description:
// Adds `a` to `b`, returning the result, or undef if either value is `undef`.
// This emulates the way undefs used to be handled in versions of OpenSCAD before 2020.
// Arguments:
// a = First value.
// b = Second value.
function u_add(a,b) = is_undef(a) || is_undef(b)? undef : a + b;
// Function: u_sub()
// Usage:
// x = u_sub(a, b);
// Description:
// Subtracts `b` from `a`, returning the result, or undef if either value is `undef`.
// This emulates the way undefs used to be handled in versions of OpenSCAD before 2020.
// Arguments:
// a = First value.
// b = Second value.
function u_sub(a,b) = is_undef(a) || is_undef(b)? undef : a - b;
// Function: u_mul()
// Usage:
// x = u_mul(a, b);
// Description:
// Multiplies `a` by `b`, returning the result, or undef if either value is `undef`.
// This emulates the way undefs used to be handled in versions of OpenSCAD before 2020.
// Arguments:
// a = First value.
// b = Second value.
function u_mul(a,b) =
is_undef(a) || is_undef(b)? undef :
is_vector(a) && is_vector(b)? vmul(a,b) :
a * b;
// Function: u_div()
// Usage:
// x = u_div(a, b);
// Description:
// Divides `a` by `b`, returning the result, or undef if either value is `undef`.
// This emulates the way undefs used to be handled in versions of OpenSCAD before 2020.
// Arguments:
// a = First value.
// b = Second value.
function u_div(a,b) =
is_undef(a) || is_undef(b)? undef :
is_vector(a) && is_vector(b)? vdiv(a,b) :
a / b;
// Section: Hyperbolic Trigonometry
// Function: sinh()

View file

@ -382,6 +382,74 @@ module test_lerp() {
test_lerp();
module test_u_add() {
assert_equal(u_add(1,2),3);
assert_equal(u_add(1,-2),-1);
assert_equal(u_add(-1,2),1);
assert_equal(u_add(-1,-2),-3);
assert_equal(u_add(243,-27),216);
assert_equal(u_add([2,3,4],[8,7,9]),[10,10,13]);
assert_equal(u_add(undef,27),undef);
assert_equal(u_add(undef,-27),undef);
assert_equal(u_add(243,undef),undef);
assert_equal(u_add(-43,undef),undef);
assert_equal(u_add(undef,[8,7,9]),undef);
assert_equal(u_add([2,3,4],undef),undef);
}
test_u_add();
module test_u_sub() {
assert_equal(u_sub(1,2),-1);
assert_equal(u_sub(1,-2),3);
assert_equal(u_sub(-1,2),-3);
assert_equal(u_sub(-1,-2),1);
assert_equal(u_sub(243,-27),270);
assert_equal(u_sub([2,3,4],[8,7,9]),[-6,-4,-5]);
assert_equal(u_sub(undef,27),undef);
assert_equal(u_sub(undef,-27),undef);
assert_equal(u_sub(243,undef),undef);
assert_equal(u_sub(-43,undef),undef);
assert_equal(u_sub(undef,[8,7,9]),undef);
assert_equal(u_sub([2,3,4],undef),undef);
}
test_u_sub();
module test_u_mul() {
assert_equal(u_mul(3,2),6);
assert_equal(u_mul(3,-2),-6);
assert_equal(u_mul(-3,2),-6);
assert_equal(u_mul(-3,-2),6);
assert_equal(u_mul(243,-27),-6561);
assert_equal(u_mul([2,3,4],[8,7,9]),[16,21,36]);
assert_equal(u_mul(undef,27),undef);
assert_equal(u_mul(undef,-27),undef);
assert_equal(u_mul(243,undef),undef);
assert_equal(u_mul(-43,undef),undef);
assert_equal(u_mul(undef,[8,7,9]),undef);
assert_equal(u_mul([2,3,4],undef),undef);
}
test_u_mul();
module test_u_div() {
assert_equal(u_div(1,2),1/2);
assert_equal(u_div(1,-2),-1/2);
assert_equal(u_div(-1,2),-1/2);
assert_equal(u_div(-1,-2),1/2);
assert_equal(u_div(243,-27),-9);
assert_equal(u_div([8,7,9],[2,3,4]),[4,7/3,9/4]);
assert_equal(u_div(undef,27),undef);
assert_equal(u_div(undef,-27),undef);
assert_equal(u_div(243,undef),undef);
assert_equal(u_div(-43,undef),undef);
assert_equal(u_div(undef,[8,7,9]),undef);
assert_equal(u_div([2,3,4],undef),undef);
}
test_u_div();
module test_hypot() {
assert_approx(hypot(20,30), norm([20,30]));
}

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,474];
BOSL_VERSION = [2,0,476];
// Section: BOSL Library Version Functions