One polyhedron works but two fails

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

One polyhedron works but two fails

Leea
I have two identical polyhedrons that do not touch. If I comment out either
one it will render just fine. But with both it fails render. I can't figure
out why. My searching would indicate a face issue but then should it fail on
just one of them. Must be some stupid typo and I have stared at it.

 translate ([95.9,10,0])

    polyhedron (
    points = [
    [0,0,0],
    [7,0,0],
    [0,0,6],
    [0,1,0],
    [7,1,0],
    [0,1,6]
    ],
    faces = [
    [0,1,4,3],  //bot
    [0,1,2], //side
    [3,4,5], // side
    [1,2,5,4], //angle
    [0,2,5,3], //back
    ]);

    translate ([95.9,24,0])

    polyhedron (
    points = [
    [0,0,0],
    [7,0,0],
    [0,0,6],
    [0,1,0],
    [7,1,0],
    [0,1,6]
    ],
    faces = [
    [0,1,4,3],  //bot
    [0,1,2], //side
    [3,4,5], // side
    [1,2,5,4], //angle
    [0,2,5,3], //back
    ]);

thanks much
Lee




--
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: One polyhedron works but two fails

acwest
If there is only one polyhedron, it is rendered with opengl, if there is more than one I believe it uses opencsg. I had the same problem myself, it turned out one of my faces was backwards

On Sun, 9 Jun 2019, 11:09 Leea, <[hidden email]> wrote:
I have two identical polyhedrons that do not touch. If I comment out either
one it will render just fine. But with both it fails render. I can't figure
out why. My searching would indicate a face issue but then should it fail on
just one of them. Must be some stupid typo and I have stared at it.

 translate ([95.9,10,0])

    polyhedron (
    points = [
    [0,0,0],
    [7,0,0],
    [0,0,6],
    [0,1,0],
    [7,1,0],
    [0,1,6]
    ],
    faces = [
    [0,1,4,3],  //bot
    [0,1,2], //side
    [3,4,5], // side
    [1,2,5,4], //angle
    [0,2,5,3], //back
    ]);

    translate ([95.9,24,0])

    polyhedron (
    points = [
    [0,0,0],
    [7,0,0],
    [0,0,6],
    [0,1,0],
    [7,1,0],
    [0,1,6]
    ],
    faces = [
    [0,1,4,3],  //bot
    [0,1,2], //side
    [3,4,5], // side
    [1,2,5,4], //angle
    [0,2,5,3], //back
    ]);

thanks much
Lee




--
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: One polyhedron works but two fails

adrianv
In reply to this post by Leea
You have backwards faces.  Use the "thrown together" option as suggested my
the manual and you will see them in purple.  



--
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: One polyhedron works but two fails

acwest
I didn't know it did that, that's cool. I wrote a library function to show the normals of the faces of my polyhedrons

On Sun, 9 Jun 2019, 11:17 adrianv, <[hidden email]> wrote:
You have backwards faces.  Use the "thrown together" option as suggested my
the manual and you will see them in purple. 



--
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: One polyhedron works but two fails

discuss
In reply to this post by Leea
Not sure what’s wrong, but easy fix is:

module OBJ()
   polyhedron (
   points = [
   [0,0,0],
   [7,0,0],
   [0,0,6],
   [0,1,0],
   [7,1,0],
   [0,1,6]
   ],
   faces = [
   [0,1,4,3],  //bot
   [0,1,2], //side
   [3,4,5], // side
   [1,2,5,4], //angle
   [0,2,5,3], //back
   ]);

translate ([95.9,10,0]) OBJ();

translate ([95.9,24,0]) OBJ();

The preview works fine, but the rendering warns
that the object is not a valid 2-manifold. it is missing one face.


 CGAL cache size in bytes: 23200
Total rendering time: 0 hours, 0 minutes, 0 seconds
Top level object is a 3D object:
Simple: no
Vertices: 12
Halfedges: 32
Edges: 16
Halffacets: 12
Facets: 6
Volumes: 1
WARNING: Object may not be a valid 2-manifold and may need repair!
Rendering finished.


> On Jun 9, 2019, at 11:08 AM, Leea <[hidden email]> wrote:
>
> I have two identical polyhedrons that do not touch. If I comment out either
> one it will render just fine. But with both it fails render. I can't figure
> out why. My searching would indicate a face issue but then should it fail on
> just one of them. Must be some stupid typo and I have stared at it.
>
> translate ([95.9,10,0])
>
>    polyhedron (
>    points = [
>    [0,0,0],
>    [7,0,0],
>    [0,0,6],
>    [0,1,0],
>    [7,1,0],
>    [0,1,6]
>    ],
>    faces = [
>    [0,1,4,3],  //bot
>    [0,1,2], //side
>    [3,4,5], // side
>    [1,2,5,4], //angle
>    [0,2,5,3], //back
>    ]);
>
>    translate ([95.9,24,0])
>
>    polyhedron (
>    points = [
>    [0,0,0],
>    [7,0,0],
>    [0,0,6],
>    [0,1,0],
>    [7,1,0],
>    [0,1,6]
>    ],
>    faces = [
>    [0,1,4,3],  //bot
>    [0,1,2], //side
>    [3,4,5], // side
>    [1,2,5,4], //angle
>    [0,2,5,3], //back
>    ]);
>
> thanks much
> Lee
>
>
>
>
> --
> 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
tp3
Reply | Threaded
Open this post in threaded view
|

