Thu Oct 3 17:57:01 EDT 2019

```There is a real world example here:

I have parametric fixing blocks with three screws positions.

I have functions that return the transformation matrices to get from the
block's origin to the screw positions.

function fixing_block_h_hole(screw = def_screw) =
translate(fixing_block_depth(screw) / 2) * rotate([90, 0, 0]); //!
Returns transform to position the horizontal screw
function fixing_block_v_holes(screw = def_screw) = //! Returns a list
of transforms to position the vertical screws
let(pitch =  2 * insert_outer_d(screw_insert(screw)) + 2 * wall,
offset = fixing_block_depth(screw) / 2)
[for(end = [-1, 1]) translate([end * pitch / 2, offset]) *
rotate([180, 0, 0])];

function fixing_block_holes(screw) =
concat([fixing_block_h_hole(screw)], fixing_block_v_holes(screw)); //!
Returns a list of transforms to position all the screws

Those functions are normally called by modules to place children at those
positions.

module fixing_block_h_hole(screw = def_screw) //! Position children on
the horizontal hole
multmatrix(fixing_block_h_hole(screw))
children();

module fixing_block_v_holes(screw = def_screw) //! Position children
on the vertical holes
for(p = fixing_block_v_holes(screw))
multmatrix(p)
children();

module fixing_block_holes(screw = def_screw) //! Position children on
all the holes
for(p = fixing_block_holes(screw))
multmatrix(p)
children();

These positioning modules are used to drill the holes in the block, place
the inserts in the holes and place the screws.

module fixing_block_assembly(screw = def_screw) //! Printed part with
the inserts inserted
translate_z(fixing_block_height(screw))
rotate([0, 180, 0])
color(pp1_colour) render() fixing_block(screw);

insert = screw_insert(screw);

fixing_block_v_holes(screw)
insert(insert);

fixing_block_h_hole(screw)
insert(insert);
}

They can also be used to drill holes in the panels they fasten to but there
is a problem: the positioning is 3D, but for speed I design my sheets in
2D. Originally I projected the holes to 2D but that is also slow.

My final solution was to factor out the position to functions that return
transformation matrices. Then when I design a box I build lists of these
transformation for all the fixing blocks in the box. For each panel I then
run through the list to see if they place a drill on the surface of the
sheet and if so position a circle to subtract from the sheet. I.e. I do the
projection myself because CGAL is too slow.

Here I build a list transforms to position all the blocks:

With this function I multiply all the block positions by the screw
positions to get a list of all the block holes positions for the box:

function side_holes(type) = [for(p = fixing_block_positions(type), q =
fixing_block_holes(bbox_screw(type))) p * q];

Here, given the position of the sheet as a transform, I check if hole is
on the sheet, and if so drill it.

module drill_holes(type, t)
for(list = [corner_holes(type), side_holes(type)], p = list)
let(q = t * p)
if(abs(transform([0, 0, 0], q).z) < eps)
multmatrix(q)

For each sheet I make a 2D object with the holes drilled in it.

module bbox_base_blank(type) { //! 2D template for the base

dxf(str(bbox_name(type), "_base"));

difference() {
sheet_2D(bbox_base_sheet(type), bbox_width(type), bbox_depth(type), 1);

drill_holes(type, translate(bbox_height(type) / 2));
}
}

Most of my objects are not this complicated though. They mostly just have
have modules to position their children with translate and rotate. If an
object only has screws in the Z plane then the positioning modules work for
both 2D and 3D. E.g.

module iec_screw_positions(type) //! Position children at the screw holes
for(side = [-1, 1])
translate([side * iec_pitch(type) / 2, 0])
children();

module iec_inserts(type) {              //! Place the inserts
insert = screw_insert(iec_screw(type));

iec_screw_positions(type)
insert(insert);
}

On Thu, 3 Oct 2019 at 21:30, macdarren via Discuss <

>
> I read but did not totally follow your plan for how you would do the 'robot
> arm, ring example'
> I am re-reading also studying-up on some points of OpenSCAD, now....
>
> I am mostly a casual user and I am sure the issue is my inexperience with
> the language.  I have not really used OpenSCAD functions and I am only now
> learning how the 'children' process works and as for using 'multmatrix' I
> have never felt the need to use it, or maybe I did but didn't know it.
>
> Do you have some simple code you could post that would show how you use
> functions and positioning modules to achieve this?  Obviously it doesn't
> have to actually contain complex objects even simple rectangular cubes as
> place holders would suffice.  What I want to see is how you would nest
> these
> positioning modules and use functions to feed position modules and return
> positions to other modules needing the position information.
>
> I would still like some ability to query objects, especially those that
> form
> hard to compute (for me) angles or positions where I need to insert items.
> Using the method you outline might suffice for many things that are done
>
> TIA
>
>
>
>
> --