stl not correct by mesh generators

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

stl not correct by mesh generators

kingoftomorrow
This post has NOT been accepted by the mailing list yet.
Dear all,

I have exported a stl file produced by openscad. I have then loaded it into two mesh generators (gmsh and netgen). Both software told me that there are problems in the stl and they were not be able to mesh it with tetrahedra. Let me know if there is something I can do to solve the problem. Best regards,

kingoftomorrow

PS: here is the code I used:

echo(version=version());

difference() {

union() {
   
// with twist the extruded shape will rotate around the Z axis
color("cyan")
    translate([10, 0, 0])
        linear_extrude(height = 200, convexity = 10, twist = 0)
            square([200, 35], center = true);

color("cyan")
    translate([10, 0, 200]) rotate([0,20,0])
        linear_extrude(height = 200, convexity = 10, twist = 0)
            square([200, 35], center = true);
   
color("cyan")
    translate([80, 0, 500]) rotate([90,0,0])
            cylinder (h = 35, r=250, center = true, $fn=100);

color("cyan")
    translate([80, -150, 500]) rotate([90,0,0])
            cylinder (h = 35, r=250, center = true, $fn=100);

color("cyan")
    translate([80, -300, 500]) rotate([90,0,0])
            cylinder (h = 35, r=250, center = true, $fn=100);
           
color("cyan")
    translate([80, -450, 500]) rotate([90,0,0])
            cylinder (h = 35, r=250, center = true, $fn=100);  
         
color("cyan")
    translate([80, -220, 500]) rotate([90,0,0])
            cylinder (h = 450, r=180, center = true, $fn=100);    
           
 }
 
 color("cyan")
    translate([80, -450, 500]) rotate([90,0,0])
            cylinder (h = 1200, r=150, center = true, $fn=100);  
 
 }
Reply | Threaded
Open this post in threaded view
|

Re: stl not correct by mesh generators

Parkinbot
This is a nasty problem and results from very small numerical "errors" that occur with rotation.
As a workaround you can enlarge your first cube by a small number.

color("cyan")    
   translate([10, 0, 200]) rotate([0,20,0])        
      linear_extrude(height = 200, convexity = 10, twist = 0)
            square([200, 35.01], center = true);
Reply | Threaded
Open this post in threaded view
|

Re: stl not correct by mesh generators

Ronaldo
Scaling the linear_extrusion before the rotation and translation makes things worst.

2017-04-16 15:12 GMT-03:00 Parkinbot <[hidden email]>:
This is a nasty problem and results from very small numerical "errors" that
occur with rotation.
As a workaround you can enlarge your first cube by a small number.


> color("cyan")
>    translate([10, 0, 200]) rotate([0,20,0])
>       linear_extrude(height = 200, convexity = 10, twist = 0)
>             square([200, 35.01], center = true);





--
View this message in context: http://forum.openscad.org/stl-not-correct-by-mesh-generators-tp21241p21245.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
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: stl not correct by mesh generators

wolf
In reply to this post by Parkinbot
For the why's, or what happens inside OpenSCAD, see my comments in <http://forum.openscad.org/template/NamlServlet.jtp?macro=reply&node=21240>
This is about the practical side, how to fix it.
1. Find the trouble spots
A sure way of creating internal rounding errors is rotating by 90 degrees. These rounding errors then show up in the F6 graphic (F5 works differently, it usually does not show it) as edges that cut straight through so-called "flat" polygons.

In the picture, "A","B", . . . mark edges that would not be shown if the respective polygons were truly flat. By itself, that is no hassle, but when you try to union shapes with nearly parallel faces, CGAL starts screaming: ASSERTION ERROR!!!
2. To correct it you use CGAL's ability to work without internal rounding errors, see this code:
// fixed version
 
difference()
{
union()
    { $fn=100;
    Front();    
    translate([80, -150, 500])  Cyl();
    translate([80, -300, 500])  Cyl();
    translate([80, -450, 500])  Cyl();  
    translate([80, -230, 500])  rotate([90,0,0])  cylinder (h = 440, r=180, center = true);  
 }
    translate([80, -250, 500]) rotate([90,0,0])  cylinder (h = 1200, r=150, center = true, $fn=10);
 }
 
module Cyl()    // ensure the cylinder's top and bottom are truly vertical
  difference()
    {
     rotate([90,0,0])  cylinder (h = 45, r=250, center = true);
     translate([0,-17.5,0]) cube([600,10,600],center=true);  
     translate([0,17.5,0]) cube([600,10,600],center=true);  
    }
   
module Front()
difference()
 {  // with twist the extruded shape will rotate around the Z axis
 union()
    {  
    translate([10, 0, 0])
        linear_extrude(height = 200, convexity = 10, twist = 0)
            square([200, 45], center = true);
    translate([10, 0, 200]) rotate([0,20,0])
        linear_extrude(height = 200, convexity = 10, twist = 0)
            square([200, 45], center = true);
    translate([80, 0, 500])  rotate([90,0,0])  cylinder (h = 45, r=250, center = true);
    }
    translate([80,-17.5,300]) cube([600,10,1000],center=true);  
    translate([80,17.5,300]) cube([600,10,1000],center=true);  
 }    

By the way: with a $fn=100, there are far too many edges, above picture uses $fn=10. The excess edges on the inside of the cylinder are currently harmless, that is going to change if you do something with it . . .

wolf
Reply | Threaded
Open this post in threaded view
|

Re: stl not correct by mesh generators

kingoftomorrow
This post has NOT been accepted by the mailing list yet.
Dear wolf,

thank you very much for the long explanation! Best,

kingoftomorrow
Reply | Threaded
Open this post in threaded view
|

Re: stl not correct by mesh generators

cacb
In reply to this post by kingoftomorrow
kingoftomorrow,

I tried the update suggested by Parkinbot on your file ("enlarge your first cube by a small number"). Then tried various options in my surface remesher until no errors and finally ran it through a program that encapsulates geompack++ "zgp" tetraeder solid mesher, resulting in a tetraeder mesh with about ~28000 nodes in GMSH .msh format, see
https://www.expirebox.com/download/b65481d442b9dc90e9df4a935660d4ff.html

The mesh can be visualised using GMSH, image below shows part of the mesh clipped away.
clipped tetraeder mesh

Meshers are generally much more "picky" than 3d print slicers, you really need an error free topology, i.e. only 2-manifold edges and no collapsed faces. This means you have to be careful with overlapping faces and sliver intersections when modelling. In this case surface remeshing worked with tolerance adjustments (ignore faces with area<0.5 and use ignore distances<0.01). Surface mesh size was selected=20

Carsten Arnholm
Reply | Threaded
Open this post in threaded view
|

Re: stl not correct by mesh generators

MichaelAtOz
Administrator
In reply to this post by kingoftomorrow
Hi King,

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, and CLICK THE LINK in the registration email (check your spam folder).
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!