Re: One polyhedron works but two fails

tp3
The only way to fix this is to flip the 2 faces with wrong
winding order:

   faces = [
   [0,1,4,3],  //bot
   [0,2,1], //side      <-- this one
   [3,4,5], // side
   [1,2,5,4], //angle
   [3,5,2,0], //back    <-- and that one
   ])

ciao,
  Torsten.

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

Re: One polyhedron works but two fails

Leea
In reply to this post by acwest
Thanks guys.
I was leery of polyhedrons before and now I think I am afraid. At least I
know why my test one worked and then why my duplicate failed. I am printing
my part right now.
Is there a technique for when they get complicated to keep them orientated
correctly.
Lee




--
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: One polyhedron works but two fails

acwest
Mostly make sure they are all consistently clockwise or consistently counterclockwise as seen from the outside

On Sun, 9 Jun 2019, 12:23 Leea, <[hidden email]> wrote:
Thanks guys.
I was leery of polyhedrons before and now I think I am afraid. At least I
know why my test one worked and then why my duplicate failed. I am printing
my part right now.
Is there a technique for when they get complicated to keep them orientated
correctly.
Lee




--
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: One polyhedron works but two fails

adrianv
In reply to this post by Leea
It can be pretty tricky, especially if constructing a polyhedron by hand, to
ensure that all of the faces are in the correct orientation.  My suggestions
are first, don't use polyhedron() when a simpler method exists.  In your
case, you could have made the triangle with polygon() and used
linear_extrude().  

Second, define your problem in a general way and write a routine that makes
the general polyhedron type you need automatically.  Doing things in a
general way with an algorithm rather than by hand may make it easier to
ensure that edges are correctly flipped.  And if they aren't you only have
to debug your code once.   Or consider using libraries written by others
(e.g. BOSL or dotSCAD) that implement the thing you need, so somebody else
has figured out the orientation.  

Thirdly, if your polyhedron is convex then just define its vertices and make
the faces using a convex hull, either Linde's hull or the hack below, which
makes a bogus polyhedron from your vertex list and then makes a real shape
by computing the convex hull.  

https://github.com/OskarLinde/scad-utils/blob/master/hull.scad

module fastpointhull(points){
    extra = len(points)%3;
    list = concat(
                [[for(i=[0:extra+2])i]],
                [for(i=[extra+3:3:len(points)-3])[i,i+1,i+2]]);
    hull() polyhedron(points, faces=list);
}




--
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: One polyhedron works but two fails

boxcarmib
Thanks for bring up the hull.scad code from scad-utils… unfortunately it’s older code now and generates some warnings…

DEPRECATED: The assign() module will be removed in future releases. Use a regular assignment instead. in file hull.scad, line 308
WARNING: len() parameter could not be converted, in file hull.scad, line 303
WARNING: len() parameter could not be converted, in file hull.scad, line 303
WARNING: len() parameter could not be converted, in file hull.scad, line 303
WARNING: len() parameter could not be converted, in file hull.scad, line 303
WARNING: len() parameter could not be converted, in file hull.scad, line 303
Compiling design (CSG Products generation)...
WARNING: PolySet has degenerate polygons
WARNING: PolySet has degenerate polygons


Fairly easy to fix the assign deprecation… and I I think I solved the len() parameter warning by substituting is_list for the tests on line 303…
BUT fixing all of those doesn’t make the

WARNING: PolySet has degenerate polygons

Go away… can anyone familiar with this code point me in the right direction?


On Jun 9, 2019, at 9:41 AM, adrianv <[hidden email]> wrote:

It can be pretty tricky, especially if constructing a polyhedron by hand, to
ensure that all of the faces are in the correct orientation.  My suggestions
are first, don't use polyhedron() when a simpler method exists.  In your
case, you could have made the triangle with polygon() and used
linear_extrude().   

Second, define your problem in a general way and write a routine that makes
the general polyhedron type you need automatically.  Doing things in a
general way with an algorithm rather than by hand may make it easier to
ensure that edges are correctly flipped.  And if they aren't you only have
to debug your code once.   Or consider using libraries written by others
(e.g. BOSL or dotSCAD) that implement the thing you need, so somebody else
has figured out the orientation.  

Thirdly, if your polyhedron is convex then just define its vertices and make
the faces using a convex hull, either Linde's hull or the hack below, which
makes a bogus polyhedron from your vertex list and then makes a real shape
by computing the convex hull.  

https://github.com/OskarLinde/scad-utils/blob/master/hull.scad

module fastpointhull(points){
   extra = len(points)%3;
   list = concat(
               [[for(i=[0:extra+2])i]],
               [for(i=[extra+3:3:len(points)-3])[i,i+1,i+2]]);
   hull() polyhedron(points, faces=list);
}




--
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: One polyhedron works but two fails

adrianv
There is a version of hull in BOSL:

https://github.com/revarbat/BOSL/wiki/convex_hull.scad




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

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