659 module construct_exterior_walls( envelop=
false )
665 : let( sf=wall_h/h_h )
666 [
for (e=h) !is_list(e) ? e * sf : [
first(e) * sf,
second(e) ] ];
668 if ( mode_scale_io ==
true )
673 pg_rectangle(wall_xy + 0*[wth, wth], vr=vr, vrm=vrm_ci, center=
true);
674 pg_rectangle(wall_xy - 2*[wth, wth], vr=vr, vrm=vrm_ci, center=
true);
682 pg_rectangle(wall_xy + 0*[wth, wth], vr=vr, vrm=vrm_ci, center=
true);
684 translate([0, 0, -10*
eps/2])
686 pg_rectangle(wall_xy - 2*[wth, wth], vr=vr, vrm=vrm_ci, center=true);
695 : let( sf = [
for (e=h) !is_list(e) ? 1 : [
for (f=
second(e)) !is_list(f) ? f :
first(f) ] ] )
700 : let( sf = [
for (e=h) !is_list(e) ? 1 : [
for (f=
second(e)) !is_list(f) ? f :
second(f) ] ] )
703 echo(
strl([
"wall: extrusion scale factors [x-min, x-max] = ", [min(sf_x), max(sf_x)]]));
704 echo(
strl([
"wall: extrusion scale factors [y-min,y- max] = ", [min(sf_y), max(sf_y)]]));
705 echo(
strl([
"wall: height (ignoring ribs) = ", wall_h]));
706 echo(
strl([
"wall: total interior height (ignoring ribs) = ", wall_h + lip_h]));
711 module construct_lips( envelop=
false )
722 sf = 2*wth / max(wall_xy) * lip_tw/100;
727 translate( [0, 0, wall_h/2] )
732 [3, 0, -1, [1 + sf, 1]],
733 [2, lip_ro, -1, [1 - sf, 1]],
734 [1, 0, +1, [1, 1 + sf]],
735 [0, lip_ro, +1, [1, 1 - sf]]
745 h1 = (ro == 0) ? [lip_h + 0 *
eps]
746 : [lip_h + 0 *
eps, hc];
748 s1 = (ro == 0) ? wall_xy - 0 * [wth, wth] * lip_bw/100
749 : (ro == 1) ? wall_xy - 2 * [wth, wth] * (1-lip_bw/100)
750 : (ro == 2) ? wall_xy - 2 * [wth, wth] * lip_bw/100
751 : wall_xy - 2 * [wth, wth] * lip_bw/100;
754 h2 = (ro == 0) ? [lip_h + 10 *
eps, hc]
755 : [lip_h + 10 *
eps];
757 s2 = (ro == 0) ? wall_xy - 2 * [wth, wth] * lip_bw/100
758 : (ro == 1) ? wall_xy - 2 * [wth, wth]
759 : (ro == 2) ? wall_xy - 2 * [wth, wth]
760 : wall_xy - 4 * [wth, wth] * lip_bw/100;
762 translate([0, 0, (wall_h + lip_h -
eps)/2 *
third(z)])
776 echo(
strl([
"lip: mode = ", lip_m]));
777 echo(
strl([
"lip: height = ", lip_h]));
778 echo(
strl([
"lip: base width percentage = ", lip_bw]));
779 echo(
strl([
"lip: top reduction percentage = ", lip_tw]));
780 echo(
strl([
"lip: inner lip alignment index = ", lip_a]));
785 module construct_lid()
788 translate([0, 0, -
eps])
790 pg_rectangle([encl_x, encl_y] + 0*[wth, wth], vr=vr, vrm=vrm_ci, center=true);
794 echo(
strl([
"lid: extrusion = ", lid]));
795 echo(
strl([
"lid: height = ", lid_h]));
800 module construct_ribs()
806 max_x =
first( wall_xy) - 2*(wth -
eps);
810 max_h = wall_h + min(2,
binary_iw2i(rib_m, 5, 2)) * lip_h;
816 rib_edx = [
for (x=[0:1/
get_fn(1)/2:1]) [2*sqrt(1-pow(x,2)), 1]];
818 rib_edy = [
for (e=rib_edx)
reverse(e)];
820 rib_sd =
defined_e_or(rib, 1, [ wth, [[wth, rib_edx]], [[wth, rib_edy]] ] );
834 crc_x = max([0, floor(max_x/rib_w * rcp_x / 100)]);
835 crc_y = max([0, floor(max_y/rib_w * rcp_y / 100)]);
836 crc_z = max([0, floor(max_h/rib_w * rcp_z / 100)]);
856 [ 0, [max_x, max_y], [cnt_x, cnt_y], [[0, 0, 0], [0, 0, 0]] ],
857 [ 1, [max_y, max_h], [cnt_y, cnt_z], [[90, 0, -90], [max_x/2, 0, max_h/2]] ],
858 [ 2, [max_x, max_h], [cnt_x, cnt_z], [[90, 0, 0], [0, max_y/2, max_h/2]] ],
859 [ 3, [max_y, max_h], [cnt_y, cnt_z], [[90, 0, 90], [-max_x/2, 0, max_h/2]] ],
860 [ 4, [max_x, max_h], [cnt_x, cnt_z], [[-90, 0, 0], [0, -max_y/2, max_h/2]] ],
883 translate([(sx/nx*(1-nx)/2) + (sx/nx * i), 0, 0])
885 square([rib_w, sy], center=true);
890 translate([0, (sy/ny*(1-ny)/2) + (sy/ny * i), 0])
892 square([sx, rib_w], center=true);
900 rib_hxd =
sum( [
for (e=rib_hx) is_list(e) ?
first(e) : e] );
901 rib_hyd =
sum( [
for (e=rib_hy) is_list(e) ?
first(e) : e] );
905 rib_rwh = wall_h + lip_h
906 - max( 0, max([rib_hxd, rib_hyd]) +
third(rib_lo) )
909 echo(
strl([
"rib: mode = ", rib_m]));
910 echo(
strl([
"rib: width = ", rib_w]));
911 echo(
strl([
"rib: extrusion x = ", rib_hx]));
912 echo(
strl([
"rib: height x = ", rib_hxd]));
913 echo(
strl([
"rib: extrusion y = ", rib_hy]));
914 echo(
strl([
"rib: height y = ", rib_hyd]));
915 echo(
strl([
"rib: coverage [x, y, z] = ", [rcp_x, rcp_y, rcp_z]]));
916 echo(
strl([
"rib: count [x, y, z] = ", [cnt_x, cnt_y, cnt_z]]));
918 echo(
strl([
"rib: global offset = ", rib_lo]));
919 echo(
strl([
"rib: remaining wall height = ", rib_rwh]));
924 module construct_interior_walls()
938 max_x =
first( wall_xy) - 2*(wth -
eps);
942 max_h = wall_h + min(2,
binary_iw2i(wall_m, 8, 2)) * lip_h;
949 (i == 1) ? [ 9, 10, 9, 10]
950 : (i == 2) ? [ 3, 4, 3, 4]
951 : (i == 3) ? [ 7, 8, 7, 8]
961 [
for (x=[0:1/
get_fn(1)/2:1]) [1,sqrt(1+
eps-pow(x,2))]],
962 [
for (x=[1:-1/
get_fn(1)/2:1/2]) [1,1-sqrt(1-pow(x,2))]],
964 [
for (x=[0:1/
get_fn(1)/2:1]) [1,sqrt(1+
eps+pow(x,2))]],
965 [
for (x=[1:-1/
get_fn(1)/2:1/2]) [1,1+sqrt(1-pow(x,2))]],
970 s_wt_rm =
select_ci( cfg_wt_rm, wt_rm_i,
true );
971 cfg_rt = [def_dw/2, s_wt_rm];
975 s_wb_rm =
select_ci( cfg_wt_rm, wb_rm_i,
true );
976 cfg_rb = [def_dw/2,
reverse(s_wb_rm)];
980 (wt_rm_i > 0 && wb_rm_i == 0) ? [max_h - def_dw/2, cfg_rt]
981 : (wt_rm_i == 0 && wb_rm_i > 0) ? [cfg_rb, max_h - def_dw/2]
982 : (wt_rm_i > 0 && wb_rm_i > 0) ? [cfg_rb, max_h - def_dw, cfg_rt]
1016 type_m = is_list(inst_m) ?
1023 tdef_s = (inst_t == 0) ?
1028 tdef_he = !is_list(def_he) ?
1039 tdef_vr = !is_list(def_vr) ?
1043 :
shift(def_vr, n=-1, r=
false, c=
true);
1046 tdef_vrm = !is_list(def_vrm) ?
1050 :
shift(def_vrm, n=+1, r=
false, c=
true);
1072 echo(
strl([
"wall-inst: [type, move, scale, rotation, size, he, vr, vrm] = ",
1073 [inst_t, inst_m, inst_f, inst_r, s, he, vr, vrm]]));
1079 wall_cnt = is_list(inst_l) ? len(inst_l) : 1;
1081 echo(
strl([
"wall: configuration = ", config]));
1082 echo(
strl([
"wall: mode = ", wall_m]));
1084 echo(
strl([
"wall: max [x, y, h] = ", [max_x, max_y, max_h]]));
1086 echo(
strl([
"wall: default width = ", def_dw]));
1087 echo(
strl([
"wall: default extrusion = ", def_he]));
1088 echo(
strl([
"wall: default edge rounding = ", def_vr]));
1089 echo(
strl([
"wall: default edge rounding mode = ", def_vrm]));
1091 echo(
strl([
"wall: count = ", wall_cnt]));
1093 echo(
strl([
"wall: global offset = ", wall_lo]));
1098 module construct_posts( add=
false, remove=
false )
1112 cfg_p_vr_sf = (cfg_rbst ==
true) ? [0, 1/2, 1/2, 0] : [0, 1/2, 3/2, 0];
1113 cfg_p_vrm_filet = (cfg_rbst ==
true) ? [0, 1, 1, 0] : [0, 1, 4, 0];
1114 cfg_p_vrm_bevel = (cfg_rbst ==
true) ? [0, 5, 5, 0] : [0, 5, 10, 0];
1116 cfg_f0_vr_sf = [2, 0, 1];
1117 cfg_f0_vrm_filet = [4, 0, 3];
1118 cfg_f0_vrm_bevel = [10, 0, 9];
1120 cfg_f1_vr_sf = [0, 1, 1, 0];
1121 cfg_f1_vrm_filet = [0, 4, 3, 0];
1122 cfg_f1_vrm_bevel = [0, 10, 9, 0];
1127 (i == 1) ? cfg_p_vrm_bevel
1128 : (i == 2) ? cfg_p_vrm_filet
1133 (i == 1) ? cfg_f0_vrm_bevel
1134 : (i == 2) ? cfg_f0_vrm_filet
1138 (i == 1) ? cfg_f1_vrm_bevel
1139 : (i == 2) ? cfg_f1_vrm_filet
1149 lip_h_t = ((
binary_bit_is(post_m, 8, 1) ? 1 : 0) + 1) * lip_h;
1152 cfg_p1_h = (
binary_bit_is(post_m, 7, 1) ? lip_h_t : 0) + wall_h;
1153 cfg_p2_h = (
binary_bit_is(post_m, 7, 0) ? lip_h_t : 0) + wall_h;
1158 max_x =
first( wall_xy) - 2*(wth -
eps);
1159 max_y =
second(wall_xy) - 2*(wth -
eps);
1160 max_h = wall_h + lip_h_t;
1187 def_h1_d_c = def_h0_d
1191 def_p1_d_c = def_h0_d
1195 def_h2_d_c = def_h0_d
1199 def_p2_d_c = def_h0_d
1218 def_p1_vr =
defined_e_or(def_p1, 5, cfg_p_vr_sf * wth);
1227 def_h2_vr =
defined_e_or(def_h2, 5, cfg_p_vr_sf * wth/2);
1236 def_p2_vr =
defined_e_or(def_p2, 5, cfg_p_vr_sf * wth);
1245 def_f0_vr =
defined_e_or(def_f0, 5, cfg_f0_vr_sf * wth);
1254 def_f1_vr =
defined_e_or(def_f1, 5, cfg_f1_vr_sf * wth);
1264 module construct_fins(d, h, t, f)
1269 function fin_embed(r, w) =
1275 r - sqrt( pow(r,2) - pow(w/2, 2) - pow(d/2, 2) );
1290 echo(
strl([
"post-inst-fins: [d, h, t, f] = ", [d, h, t, f]]));
1292 f_in = fin_embed(d/2, w);
1299 rotate([90, 0, da/c * i + 180])
1300 translate([-d/2 - b + f_in, 0, 0])
1311 rotate([0, 0, da/c * i])
1312 translate([b/2 + d/2 - f_in, 0, 0])
1322 module construct_cylinder ( en, c, ft, f,
eps=0 )
1335 echo(
strl([
"post-inst-cylinder: [c, eps] = ", [c,
eps]]));
1337 translate([0, 0, ho -
eps/2])
1346 construct_fins(d_adj, h_adj, ft, f);
1354 post_cfm = ( add ==
true && remove == false ) ?
"add"
1355 : ( add ==
false && remove ==
true ) ?
"remove"
1356 : ( add ==
true && remove == true ) ?
"add & remove"
1359 echo(
strl([
"post: construction phase = ", post_cfm]));
1383 inst_zx =
limit(inst_ax, -1, 1) * (max_x + wth)/2;
1384 inst_zy =
limit(inst_ay, -1, 1) * (max_y + wth)/2;
1385 inst_zz =
limit(inst_az, -1, 0) * lid_h;
1397 tdef_h1_d_c = (inst_pt == 0) ? def_h1_d_c : def_h2_d_c;
1398 tdef_h1_d = (inst_pt == 0) ? def_h1_d : def_h2_d;
1399 tdef_h1_h = (inst_pt == 0) ? def_h1_h : def_h2_h;
1400 tdef_h1_ho = (inst_pt == 0) ? def_h1_ho : def_h2_ho;
1401 tdef_h1_da = (inst_pt == 0) ? def_h1_da : def_h2_da;
1402 tdef_h1_ha = (inst_pt == 0) ? def_h1_ha : def_h2_ha;
1403 tdef_h1_vr = (inst_pt == 0) ? def_h1_vr : def_h2_vr;
1404 tdef_h1_vrm = (inst_pt == 0) ? def_h1_vrm : def_h2_vrm;
1407 tdef_p_d_c = (inst_pt == 0) ? def_p1_d_c : def_p2_d_c;
1408 tdef_p_d = (inst_pt == 0) ? def_p1_d : def_p2_d;
1409 tdef_p_h = (inst_pt == 0) ? def_p1_h : def_p2_h;
1410 tdef_p_ho = (inst_pt == 0) ? def_p1_ho : def_p2_ho;
1411 tdef_p_da = (inst_pt == 0) ? def_p1_da : def_p2_da;
1412 tdef_p_ha = (inst_pt == 0) ? def_p1_ha : def_p2_ha;
1413 tdef_p_vr = (inst_pt == 0) ? def_p1_vr : def_p2_vr;
1414 tdef_p_vrm = (inst_pt == 0) ? def_p1_vrm : def_p2_vrm;
1420 tdef_f_c = (inst_ft == 0) ? def_f0_c : def_f1_c;
1421 tdef_f_da = (inst_ft == 0) ? def_f0_da : def_f1_da;
1422 tdef_f_w = (inst_ft == 0) ? def_f0_w : def_f1_w;
1423 tdef_f_d_sf = (inst_ft == 0) ? def_f0_d_sf : def_f1_d_sf;
1424 tdef_f_h_sf = (inst_ft == 0) ? def_f0_h_sf : def_f1_h_sf;
1425 tdef_f_vr = (inst_ft == 0) ? def_f0_vr : def_f1_vr;
1426 tdef_f_vrm = (inst_ft == 0) ? def_f0_vrm : def_f1_vrm;
1433 h0_en = (remove ==
true);
1443 h0 = [h0_d, h0_h, h0_ho, h0_da, h0_ha, h0_vr, h0_vrm];
1448 tdef_h1_ims = (cfg_hp_idr ==
true) ? h0_d + tdef_h1_d_c : tdef_h1_d;
1449 tdef_p_ims = (cfg_hp_idr ==
true) ? h0_d + tdef_p_d_c : tdef_p_d;
1452 h1_en = (remove ==
true);
1462 h1 = [h1_d, h1_h, h1_ho, h1_da, h1_ha, h1_vr, h1_vrm];
1465 p_en = (add ==
true);
1475 p = [p_d, p_h, p_ho, p_da, p_ha, p_vr, p_vrm];
1485 f = [f_c, f_da, f_w, f_d_sf, f_h_sf, f_vr, f_vrm];
1492 translate([inst_zx, inst_zy, inst_zz])
1496 construct_cylinder(p_en, p, inst_ft, f);
1498 construct_cylinder(h0_en, h0,
eps=10*
eps);
1499 construct_cylinder(h1_en, h1,
eps=10*
eps);
1503 echo(
strl([
"post-inst: [type, align, move, rotation, hole0, hole1, post, fins] = ",
1504 [inst_t, inst_a, inst_m, inst_r, inst_h0, inst_h1, inst_p, inst_f]]));
1511 post_cnt = is_list(inst_l) ? len(inst_l) : 1;
1513 echo(
strl([
"post: configuration = ", config]));
1514 echo(
strl([
"post: mode = ", post_m]));
1516 echo(
strl([
"post: count = ", post_cnt]));
1521 module envelop_assembly( envelop=
false )
1523 if ( envelop ==
true )
1529 construct_exterior_walls(
true );
1530 construct_lips(
true );
1543 module assembly_add()
1547 construct_exterior_walls();
1566 envelop_assembly( mode_int_mask ==
true )
1572 envelop_assembly( mode_int_mask ==
true )
1573 construct_interior_walls();
1578 envelop_assembly( mode_int_mask ==
true )
1579 construct_posts( add=true);
1584 module assembly_remove()
1588 construct_posts( remove=
true);
1614 vrm_ci = (mode_lmt_vrm ==
false) ? vrm
1616 [
for (e=vrm)
select_ci(v=[0, 5, 1], i=e, l=
false)]
1617 :
select_ci(v=[0, 5, 1], i=vrm, l=
false);
1628 wall_h = (mode_size_in ==
true) ? h_h - lip_h : h_h - lip_h - lid_h;
1636 encl_x = (mode_size_in ==
true) ? size_x + 2*wth - wall_ox : size_x;
1637 encl_y = (mode_size_in ==
true) ? size_y + 2*wth - wall_oy : size_y;
1638 encl_z = (mode_size_in ==
true) ? wall_h + lip_h + lid_h : h_h;
1641 wall_xy = [encl_x + wall_ox, encl_y + wall_oy];
1644 szint_x =
first (wall_xy) - 2*wth;
1645 szint_y =
second(wall_xy) - 2*wth;
1646 szint_z = wall_h + lip_h;
1650 echo(
strl([
"box: construction begin"]));
1652 echo(
strl([
"box: exterior dimensions [x, y, z] = ", [encl_x, encl_y, encl_z]]));
1653 echo(
strl([
"box: interior dimensions [x, y, z] = ", [szint_x, szint_y, szint_z]]));
1664 [0, -encl_x, -szint_x -wth*2, -szint_x, +szint_x, +szint_x +wth*2, +encl_x ]/2,
1665 [0, -encl_y, -szint_y -wth*2, -szint_y, +szint_y, +szint_y +wth*2, +encl_y ]/2,
1666 [lid_h, 0, lid_h -encl_z/2, -wall_h/2, -wall_h, -wall_h -lip_h]
1673 translate([align_x, align_y, align_z])
1682 echo(
strl([
"box: alignment [x, y, z] = ", [align_x, align_y, align_z]]));
1684 echo(
strl([
"box: construction end"]));
zero3d
<decimal-list-2> A 3d zero vector (a list with three zeros).
eps
<decimal> Epsilon, small distance to deal with overlapping shapes.
empty_lst
<list> A list with no values (the empty list).
function binary_iw2i(v, s, w)
Decode the binary bits of a bit window to an integer value.
function binary_bit_is(v, b, t=1)
Test if a binary bit position of an integer value equals a test bit.
function defined_e_or(v, i, d)
Return an element of an iterable when it exists or a default value otherwise.
function third(v)
Return the third element of an iterable value.
function shift(v, n=0, r=true, c=true)
Shift the elements of an iterable value.
function second(v)
Return the second element of an iterable value.
function first(v)
Return the first element of an iterable value.
function reverse(v)
Reverse the elements of an iterable value.
function select_ci(v, i, l=true)
Select specified element from list or return a default.
function limit(v, l, u)
Limit a list of numbers between an upper and lower bounds.
function strl(v)
Convert a list of values to a concatenated string.
function merge_s(v, r=false)
Serially merge the elements of a list.
function sum(v, i1, i2)
Compute the sum of a list of numbers.
function defined_or(v, d)
Return given value, if defined, or a secondary value, if primary is not defined.
function is_scalar(v)
Test if a value is a single non-iterable value.
function is_defined(v)
Test if a value is defined.
function polygon_regular_perimeter(n, r, a)
Compute the perimeter of an n-sided regular polygon in 2D.
function get_fn(r)
Return facets number for the given arc radius.
module project_box_rectangle(wth, h, size, vr, vrm, inset, lid, lip, rib, wall, post, align, mode=0, verb=0)
A rectangular box maker for project boxes, enclosures and housings.
module pg_triangle_sas(v, a=x_axis_ci, o, vr, vrm=1, vfn, cm=0)
A polygon triangle specified by size-angle-size with vertex rounding.
module pg_rectangle(size=1, o, vr, vrm=1, vfn, center=false)
A polygon rectangle with vertex rounding.