265 module construct_side( idx, size, insts, p, vr, vrm )
270 module construct_joint( size,
length,
count, offset, axis, sides, type )
272 side_offset = type == 2 ? -1 : +1;
274 joint_length =
first(pin_conf) * 2 +
second(pin_conf) + offset;
275 joint_count = min(
count, max(1, floor(
length / joint_length)));
282 [ s * (size.x/2 + mth/2 * side_offset), 0 ]
283 : [ 0, s * (size.y/2 + mth/2 * side_offset) ]
285 rotate(axis == 0 ? -90 : 0)
286 translate([joint_length/2 - (joint_length * joint_count)/2, 0])
287 mirror(s < 0 ? [0, 1] : [0, 0])
288 mirror(type == 2 ? [0, 1] : [0, 0])
291 conf = [
length, mth, pin_conf, screw_conf, nut_conf ],
292 insts = [ for ( i = [0 : joint_count - 1] ) [0, joint_length * i, joint_form ] ],
303 module construct_hole_inst( inst )
308 shape_type = is_list(shape) ?
first(shape) : shape;
309 shape_argv = is_list(shape) ?
tailn(shape, 1) : undef;
316 log_info(
strl([
"holes for side index = ", idx,
", conf = ", inst]));
320 echo(shape_type=shape_type, shape_argv=shape_argv, layout=layout);
342 x = size.x/2, y = size.y/2,
346 [[x, -y], [x, y], [-x, y], [-x, -y]]
348 : concat([[x, -y], [x, y]], p ,[[-x, y], [-x, -y]]),
361 offset=offset, axis=axis, sides=sides,
376 size_ro = size + [
eps,
eps] * 8;
383 offset=offset, axis=axis, sides=sides,
392 offset=offset, axis=axis, sides=sides,
403 if ( !
is_empty( search(idx, is_list(e) ? e : [e]) ) )
404 construct_hole_inst( i );
412 module layout_2d( gap, select )
417 side_offset_x = (select == 0) ?
418 (side_xy.x + side_yz.x)/2 + gap - mth
419 : (side_xy.x + side_yz.y)/2 + gap;
421 side_offset_y = (side_xy.y + side_xz.y)/2 + gap;
423 for (side = close ? [0, 2] : [0])
426 i = side > 0 ? 5 : 4,
428 r = side > 0 ? 0 : 180,
429 t = [0, side_offset_y * side],
432 vr = side > 0 ? vr_xy_1 : vr_xy_2,
433 vrm = side > 0 ? vrm_xy_1 : vrm_xy_2
436 translate(t) rotate(r)
437 construct_side( idx=i, size=side_xy, insts=insts_xy, p=p, vr=vr, vrm=vrm );
442 i = side > 0 ? 1 : 0,
444 r = side > 0 ? 0 : 180,
445 t = [0, side_offset_y * side],
447 p = side > 0 ? ap_xz_1 : ap_xz_2,
448 vr = side > 0 ? vr_xz_1 : vr_xz_2,
449 vrm = side > 0 ? vrm_xz_1 : vrm_xz_2
452 translate(t) rotate(r)
453 construct_side( idx=i, size=side_xz, insts=insts_xz, p=p, vr=vr, vrm=vrm );
458 i = side > 0 ? 3 : 2,
462 : side > 0 ? 270 : 90,
465 [side_offset_x * side, side_offset_y * side]
466 : [side_offset_x * side, 0],
468 p = side > 0 ? ap_yz_1 : ap_yz_2,
469 vr = side > 0 ? vr_yz_1 : vr_yz_2,
470 vrm = side > 0 ? vrm_yz_1 : vrm_yz_2
473 translate(t) rotate(r)
474 construct_side( idx=i, size=side_yz, insts=insts_yz, p=p, vr=vr, vrm=vrm );
480 module layout_3d( gap )
486 for (side = close ? [-1, 1] : [-1])
489 i = side > 0 ? 5 : 4,
492 t = [0, 0, (box_z/2 - mth/2 + gap) * side + (close ? 0 : -mth/2)],
495 vr = side > 0 ? vr_xy_1 : vr_xy_2,
496 vrm = side > 0 ? vrm_xy_1 : vrm_xy_2
499 translate(t) rotate(r)
501 construct_side( idx=i, size=side_xy, insts=insts_xy, p=p, vr=vr, vrm=vrm );
507 i = side > 0 ? 1 : 0,
509 r = side > 0 ? [90, 0, 0] : [90, 0, 180],
510 t = [0, (box_y/2 + gap) * side, 0],
512 p = side > 0 ? ap_xz_1 : ap_xz_2,
513 vr = side > 0 ? vr_xz_1 : vr_xz_2,
514 vrm = side > 0 ? vrm_xz_1 : vrm_xz_2
517 translate(t) rotate(r)
519 construct_side( idx=i, size=side_xz, insts=insts_xz, p=p, vr=vr, vrm=vrm );
525 i = side > 0 ? 3 : 2,
527 r = side > 0 ? [90, 0, 90] : [90, 0, 270],
528 t = [(box_x/2 - mth + gap) * side, 0, 0],
530 p = side > 0 ? ap_yz_1 : ap_yz_2,
531 vr = side > 0 ? vr_yz_1 : vr_yz_2,
532 vrm = side > 0 ? vrm_yz_1 : vrm_yz_2
535 translate(t) rotate(r)
537 construct_side( idx=i, size=side_yz, insts=insts_yz, p=p, vr=vr, vrm=vrm );
554 pin_conf =
defined_or(joint_pin, [mth, mth * 5/2]);
557 pin_offset_y =
defined_e_or (joint_spacing, 1, pin_offset_x);
558 pin_offset_z =
defined_e_or (joint_spacing, 2, pin_offset_y);
570 ap_xz_1 = close ? undef :
defined_e_or (side_add, 0, undef);
571 ap_yz_1 = close ? undef :
defined_e_or (side_add, 1, undef);
573 ap_xz_2 = close ? undef :
defined_e_or (side_add, 2, ap_xz_1);
574 ap_yz_2 = close ? undef :
defined_e_or (side_add, 3, ap_yz_1);
599 box_x = inside ? box_p_x + mth*2 : box_p_x;
600 box_y = inside ? box_p_y + mth*2 : box_p_y;
601 box_z = inside ? box_p_z + mth*2 : box_p_z;
604 side_xy = [ box_x, box_y ];
605 side_xz = [ box_x - mth*2, box_z - (close ? mth*2 : mth) ];
606 side_yz = [ box_y, box_z - (close ? mth*2 : mth) ];
609 joint_x = min(side_xy.x, side_xz.x);
610 joint_y = min(side_xy.y, side_yz.y);
611 joint_z = min(side_xz.y, side_yz.y);
619 [joint_y, max_sets_y, pin_offset_y, 0, [-1, +1], 2],
620 [joint_x, max_sets_x, pin_offset_x, 1, [-1, +1], 2]
625 [joint_z, max_sets_z, pin_offset_z, 0, [-1, +1], 0],
626 [joint_x, max_sets_x, pin_offset_x, 1, close ? [-1, +1] : [-1], 0]
631 [joint_z, max_sets_z, pin_offset_z, 0, [-1, +1], 2],
632 [joint_y, max_sets_y, pin_offset_y, 1, close ? [-1, +1] : [-1], 0]
641 log_info(
strl([
"box exterior size = ", [box_x, box_y, box_z]]));
650 layout_3d( gap=side_offset );
657 layout_2d( gap=side_offset, select=layout );
661 layout_2d( gap=side_offset, select=layout );
module log_echo(m)
Output message to console.
module log_info(m)
Output information message to console.
eps
<decimal> Epsilon, small distance to deal with overlapping shapes.
number_max
<decimal> The largest representable number in OpenSCAD scripts.
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)
Returns an element from an iterable if it exists, or a default value if not.
function count(mv, v, s=true, i)
Count all occurrences of a match value in an iterable value.
function second(v)
Return the second element of an iterable value.
function defined_eon_or(v, i, d)
Returns the list element or scalar numeric value if defined, otherwise returns the default value.
function first(v)
Return the first element of an iterable value.
function tailn(v, n=1)
Return a list containing all but the first n elements of an iterable value.
function is_empty(v)
Test if an iterable value is empty.
function strl(v)
Convert a list of values to a concatenated string.
function defined_or(v, d)
Return given value, if defined, or a secondary value, if primary is not defined.
function polygon_round_eve_all_p(c, vr=0, vrm=1, vfn, w=true, cw=true)
Compute coordinates that round all of the vertices between each adjacent edges in 2D.
module joint2d_box_screw(conf, insts, mode=0, type=0, trim=false, align)
Create 2d edge profiles for screw and nut box joint construction.
module box2d_finger_joint(mth=1, size, joint_pin, joint_screw, joint_nut, joint_form=7, joint_mode=0, joint_spacing, joints_max, side_holes, side_add, vr, vrm, side_spacing, layout=0, mode=0, part=63, verb=0)
Generate a 2D box design using screw-based finger joint (box-joint).
module select_common_2d_shape(type=0, argv, center=false, verb=0)
Select configure and construct one of the available 2d shapes.
function length(v, from=length_unit_default, to=length_unit_base, d=1)
Convert a length value from one unit to another, with optional dimensional scaling.