polyhedron with cube not valid 2-manifold

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

polyhedron with cube not valid 2-manifold

dknell
Hello,

I have a simple polyhedron and I'm trying to attach a cube to it. My code is below.

The preview looks like this:


The render looks like this:


If I remove the cube, it renders fine:


I've read a bunch of posts regarding this subject on the OpenSCAD forums and a few other places and I can't seem to figure out why my object is not rendering correctly.

If anyone can shed some light, I'd really appreciate it.

Here is my code:
$fn = 180;

size = 34;

side_a = size * sin(45);
side_b = size * cos(45);
side_c = size * tan(45);
tri_top_0 = [0,0,0];
tri_top_1 = [side_b,0,0];
tri_top_2 = [0,-side_a,0];
tri_bot_3 = [0,0,size];
tri_bot_4 = [side_b,0,size];
tri_bot_5 = [0,-side_a,size];

show_mount_plate = false;
mount_plate_thickness = 5;

union() {
    polyhedron(
      points=[ 
        tri_top_0, tri_top_1, tri_top_2,
        tri_bot_3, tri_bot_4, tri_bot_5,
      ], 
      faces=[ [0,1,2], [3,4,5], [0,1,4,3], [1,2,5,4], [2,0,3,5] ]
     );
    
    if (show_mount_plate == true) {
        translate([0,-side_b,0])
            rotate([0,0,-45])
                cube([mount_plate_thickness, size, size]);
    }
}


Reply | Threaded
Open this post in threaded view
|

Re: polyhedron with cube not valid 2-manifold

Peter Falke

Most likely there are wrongly orientated triangles:

Have a look here: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids

Let's now see how to fix polyhedrons with badly oriented polygons. When you select 'Thrown together' from the view menu and compile the design (not compile and render!) you will see a preview with the mis-oriented polygons highlighted. Unfortunately this highlighting is not possible in the OpenCSG preview mode because it would interfere with the way the OpenCSG preview mode is implemented.)

Below you can see such a problematic polyhedron, bad triangles are in pink.


2016-02-15 0:17 GMT+01:00 dknell <[hidden email]>:
Hello,

I have a simple polyhedron and I'm trying to attach a cube to it. My code is
below.

The preview looks like this:
<http://forum.openscad.org/file/n16132/img1.png>

The render looks like this:
<http://forum.openscad.org/file/n16132/img2.png>

If I remove the cube, it renders fine:
<http://forum.openscad.org/file/n16132/img3.png>

I've read a bunch of posts regarding this subject on the OpenSCAD forums and
a few other places and I can't seem to figure out why my object is not
rendering correctly.

If anyone can shed some light, I'd really appreciate it.

Here is my code:







--
View this message in context: http://forum.openscad.org/polyhedron-with-cube-not-valid-2-manifold-tp16132.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: polyhedron with cube not valid 2-manifold

jpmendes

Hey

Check this.

Code:    
 
$fn = 180;

size = 34;

side_a = size * sin(45);
side_b = size * cos(45);
side_c = size * tan(45);
tri_top_0 = [0,0,0];
tri_top_1 = [side_b,0,0];
tri_top_2 = [0,-side_a,0];
tri_bot_3 = [0,0,size];
tri_bot_4 = [side_b,0,size];
tri_bot_5 = [0,-side_a,size];

show_mount_plate = true;

mount_plate_thickness = 5;

union() {
    polyhedron(
      points=[
        tri_top_0, tri_top_1, tri_top_2,
        tri_bot_3, tri_bot_4, tri_bot_5,
      ],
     // faces=[ [0,1,2], [3,4,5], [0,1,4,3], [1,2,5,4], [2,0,3,5] ]
     faces=[ [1,0,2], [3,4,5], [1,2,5,4], [0,3,5,2] , [0,1,4,3 ] ]
     );
   
    if (show_mount_plate == true) {
        translate([0,-side_b,0])
            rotate([0,0,-45])
                cube([mount_plate_thickness, size, size]);
    }
}


jpmendes
Reply | Threaded
Open this post in threaded view
|

Re: polyhedron with cube not valid 2-manifold

dknell
Thanks for the help jpmendes and peter!

I was just reading about the "Point ordering for faces" in the manual and it looks like my problem was with the order of points in the bottom triangle going counter-clockwise instead of clockwise.

Thanks so much for the tips!
Reply | Threaded
Open this post in threaded view
|

Re: polyhedron with cube not valid 2-manifold

jpmendes
In reply to this post by jpmendes
Hey

In fact it is sufficient to change the order of the points of the bottom triangle only:

  faces=[ [1,0,2], [4,3,5], [0,1,4,3], [1,2,5,4], [2,0,3,5] ] );

Can anybody explain why?

Thanks

jpmendes
Reply | Threaded
Open this post in threaded view
|

Re: polyhedron with cube not valid 2-manifold

dknell
According to the documentation, “ When looking at the face from the outside inwards, the points must be clockwise”. I incorrectly oriented the bottom triangle by looking from the inside outward. 


On Feb 14, 2016, at 8:34 PM, jpmendes [via OpenSCAD] <[hidden email]> wrote:

Hey

In fact it is sufficient to change the order of the points of the bottom triangle only:

  faces=[ [1,0,2], [4,3,5], [0,1,4,3], [1,2,5,4], [2,0,3,5] ] );

Can anybody explain why?

Thanks

jpmendes


If you reply to this email, your message will be added to the discussion below:
http://forum.openscad.org/polyhedron-with-cube-not-valid-2-manifold-tp16132p16139.html
To unsubscribe from polyhedron with cube not valid 2-manifold, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: polyhedron with cube not valid 2-manifold

jpmendes
In reply to this post by jpmendes
Ok, I read the manual.

However I can't understand why this have to be this way. I do not imagine me spending a lot of time making a complex polyhedron from points and having to care about the order of points for each face.
I think that the language should infer the correct order and rearrange the points order internally if necessary to avoid crashing or the type of issues above.
As a minimum, an error message should be echoed reporting the faces with problems.

jpmendes