Strange things happening when doing difference

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

Strange things happening when doing difference

Troberg
Look at the following code to draw a heart (it's Christmas, after all). The
first module draws a heart, but I also wanted just a heart outline, so I
made the second. It works by drawing a heart, then drawing a heart of
similar size, do a negative offset, extrude and difference.

module hjarta(width,tjocklek){
    spets=width*0.7;
   
    color([1,0,0])
    linear_extrude(tjocklek)
    union(){
        hull(){
            translate([-width/4,spets,0])
            circle(d=width/2);
           
            polygon([[0,0],[1,spets],[-width/2,spets]]);
        }
        hull(){
            translate([width/4,spets,0])
            circle(d=width/2);
           
            polygon([[0,0],[width/2,spets],[-1,spets]]);
        }
    }
}

module hjartaoutline(width,outlinewidth,tjocklek){
    spets=width*0.7;
   
    color([1,0,0])
    difference(){
        hjarta(width,tjocklek);
       
        translate([0,0,-1])
        linear_extrude(tjocklek+2)
        offset(delta=-outlinewidth)
        union(){
            hull(){
                translate([-width/4,spets,0])
                circle(d=width/2);
               
                polygon([[0,0],[1,spets],[-width/2,spets]]);
            }
            hull(){
                translate([width/4,spets,0])
                circle(d=width/2);
               
                polygon([[0,0],[width/2,spets],[-1,spets]]);
            }
        }
    }
}

hjartaoutline(60,5,10);

It looks great from above, but zoom in and look from a low angle at the area
around the inner tip, and it looks like faces are missing.

What am I doing wrong?

(Of course, if anyone wants to use the heart code, have fun.)



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

Ronaldo
Your rendered model is fine. The missing faces are artifacts of the preview process. To avoid them just add the argument convexity=10 to all linear_extrude().


2017-12-11 10:52 GMT-02:00 Troberg <[hidden email]>:
Look at the following code to draw a heart (it's Christmas, after all). The
first module draws a heart, but I also wanted just a heart outline, so I
made the second. It works by drawing a heart, then drawing a heart of
similar size, do a negative offset, extrude and difference.

module hjarta(width,tjocklek){
    spets=width*0.7;

    color([1,0,0])
    linear_extrude(tjocklek)
    union(){
        hull(){
            translate([-width/4,spets,0])
            circle(d=width/2);

            polygon([[0,0],[1,spets],[-width/2,spets]]);
        }
        hull(){
            translate([width/4,spets,0])
            circle(d=width/2);

            polygon([[0,0],[width/2,spets],[-1,spets]]);
        }
    }
}

module hjartaoutline(width,outlinewidth,tjocklek){
    spets=width*0.7;

    color([1,0,0])
    difference(){
        hjarta(width,tjocklek);

        translate([0,0,-1])
        linear_extrude(tjocklek+2)
        offset(delta=-outlinewidth)
        union(){
            hull(){
                translate([-width/4,spets,0])
                circle(d=width/2);

                polygon([[0,0],[1,spets],[-width/2,spets]]);
            }
            hull(){
                translate([width/4,spets,0])
                circle(d=width/2);

                polygon([[0,0],[width/2,spets],[-1,spets]]);
            }
        }
    }
}

hjartaoutline(60,5,10);

It looks great from above, but zoom in and look from a low angle at the area
around the inner tip, and it looks like faces are missing.

What am I doing wrong?

(Of course, if anyone wants to use the heart code, have fun.)



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

Troberg
Worked like a charm!

I kept think I've done something wrong in my logic, and kept checking that.
I didn't think as far as the under the hood considerations.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

JordanBrown
In reply to this post by Ronaldo
On 12/11/2017 5:19 AM, Ronaldo Persiano wrote:
Your rendered model is fine. The missing faces are artifacts of the preview process. To avoid them just add the argument convexity=10 to all linear_extrude().

Why isn't convexity=10 (or whatever) the default?  What's the downside?  Should I be defining my own linear_extrude module that just always slaps in a convexity=10?


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

shadowwynd
There is a performance penalty for convexity.  More convex shapes need a higher convexity setting; setting it manually allows for user control.   

Sent from my iPhone

On Dec 11, 2017, at 11:02 AM, Jordan Brown <[hidden email]> wrote:

On 12/11/2017 5:19 AM, Ronaldo Persiano wrote:
Your rendered model is fine. The missing faces are artifacts of the preview process. To avoid them just add the argument convexity=10 to all linear_extrude().

Why isn't convexity=10 (or whatever) the default?  What's the downside?  Should I be defining my own linear_extrude module that just always slaps in a convexity=10?

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

Troberg
Well, he has a point. Perhaps a higher default would make sense.

Why?

* Because the people who are likely to run into performance issues are the
ones who are more advanced users. They can probably explicitly set a lower
limit.

* Because performance of the hardware is increasing all the time, so
performance issues are likely to go away, given time.

* Standard programming wisdom: Make it work first, then look at performance.

* It wouldn't break existing code.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

codifies
> * Because the people who are likely to run into performance issues are the
> ones who are more advanced users. They can probably explicitly set a lower
> limit.
Save for the fact that often on this list people complaining of
excessive "compile" times are those that have (seemingly) randomly
changed defaults and unknowingly created models with a bazillion vertices...


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Strange things happening when doing difference

nophead
convexity only affects F5 preview times. It doesn't seem to affect it much either. When I can be bothered I set it appropriately, other times a random number big enough. 

On 11 December 2017 at 22:00, Chris Camacho <[hidden email]> wrote:
* Because the people who are likely to run into performance issues are the
ones who are more advanced users. They can probably explicitly set a lower
limit.
Save for the fact that often on this list people complaining of excessive "compile" times are those that have (seemingly) randomly changed defaults and unknowingly created models with a bazillion vertices...



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org