[OpenSCAD] avoiding assertion violation

Carsten Arnholm arnholm at arnholm.org
Wed Jul 17 07:30:50 EDT 2019


On 17.07.2019 08:16, Ronaldo Persiano wrote:
> Em qua, 17 de jul de 2019 às 03:07, MichaelAtOz <oz.at.michael at gmail.com 
> <mailto:oz.at.michael at gmail.com>> escreveu:
> 
>     What Ronaldo says is if there is a bug it would be that OpenSCAD
>     might be
>     able to detect such attempts and produce a better error message.
> 
> 
> The only situation the rotate_extrude() of a simple polygon is clearly a 
> manifold is when the polygon does not have any intersection with the Y 
> axis and it rests entirely at left or at right of the Y axis. Then the 
> rotate_extrude() will be a torus like object.
> 
> When the intersection of a simple polygon and the Y axis is a full 
> polygon edge, I would expect a non-manifold result because that 
> particular edge would be in the interior of the object. But CGAL does 
> produce a valid polyhedron 

I don't know how rotate_extrude is implemented in OpenSCAD, but I am 
guessing CGAL does not provide such a feature, and instead 
rotate_extrude is done by OpenSCAD directly to compute the coordinates 
of a polyhedron. Implemented this way, there are no boolean operations 
involved.

This is certainly the case in AngelCAD where rotate_extrude is not a 
feature at all in Carve (Carve is the equivalent to CGAL), it is 
computed directly by the application, not the library.

The implication is that the issue is not about manifoldness, but rather 
about self intersection and collapsed faces. Manifoldness is about 
topology (connectivity), self-intersection and collapsed faces is about 
geometry (coordinates in this case). You can have a self-intersecting 
polyhedron with collapsed faces which is 2 manifold, as in the below example

When you say "I would expect a non-manifold result because that 
particular edge would be in the interior of the object. But CGAL does
produce a valid polyhedron". I would say CGAL that is correct, and the 
expectation is incorrect.

Consider the example

rotate_extrude(){
   polygon([ [0,-2],[2,0], [0,2] ]);
}

This produces no error by OpenSCAD, and you could argue it is ok at this 
stage.

    Top level object is a 3D object:
    Facets:         42

The visible external faces are only 14. If you export to OFF format and 
then analyze it with polyfix...

OFF export finished: O:/STL/rotate1.off

...you will find that OpenSCAD appears to have merged overlapping 
vertices, thus creating a non-manifold model and containing collapsed 
faces. After repair, the collapsed faces are removed and thus the model 
is again 2-manifold.

===
$ polyfix rotate1.off

Parameters:
   input_file = rotate1.off


polyhedron 0 ================= volume=14.5942, dtol=0.01, atol=1e-06, 
maxiter=10
iteration 0: vertices=9 faces=42
              warning: 28 zero area faces.
              warning: nonmanifold edges: uc(4)=14 uc(14)=2 uc(28)=1
              removed 28 collapsed or zero area faces
              total changes=28
              no warnings

iteration 1: vertices=9 faces=14
              total changes=0
              no warnings

Summary:
              polyhedron 0: vertices=9 faces=14 : no warnings

Writing: rotate1_1.off
===

We can repeat the same exercise in AngelCAD (coordinates are a bit 
different, because AngelCAD rotates around global Y).


// AngelCAD code.
shape@ main_shape()
{
    array<pos2d@> p = { {0,-2},{2,0},{0,2} };
    return rotate_extrude(polygon(p),deg:360);
}

void main()
{
    shape@ obj = main_shape();
    obj.write_xcsg(GetInputFullPath(),secant_tolerance:0.2);
}


This creates the output

xcsg processing: /media/nas_openbzr/STL/xcsg/test1.xcsg
processing solid: rotate_extrude
...completed CSG tree: 0 boolean operations to process.
...Info: rotate_extrude angle>=2*PI implies a torus
...completed boolean operations in 0 [sec]
...result model contains 1 lump.
...lump 1: 21 vertices, 15 polygon faces.
...Polyhedron is water-tight (edge use-count check OK)
 >>> Warning: Polyhedron has 1 zero area faces.
...Polyhedron has 15 non-triangular faces
...Triangulating lump ...
...Triangulation completed with 28 triangle faces in 0 [sec]
...Exporting results
Created STL file     : /media/nas_openbzr/STL/xcsg/test1.stl
xcsg finished using 0h 0m 0.01s

i.e. 28 faces makes sense = 7x3, of which one third will be collapsed, 
due to the way rotate_extrude is implemented.

=====

$ polyfix xcsg/test1.off

Parameters:
   input_file = xcsg/test1.off


polyhedron 0 ================= volume=14.5942, dtol=0.01, atol=1e-06, 
maxiter=10
iteration 0: vertices=21 faces=28
              warning: 14 zero area faces.
              warning: nonmanifold edges: uc(1)=14
              merged 12 vertices
              removed 14 collapsed or zero area faces
              total changes=26
              no warnings

iteration 1: vertices=9 faces=14
              total changes=0
              no warnings

Summary:
              polyhedron 0: vertices=9 faces=14 : no warnings

Writing: xcsg/test1_1.off

=====

Here, polyfix assumes overlapping vertices is undesired and merges them, 
the end result is the same as via OpenSCAD, 14 faces and 9 vertices.



Carsten Arnholm




More information about the Discuss mailing list