Reworked orientation to use vectors. Added spin.

This commit is contained in:
Revar Desmera
2019-05-25 23:31:05 -07:00
parent d236fbf640
commit 16919f39c3
25 changed files with 978 additions and 768 deletions

View File

@@ -23,18 +23,19 @@
// a = Overhang angle of the joiner.
// clearance = Extra width to clear.
// overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Example:
// half_joiner_clear(orient=ORIENT_X);
module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, anchor=CENTER)
// half_joiner_clear(spin=-90);
module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP)
{
dmnd_height = h*1.0;
dmnd_width = dmnd_height*tan(a);
guide_size = w/3;
guide_width = 2*(dmnd_height/2-guide_size)*tan(a);
orient_and_anchor([w, guide_width, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w, guide_width, h], orient, anchor, spin=spin) {
union() {
yspread(overlap, n=overlap>0? 2 : 1) {
difference() {
@@ -68,11 +69,12 @@ module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, orient=ORI
// screwsize = Diameter of screwhole.
// guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Example:
// half_joiner(screwsize=3, orient=ORIENT_X);
module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, anchor=CENTER)
// half_joiner(screwsize=3, spin=-90);
module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, anchor=CENTER, spin=0, orient=UP)
{
dmnd_height = h*1.0;
dmnd_width = dmnd_height*tan(a);
@@ -82,11 +84,11 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PR
if ($children > 0) {
difference() {
children();
half_joiner_clear(h=h, w=w, a=a, clearance=0.1, overlap=0.01, orient=orient, anchor=anchor);
half_joiner_clear(h=h, w=w, a=a, clearance=0.1, overlap=0.01, anchor=anchor, spin=spin, orient=orient);
}
}
render(convexity=12)
orient_and_anchor([w, 2*l, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w, 2*l, h], orient, anchor, spin=spin) {
difference() {
union() {
// Make base.
@@ -134,7 +136,7 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PR
}
}
}
//half_joiner(screwsize=3, orient=ORIENT_Z, anchor=UP);
//half_joiner(screwsize=3);
@@ -150,11 +152,12 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PR
// a = Overhang angle of the half_joiner.
// screwsize = Diameter of screwhole.
// guides = If true, create sliding alignment guides.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Example:
// half_joiner2(screwsize=3, orient=ORIENT_X);
module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, orient=ORIENT_Y, anchor=CENTER)
// half_joiner2(screwsize=3, spin=-90);
module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP)
{
dmnd_height = h*1.0;
dmnd_width = dmnd_height*tan(a);
@@ -164,12 +167,12 @@ module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, orient
if ($children > 0) {
difference() {
children();
half_joiner_clear(h=h, w=w, a=a, clearance=0.1, overlap=0.01, orient=orient, anchor=anchor);
half_joiner_clear(h=h, w=w, a=a, clearance=0.1, overlap=0.01, orient=orient, spin=spin, anchor=anchor);
}
}
render(convexity=12)
orient_and_anchor([w, 2*l, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w, 2*l, h], orient, anchor, spin=spin) {
difference() {
union () {
fwd(l/2) cube(size=[w, l, h], center=true);
@@ -203,18 +206,19 @@ module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, orient
// a = Overhang angle of the joiner.
// clearance = Extra width to clear.
// overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Example:
// joiner_clear(orient=ORIENT_X);
module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, anchor=CENTER)
// joiner_clear(spin=-90);
module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP)
{
dmnd_height = h*0.5;
dmnd_width = dmnd_height*tan(a);
guide_size = w/3;
guide_width = 2*(dmnd_height/2-guide_size)*tan(a);
orient_and_anchor([w, guide_width, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w, guide_width, h], orient, anchor, spin=spin) {
union() {
up(h/4) half_joiner_clear(h=h/2.0-0.01, w=w, a=a, overlap=overlap, clearance=clearance);
down(h/4) half_joiner_clear(h=h/2.0-0.01, w=w, a=a, overlap=overlap, clearance=-0.01);
@@ -237,20 +241,21 @@ module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y
// screwsize = Diameter of screwhole.
// guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Examples:
// joiner(screwsize=3, orient=ORIENT_X);
// joiner(w=10, l=10, h=40, orient=ORIENT_X) cuboid([10, 10*2, 40], anchor=RIGHT);
module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, anchor=CENTER)
// joiner(screwsize=3, spin=-90);
// joiner(w=10, l=10, h=40, spin=-90) cuboid([10, 10*2, 40], anchor=RIGHT);
module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER_SLOP, anchor=CENTER, spin=0, orient=UP)
{
if ($children > 0) {
difference() {
children();
joiner_clear(h=h, w=w, a=a, clearance=0.1, orient=orient, anchor=anchor);
joiner_clear(h=h, w=w, a=a, clearance=0.1, orient=orient, spin=spin, anchor=anchor);
}
}
orient_and_anchor([w, 2*l, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w, 2*l, h], orient, anchor, spin=spin) {
union() {
up(h/4) half_joiner(h=h/2, w=w, l=l, a=a, screwsize=screwsize, guides=guides, slop=slop);
down(h/4) half_joiner2(h=h/2, w=w, l=l, a=a, screwsize=screwsize, guides=guides);
@@ -276,19 +281,20 @@ module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, slop=PRINTER
// n = Number of joiners (2 by default) to clear for.
// clearance = Extra width to clear.
// overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Examples:
// joiner_pair_clear(spacing=50, n=2);
// joiner_pair_clear(spacing=50, n=3);
module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overlap=0.01, orient=ORIENT_Y, anchor=CENTER)
module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP)
{
dmnd_height = h*0.5;
dmnd_width = dmnd_height*tan(a);
guide_size = w/3;
guide_width = 2*(dmnd_height/2-guide_size)*tan(a);
orient_and_anchor([spacing+w, guide_width, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([spacing+w, guide_width, h], orient, anchor, spin=spin) {
xspread(spacing, n=n) {
joiner_clear(h=h, w=w, a=a, clearance=clearance, overlap=overlap);
}
@@ -313,23 +319,24 @@ module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overla
// screwsize = Diameter of screwhole.
// guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Examples:
// joiner_pair(spacing=50, l=10, orient=ORIENT_X) cuboid([10, 50+10-0.1, 40], anchor=RIGHT);
// joiner_pair(spacing=50, l=10, n=2, orient=ORIENT_X);
// joiner_pair(spacing=50, l=10, n=3, alternate=false, orient=ORIENT_X);
// joiner_pair(spacing=50, l=10, n=3, alternate=true, orient=ORIENT_X);
// joiner_pair(spacing=50, l=10, n=3, alternate="alt", orient=ORIENT_X);
module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, anchor=CENTER)
// joiner_pair(spacing=50, l=10, spin=-90) cuboid([10, 50+10-0.1, 40], anchor=RIGHT);
// joiner_pair(spacing=50, l=10, n=2, spin=-90);
// joiner_pair(spacing=50, l=10, n=3, alternate=false, spin=-90);
// joiner_pair(spacing=50, l=10, n=3, alternate=true, spin=-90);
// joiner_pair(spacing=50, l=10, n=3, alternate="alt", spin=-90);
module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, anchor=CENTER, spin=0, orient=UP)
{
if ($children > 0) {
difference() {
children();
joiner_pair_clear(spacing=spacing, h=h, w=w, a=a, clearance=0.1, orient=orient, anchor=anchor);
joiner_pair_clear(spacing=spacing, h=h, w=w, a=a, clearance=0.1, orient=orient, spin=spin, anchor=anchor);
}
}
orient_and_anchor([spacing+w, 2*l, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([spacing+w, 2*l, h], orient, anchor, spin=spin) {
left((n-1)*spacing/2) {
for (i=[0:n-1]) {
right(i*spacing) {
@@ -361,16 +368,17 @@ module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, scr
// n = Number of joiners in a row. Default: 2
// clearance = Extra width to clear.
// overlap = Extra depth to clear.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Examples:
// joiner_quad_clear(spacing1=50, spacing2=50, n=2);
// joiner_quad_clear(spacing1=50, spacing2=50, n=3);
module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing2=undef, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, orient=ORIENT_Y, anchor=CENTER)
module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing2=undef, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP)
{
spacing1 = first_defined([spacing1, xspacing, 100]);
spacing2 = first_defined([spacing2, yspacing, 50]);
orient_and_anchor([w+spacing1, spacing2, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w+spacing1, spacing2, h], orient, anchor, spin=spin) {
zrot_copies(n=2) {
back(spacing2/2) {
joiner_pair_clear(spacing=spacing1, n=n, h=h, w=w, a=a, clearance=clearance, overlap=overlap);
@@ -397,25 +405,26 @@ module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing
// screwsize = Diameter of screwhole.
// guides = If true, create sliding alignment guides.
// slop = Printer specific slop value to make parts fit more closely.
// orient = Orientation of the shape. Use the `ORIENT_` constants from `constants.scad`. Default: `ORIENT_Y`.
// anchor = Alignment of the shape by the axis-negative (size1) end. Use the constants from `constants.scad`. Default: `CENTER`.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments#orient). Default: `UP`
// Examples:
// joiner_quad(spacing1=50, spacing2=50, l=10, orient=ORIENT_X) cuboid([50, 50+10-0.1, 40]);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=2, orient=ORIENT_X);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=false, orient=ORIENT_X);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=true, orient=ORIENT_X);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate="alt", orient=ORIENT_X);
module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=undef, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, orient=ORIENT_Y, anchor=CENTER)
// joiner_quad(spacing1=50, spacing2=50, l=10, spin=-90) cuboid([50, 50+10-0.1, 40]);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=2, spin=-90);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=false, spin=-90);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=true, spin=-90);
// joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate="alt", spin=-90);
module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=undef, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, slop=PRINTER_SLOP, anchor=CENTER, spin=0, orient=UP)
{
spacing1 = first_defined([spacing1, xspacing, 100]);
spacing2 = first_defined([spacing2, yspacing, 50]);
if ($children > 0) {
difference() {
children();
joiner_quad_clear(spacing1=spacing1, spacing2=spacing2, h=h, w=w, a=a, clearance=0.1, orient=orient, anchor=anchor);
joiner_quad_clear(spacing1=spacing1, spacing2=spacing2, h=h, w=w, a=a, clearance=0.1, orient=orient, spin=spin, anchor=anchor);
}
}
orient_and_anchor([w+spacing1, spacing2, h], orient, anchor, orig_orient=ORIENT_Y) {
orient_and_anchor([w+spacing1, spacing2, h], orient, anchor, spin=spin) {
zrot_copies(n=2) {
back(spacing2/2) {
joiner_pair(spacing=spacing1, n=n, h=h, w=w, l=l, a=a, screwsize=screwsize, guides=guides, slop=slop);