Quantcast

difference of 2 polyhedrons returns 2 planar shape - is this a bug?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

difference of 2 polyhedrons returns 2 planar shape - is this a bug?

bobbywong
This post has NOT been accepted by the mailing list yet.

I have the following OpenSCAD code:

difference(){


polyhedron(
        points = [
                //0, 1, 2, 3,
                [000.0, 000.0, 000.0], [100.0, 000.0, 000.0], [100.0, 100.0, 000.0], [000.0, 100.0, 000.0],
                //4, 5, 6, 7
                [000.0-020.5, 000.0-020.5, 050.0], [100.0+020.5, 000.0-020.5, 050.0], [100.0+020.5, 100.0+020.5, 050.0], [000.0-020.5, 100.0+020.5, 050]
                ],
        faces = [
                [0,1,2,3],
                [0,1,5,4], [1,2,6,5],
                [2,3,7,6], [3,0,4,7],
                [4,5,6,7]
                ],
        convexity = 1);


translate([000.0, 000.0, 010.0]) {
polyhedron(
        points = [
                //0, 1, 2, 3,
                [000.0, 000.0, 000.0], [100.0, 000.0, 000.0], [100.0, 100.0, 000.0], [000.0, 100.0, 000.0],
                //4, 5, 6, 7
                [000.0-000.0, 000.0-000.0, 050.0], [100.0+000.0, 000.0-000.0, 050.0], [100.0+000.0, 100.0+000.0, 050.0], [000.0-000.0, 100.0+000.0, 050]
                ],
        faces = [
                [0,1,2,3],
                [0,1,5,4], [1,2,6,5],
                [2,3,7,6], [3,0,4,7],
                [4,5,6,7]
                ],
        convexity = 1);
};

}

I expect an indent into the first polyhedron.  

But I got the following planar shapes.   Is this a bug or there is a mistake in my code?



If I do a sum, the result is as expected.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: difference of 2 polyhedrons returns 2 planar shape - is this a bug?

droftarts
It's because the faces of your polyhedron are inside out. If you view in 'Thrown Together' mode, and view each polyhedron individually, you'll see that they are mostly purple. This means the 'normal' of the face is pointing the wrong way. From https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#polyhedron :
"All faces must have points ordered in the same direction . OpenSCAD prefers clockwise when looking at each face from outside inwards. The back is viewed from the back, the bottom from the bottom, etc.."
So you just need to reorder each face in the 'faces' part of each polyhedron, to get the faces so the purple is 'inwards', and the yellow is outwards.

Ian
Loading...