Two bugs in one file...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Two bugs in one file...

Dan Zuras 3D

        Folks,

        I include a file at the end of this note that illustrates
        a couple of problems.  I think both are merely rendering
        problems.  I don't think either are anything new.  But
        this code allows me to illustrate each in an easier fashion
        than before.

        For reference, the code is intended to create a series of
        funny shaped holes for a Mendel application.

        If you just run the file as is you will see 3 figures.  The
        middle figure is subtracted from the right figure to produce
        the hole on the left.

        The first bug can be seen in the form of the green fuzz when
        you look into the hole.  I'm pretty sure this is just a
        rendering problem & not something that will actually appear
        in plastic.  I'm also pretty sure it is caused by two figures
        which butt together rather than overlap.

        But as you can see by looking at things, I have gone out of
        my way to overlap things as much as possible.  Still, there
        are a couple of objects that have no choice but to meet at
        their edges.

        Thus the bug.

        Nothing new.  We all know its an ongoing problem.  Still,
        its annoying.  And it makes it difficult to know when you
        have your code correct.

        Now for the second bug.

        Uncomment the "for (i = [1:5])" line near the bottom & run
        it again.

        You will see a series of ever taller holes.  Each will have
        the fuzz of the first bug.

        And you should notice that it takes a long time to render.
        Some 10s of seconds.  Not so much that it makes it
        impossible to use but far more than the complexity of the
        image deserves.  If you roll it around & look at it from
        various angles you will also notice that it takes longer
        to move it around than it deserves.

        I am running this on two different Ubuntu 10.4 systems with
        no special 'gaming' hardware so likely much of what I am
        seeing involves software rendering.

        Now try this:  Comment out that for loop line again &
        uncomment the "for (i = [1:6])" line.  Run it again.

        One more object but this time it renders almost instantly.
        The bug is that each of the subtracted objects now appears
        in solid green rather than as fuzzy or not there at all.
        Further, you can roll it around with no trouble at all.
        Snappy & quick.

        Again, nothing new.  I have noticed this problem ever since
        I started using OpenSCAD.  This is just the first time I
        have been able to illustrate it so easily.

        (There is a third failure mode in which openscad quickly
        sucks up all the available memory & dies on a malloc
        failure.  When I find a way of showing that one easily I
        will send you a file.)

        The version of OpenSCAD I am running is dated 2010.05.

        Should I be running a newer version?

        If so, could new releases be announced in this forum when
        they happen?  As well as some description of what changes
        are included, of course.

        Well, like I said, I'm sure you all have seen this before.

        I just thought having a simple way to produce it might aid
        in its cure.

        OK, maybe not. :-)

        Thanks,

                                Dan Zuras

//////////////////////

// The outside of a hole (to be union'ed in).

module hole2OD(ir, tir, lip, h, hs, nh) union() {
        for (i = [0:nh - 1]) translate([0, 0, i*(h + hs)]) {
                translate([0, 0, h]) rotate([180, 0, 0])
                        scale([1/100, 1/100, 1/100])
                                cylinder(h = 100*(ir + tir + lip)*sqrt(3),
                                        r1 = 100*(ir + tir + lip), r2 = 0,
                                        center = false);
                scale([1/100, 1/100, 1/100])
                        cylinder(h = 100*(ir + tir + lip)*sqrt(3),
                                r1 = 100*(ir + tir + lip), r2 = 0,
                                center = false);
                scale([1/100, 1/100, 1/100])
                        cylinder(h = 100*h, r = 100*(ir + tir),
                                center = false);
        }
        if (nh > 1) for (i = [0:nh - 2]) translate([0, 0, i*(h + hs)])
                translate([0, 0, h]) scale([1/100, 1/100, 1/100])
                        cylinder(h = 100*hs, r = 100*(ir + tir + lip),
                                center = false);
}


// The inside of a hole (to be difference'd in).

module hole2ID(ir, tir, lip, h, hs, nh) union() {
        for (i = [0:nh - 1]) translate([0, 0, i*(h + hs)]) {
                scale([1/100, 1/100, 1/100])
                        cylinder(h = 100*(ir + lip)*sqrt(3),
                                r1 = 100*(ir + lip), r2 = 0, center = false);
                translate([0, 0, h]) rotate([180, 0, 0])
                        scale([1/100, 1/100, 1/100])
                                cylinder(h = 100*(ir + lip)*sqrt(3),
                                        r1 = 100*(ir + lip), r2 = 0,
                                        center = false);
        }
        if (nh > 1) for (i = [0:nh - 2]) translate([0, 0, i*(h + hs) + h])
                scale([1/100, 1/100, 1/100])
                        cylinder(h = 100*hs, r = 100*(ir + lip),
                                center = false);
        translate([0, 0, -3*h]) scale([1/100, 1/100, 1/100])
                cylinder(h = 100*3*h, r = 100*(ir + lip), center = false);
        translate([0, 0, nh*(h + hs) - hs]) scale([1/100, 1/100, 1/100])
                cylinder(h = 100*3*h, r = 100*(ir + lip), center = false);
        scale([1/100, 1/100, 1/100])
                cylinder(h = 100*(nh*(h + hs) - hs), r = 100*ir,
                        center = false);

}

translate([ 15,0,0]) hole2OD(5,1,1,4,1,3);
translate([  0,0,0]) hole2ID(5,1,1,4,1,3);
translate([-15,0,0])
        difference() { hole2OD(5,1,1,4,1,3); hole2ID(5,1,1,4,1,3); }

//for (i = [1:5])
//for (i = [1:6])
translate([15*(i - 3),-15,0])
        difference() { hole2OD(5,1,1,4,1,i); hole2ID(5,1,1,4,1,i); }