Yet another coincident point problem...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Yet another coincident point problem...

Dan Zuras 3D

        Folks,

        I have what I'm fairly sure is another problem with
        OpenSCAD not properly recognising coincident points
        when it sees them.

        I was trying to learn how to use children objects in
        OpenSCAD modules when I ran across this.  There are
        60 degree angles involved but I went out of my way to
        keep things as rational as possible.  Even so, that
        pesky sqrt(3)/2 just HAS TO appear one way or another.

        I include the code below.  It is short.

        I can't tell from looking at it if OpenSCAD is having
        the problem or the rendering is the problem.  As such,
        I cannot tell whether to ignore it & proceed or try
        some other approach.

        I know the recommendation will be to overlap the
        objects but, really, the problem is in how coincident
        points are recognised not in improper overlap.

        And the solution is not to be found in higher precision.
        Plain old 64-bit double precision is more than adequate.
        It is the coincidence test that needs to be changed.

        Sorry about the rant but overlapping is contrary to
        where I'm going with this code.

        Yours,

                                Dan



module triplicate(s) {
        for (i = [0:3]) rotate([0,0,120*i]) translate([-s/3,0])
                rotate([0,0,60]) translate([s/6,0]) child(0);
}

module flakeSide(s) {
        polygon(points = [[-s/2, 0], [0, -sqrt(3)*s/6], [s/2, 0]]);
}

module flake0Body(s, n, rs, c) {
        if (s - 6*n*(2*rs + c)/sqrt(3) > 0)
                triplicate(s - 6*n*(2*rs + c)/sqrt(3))
                        flakeSide(s - 6*n*(2*rs + c)/sqrt(3));
        else cube([2,2,2], center = true); /* just an error case */
}

translate([0,0]) difference() {
        flake0Body(9,0,1/2,1/10);
        flake0Body(9,1,1/2,1/10);
}

Reply | Threaded
Open this post in threaded view
|

Re: Yet another coincident point problem...

kintel
Administrator
On Jul 9, 2010, at 03:17 AM, Dan Zuras 3D wrote:

> I can't tell from looking at it if OpenSCAD is having
> the problem or the rendering is the problem.  As such,
> I cannot tell whether to ignore it & proceed or try
> some other approach.

This is just a rendering glitch in 2D mode.
You can verify this by e.g.:
o Render using CGAL (F6): You will now get a 2D plane with red outlines showing that the 2D objects was unioned correctly
o Add a linear_extrude() -> the bug wil go away.

..at least this is the behavior on my machine (64-bit Mac build).

~/= Marius

--
We are Elektropeople for a better living.


Reply | Threaded
Open this post in threaded view
|

Re: Yet another coincident point problem...

Dan Zuras 3D
> Subject: Re: [OpenSCAD] Yet another coincident point problem...
> From: Marius Kintel <[hidden email]>
> Date: Fri, 9 Jul 2010 11:30:17 +0200
> To: Dan Zuras 3D <[hidden email]>,
>  [hidden email]
>
> On Jul 9, 2010, at 03:17 AM, Dan Zuras 3D wrote:
>
> > I can't tell from looking at it if OpenSCAD is having
> > the problem or the rendering is the problem.  As such,
> > I cannot tell whether to ignore it & proceed or try
> > some other approach.
>
> This is just a rendering glitch in 2D mode.
> You can verify this by e.g.:
> o Render using CGAL (F6): You will now get a 2D plane with red outlines =
> showing that the 2D objects was unioned correctly
> o Add a linear_extrude() -> the bug wil go away.
>
> ..at least this is the behavior on my machine (64-bit Mac build).
>
> ~/= Marius
>
> --
> We are Elektropeople for a better living.

        Alas, that is not what happens
        for me (32-bit Ubuntu 10.04).  - Dan


function absoluteValue(x) = (x < 0)?-x:x;
function signum(x) = (x < 0)?-1:(x > 0)?1:0;

module triplicate(s) {
        for (i = [0:3]) rotate([0,0,120*i]) translate([-s/3,0])
                rotate([0,0,60]) translate([s/6,0]) child(0);
}

module flake0Poly(s) {
        polygon(points = [[-s/2, 0], [0, -sqrt(3)*s/6], [s/2, 0]]);
}

module flake0Face(s, n, rs, c) {
        if (s - 2*sqrt(3)*n*(2*rs + c) > rs)
                translate([0,-n*(2*rs + c)])
                        flake0Poly(s - 2*sqrt(3)*n*(2*rs + c));
        else cube([2,2,2], center = true); // just an error state
}

module flake1Poly(s, n, rs, c) {
        polygon(points = [[-s/3, -sqrt(3)*absoluteValue(s)/18],
                [0, -sqrt(3)*absoluteValue(s)/6],
                [0, sqrt(3)*absoluteValue(s)/18],
                [-s/6 + sqrt(3)*signum(s)*n*(2*rs + c), n*(2*rs + c)],
                [-s/6 + signum(s)*n*(2*rs + c)/sqrt(3), -n*(2*rs + c)],
                [-s/6 - sqrt(3)*signum(s)*n*(2*rs + c), -n*(2*rs + c)]]);
}

module flake1Face(s, n, rs, c) if (s/3 - 2*sqrt(3)*n*(2*rs + c) > rs)
        union() for (i = [-1,1]) {
                flake1Poly(i*s, n, rs, c);
                translate([i*s/3,0]) flake0Face(s/3, n, rs, c);
                translate([-i*s/6,0]) rotate([0,0,i*60]) translate([i*s/6,0])
                        flake0Face(s/3, n, rs, c);
        }
        else flake0Face(s, n, rs, c);

module flake1Bottom(s, n, rs, c) {
        triplicate(s) flake1Face(s, n, rs, c);
}

linear_extrude(height=1, center=true, convexity=10, twist=-1, slices=5)
        flake1Bottom(117,0,1/2,1/10);

Reply | Threaded
Open this post in threaded view
|

Re: Yet another coincident point problem...

kintel
Administrator
On Jul 9, 2010, at 13:02 PM, Dan Zuras 3D wrote:
>
> Alas, that is not what happens
> for me (32-bit Ubuntu 10.04).  - Dan
>
Your new model also fails here, the problem being, as you pointed out, that the vertices are not considered coincident.

Please keep posting issues, rants and ideas. I don't have much time to look deeper into this exact issue at the moment, but this is valuable input for when that time comes :)

~/= Marius

--
We are Elektropeople for a better living.