[OpenSCAD] Newbie question

Jordan Brown openscad at jordan.maileater.net
Wed May 22 20:15:50 EDT 2019


On 5/22/2019 1:00 PM, Dirk Willems wrote:
> But for now I'm struggling with the following
>
> difference() {
>    translate([0,37,15]) rotate([90,0,0]) cylinder(h=20,r=5);
>    translate([0,37,15]) rotate([90,0,0]) cylinder(h=20,r=4);
> }
>
> difference() {   
>     cylinder(h=30,r1=25,r2=16,central=true);
>     cylinder(h=30,r1=23,r2=14,central=true);
> }
>
> What I want to accomplish is to combine the 2 cylinders into each
> other with the inside is smooth and off course having my hole in the
> second cylinder.

You say in the second block "central=true".  Perhaps you meant
"center=true", but that doesn't seem to do what you want.  (But maybe it
would, if you took away the translate.)

Others have talked about the "Z fighting" issue of having a difference
(or intersection) yield a zero-thickness piece.  The software can't
quite decide whether or not there's something there.  (Suggestion to
developers:  if you can detect this case... there's nothing there. 
There's no practical reason for a zero-thickness piece; the intent is
almost certainly that it's nothing.)

Here's a simple tweak to fix that.  It nudges the "negative" cylinders
down a little and makes them a little longer so the boundaries of the
result are unambiguous.  And while we're there, let's factor out the
translate and rotate so we don't have to repeat them.

    eps=0.01;
    translate([0,37,15]) rotate([90,0,0]) {
        difference() {
            cylinder(h=20,r=5);
            translate([0,0,-eps]) cylinder(h=20+eps*2,r=4);
        }
    }

    difference() {   
        cylinder(h=30,r1=25,r2=16);
        translate([0,0,-eps]) cylinder(h=30+2*eps,r1=23,r2=14);
    }

But if you look carefully, maybe that isn't what you want.  Note that
the hole in the horizontal pipe doesn't go through; it's blocked by the
cone's wall.  That's because you're taking a pipe and unioning it with a
hollow cone.  You might also notice that the pipe protrudes into the
hollow cone, which might not be what you want.

Here's a version that fixes both of those.  Alas, because of the
regrouping we have to bring back the duplicated translate and rotate.

    eps=0.01;
    difference() {
        union() {
            translate([0,37,15]) rotate([90,0,0]) cylinder(h=20,r=5);
            cylinder(h=30,r1=25,r2=16);
        }
        union() {
            translate([0,37+eps,15]) rotate([90,0,0]) cylinder(h=20+eps*2,r=4);
            translate([0,0,-eps]) cylinder(h=30+2*eps,r1=23,r2=14);
        }
    }

If you really did want the pipe to protrude into the cone, you have to
regroup a little:

    eps=0.01;
    difference() {
        union() {
            difference() {
                cylinder(h=30,r1=25,r2=16);
                translate([0,0,-eps]) cylinder(h=30+2*eps,r1=23,r2=14);
            }
            translate([0,37,15]) rotate([90,0,0]) cylinder(h=20,r=5);
        }
        translate([0,37+eps,15]) rotate([90,0,0]) cylinder(h=20+eps*2,r=4);
    }

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscad.org/pipermail/discuss_lists.openscad.org/attachments/20190523/93242faa/attachment.html>


More information about the Discuss mailing list