Hi eZe,
Welcome to the forum. Your post is still flagged as "This post has NOT been
accepted by the mailing list yet", so nobody gets it unless they look.
You need to subscribe to the mailing list
http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1 ,
and respond to the registration email.
I'm being a bit more expansive than you may have wanted, but early tips are
better IMO. While overkill for small examples, many of these will become
essential when your code gets more complex.
Firstly, if you ever see something like this in preview:
http://forum.openscad.org/file/n20216/box_feedback.jpg
http://forum.openscad.org/file/n20216/box_feedback_2.jpg
it points to what can be a problem, coincident faces
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#What_are_those_strange_flickering_artifacts_in_the_preview.3F
, often not a problem when rendering, but when involved in other CSG they
can bite you in the arse at the worst time and lead to holes in the mesh
and/or degenerate faces. So best to avoid them.
I note you use eps so you may have picked up on this. Usually this is done
by subtracting eps from the start and adding 2*eps at the end, like I've
shown below, but in your code there is the other way shown in your code
further below.
http://forum.openscad.org/file/n20216/box_feedback_3.jpg
It is very common to have a pattern like this:
i=20;
cube([i,i,i]);
translate([0,0,-eps])
cylinder(r=i/4,h=i+2*eps);
Similar issues can happen when joining two objects, always embed one just
inside the other, by eps or more, never butt the faces together. This can
happen haphazardly when joining curved surfaces, you'll find...
Second, format/layout. I think you will find that one statement per line and
indentation will make it a lot easier to see what's what. I've rejigged your
code below in the way I would do it. It allows inserting extra
transformations easy and also commenting one out temporarily in testing.
Also makes for shorter lines, no wrapped lines, and the preview window can
be bigger.
Then, a suggestion, label your close braces '}', then you can easily see
what opening operators they pair with. I use '// [a letter or two]', such as
'// i' for intersection(), '// if' for if(), '// t' for translate(), f for
for, etc as shown below. I also use '// -' in difference() to separate the
positive from the negative (removed) parts; in more complex code it is not
always apparent. Label a module() close brace with the module name.
Your code, how I do it:
length=100;
width=24;
depth=40;
thickness=2;
drv_rad=18;
drv_mnt_x=width;
drv_mnt_y=18;
drv_mnt_z=length-drv_rad-10;
eps=0.05; // better, until you do bigger, real big models, then use 0.1
plate_offset=8.5;
drv_plate=2.1;
hole=width-19.6;
groove=3;
mu=0.4;
groove_thick=1.2;
module box(){
difference(){
cube([width,depth,length]);
// -
translate([thickness,thickness,thickness])
cube([width,depth-2thickness,length-2thickness]);
} // d
} // box
module box_cut(){
difference(){ // <-- moved { up, like you did elsewhere
box();
// -
// coincident faces problem
// use -eps, +2eps
translate([width-groove,mu+groove_thick-eps,mu]) // -eps
cube([groove+eps,depth-2(mu+groove_thick)+2eps,groove_thick]); //
+2eps
// or
#translate([width-groove,mu,mu])
cube([groove+eps,depth-2mu,groove_thick]);
translate([width-groove,mu,length-mu-groove_thick])
cube([groove+eps,depth-2*(mu),groove_thick]);
translate([width-groove,mu,mu])
cube([groove+eps,groove_thick,length-(mu+groove_thick)]);
translate([width-groove,depth-mu-groove_thick,mu])
cube([groove+eps,groove_thick,length-(mu+groove_thick)]);
} // d
} // box_cut
module box_driver(){
difference(){
union(){ // <-- moved { up, like you did elsewhere
box_cut();
translate([drv_mnt_x,drv_mnt_y,drv_mnt_z]){ // {} not needed
rotate(90,[1,0,0])
cylinder(r=drv_rad+thickness,h=drv_mnt_y+7);
} // t
} //u
// -
translate([drv_mnt_x,drv_mnt_y+eps,drv_mnt_z]){ // {} not needed
rotate(90,[1,0,0])
cylinder(r=drv_rad,h=drv_mnt_y+7+2*eps);
} // t
translate([drv_mnt_x,-7-eps,drv_mnt_z-drv_rad-thickness-eps])
cube([drv_rad+thickness+eps,drv_mnt_y+7+2eps,2(drv_rad+thickness+eps)]);
} // d
} // box_driver
module box_driver_full(){
difference(){
box_driver();
// -
translate([hole,plate_offset,drv_mnt_z-drv_rad-thickness-eps])
cube([width+eps,drv_plate,2*(drv_rad+thickness+eps)]);
} // d
} // box_driver_full
box_driver_full();
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
View this message in context: http://forum.openscad.org/Is-there-a-better-way-of-doing-it-tp20212p20216.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Hi eZe,
Welcome to the forum. Your post is still flagged as "This post has NOT been
accepted by the mailing list yet", so nobody gets it unless they look.
You need to subscribe to the mailing list
<http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1> ,
and respond to the registration email.
I'm being a bit more expansive than you may have wanted, but early tips are
better IMO. While overkill for small examples, many of these will become
essential when your code gets more complex.
Firstly, if you ever see something like this in preview:
<http://forum.openscad.org/file/n20216/box_feedback.jpg>
<http://forum.openscad.org/file/n20216/box_feedback_2.jpg>
it points to what can be a problem, coincident faces
<https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#What_are_those_strange_flickering_artifacts_in_the_preview.3F>
, often not a problem when rendering, but when involved in other CSG they
can bite you in the arse at the worst time and lead to holes in the mesh
and/or degenerate faces. So best to avoid them.
I note you use eps so you may have picked up on this. Usually this is done
by subtracting eps from the start and adding 2*eps at the end, like I've
shown below, but in your code there is the other way shown in your code
further below.
<http://forum.openscad.org/file/n20216/box_feedback_3.jpg>
It is very common to have a pattern like this:
i=20;
cube([i,i,i]);
translate([0,0,-eps])
cylinder(r=i/4,h=i+2*eps);
Similar issues can happen when joining two objects, always embed one just
inside the other, by eps or more, never butt the faces together. This can
happen haphazardly when joining curved surfaces, you'll find...
Second, format/layout. I think you will find that one statement per line and
indentation will make it a lot easier to see what's what. I've rejigged your
code below in the way I would do it. It allows inserting extra
transformations easy and also commenting one out temporarily in testing.
Also makes for shorter lines, no wrapped lines, and the preview window can
be bigger.
Then, a suggestion, label your close braces '}', then you can easily see
what opening operators they pair with. I use '// [a letter or two]', such as
'// i' for intersection(), '// if' for if(), '// t' for translate(), f for
for, etc as shown below. I also use '// -' in difference() to separate the
positive from the negative (removed) parts; in more complex code it is not
always apparent. Label a module() close brace with the module name.
Your code, how I do it:
> length=100;
> width=24;
> depth=40;
> thickness=2;
> drv_rad=18;
> drv_mnt_x=width;
> drv_mnt_y=18;
> drv_mnt_z=length-drv_rad-10;
> eps=0.05; // better, until you do bigger, real big models, then use 0.1
> plate_offset=8.5;
> drv_plate=2.1;
> hole=width-19.6;
> groove=3;
> mu=0.4;
> groove_thick=1.2;
>
> module box(){
> difference(){
> cube([width,depth,length]);
> // -
> translate([thickness,thickness,thickness])
> cube([width,depth-2*thickness,length-2*thickness]);
> } // d
> } // box
>
> module box_cut(){
> difference(){ // <-- moved { up, like you did elsewhere
> box();
> // -
> // coincident faces problem
> // use -eps, +2*eps
> *translate([width-groove,mu+groove_thick-eps,mu]) // -eps
> cube([groove+eps,depth-2*(mu+groove_thick)+2*eps,groove_thick]); //
> +2*eps
> // or
> #translate([width-groove,mu,mu])
> cube([groove+eps,depth-2*mu,groove_thick]);
> translate([width-groove,mu,length-mu-groove_thick])
> cube([groove+eps,depth-2*(mu),groove_thick]);
> translate([width-groove,mu,mu])
> cube([groove+eps,groove_thick,length-(mu+groove_thick)]);
> translate([width-groove,depth-mu-groove_thick,mu])
> cube([groove+eps,groove_thick,length-(mu+groove_thick)]);
> } // d
> } // box_cut
>
> module box_driver(){
> difference(){
> union(){ // <-- moved { up, like you did elsewhere
> box_cut();
> translate([drv_mnt_x,drv_mnt_y,drv_mnt_z]){ // {} not needed
> rotate(90,[1,0,0])
> cylinder(r=drv_rad+thickness,h=drv_mnt_y+7);
> } // t
> } //u
> // -
> translate([drv_mnt_x,drv_mnt_y+eps,drv_mnt_z]){ // {} not needed
> rotate(90,[1,0,0])
> cylinder(r=drv_rad,h=drv_mnt_y+7+2*eps);
> } // t
> translate([drv_mnt_x,-7-eps,drv_mnt_z-drv_rad-thickness-eps])
>
> cube([drv_rad+thickness+eps,drv_mnt_y+7+2*eps,2*(drv_rad+thickness+eps)]);
> } // d
> } // box_driver
>
> module box_driver_full(){
> difference(){
> box_driver();
> // -
> translate([hole,plate_offset,drv_mnt_z-drv_rad-thickness-eps])
> cube([width+eps,drv_plate,2*(drv_rad+thickness+eps)]);
> } // d
> } // box_driver_full
>
> box_driver_full();
-----
Admin - PM me if you need anything, or if I've done something stupid...
Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
--
View this message in context: http://forum.openscad.org/Is-there-a-better-way-of-doing-it-tp20212p20216.html
Sent from the OpenSCAD mailing list archive at Nabble.com.