<p>I'm trying to subtract a polyhedron from a cube, but it is not working (the cube remains solid). However, I can see the cut-out poly in preview mode (but not after a full render).</p>
<p><strong>Preview</strong> -- poly cutout shows on the top (and bottom).</p>
<p><a href="https://i.stack.imgur.com/Zk1Z5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zk1Z5.png" alt="preview" /></a></p>
<p><strong>Rendered</strong> -- poly cutout not visible.</p>
<p><a href="https://i.stack.imgur.com/cofDh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cofDh.png" alt="rendered" /></a></p>
<p><strong>Poly Exploded</strong> -- pulled the poly to the right to show its shape.</p>
<p><a href="https://i.stack.imgur.com/VILrM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VILrM.png" alt="poly exploded" /></a></p>
<p><strong>Code</strong></p>
<pre><code>size = 30;
wall = 3;
wall_x2 = wall * 2;
nubGap = .125;
nubHeight = 8;
nubOffset = wall + nubGap;
xCutoutSize = size - wall_x2;
yCutoutSize = size - wall_x2;
cutoutLowerY = nubHeight + nubGap;
cutoutUpperOffset = nubOffset + wall;
    
difference() {
    cube([size, size, size]);
    
    translate([wall, wall, 0]) {
        polyhedron(
            points = [
                [0, 0, -10],
                [xCutoutSize, 0, -10],
                [xCutoutSize, yCutoutSize, -10],
                [0, yCutoutSize, -10],
        
                [0, 0, cutoutLowerY],
                [xCutoutSize, 0, cutoutLowerY],
                [xCutoutSize, yCutoutSize, cutoutLowerY],
                [0, yCutoutSize, cutoutLowerY],
        
                [cutoutUpperOffset, cutoutUpperOffset, size],
                [xCutoutSize - cutoutUpperOffset, cutoutUpperOffset, size],
                [xCutoutSize - cutoutUpperOffset, yCutoutSize - cutoutUpperOffset, size],
                [cutoutUpperOffset, yCutoutSize - cutoutUpperOffset, size]
            ],
            faces = [
                [0, 1, 2], [2, 3, 0],     // bottom
                
                [0, 1, 4], [1, 4, 5],     // side A
                [1, 2, 5], [2, 5, 6],     // side B
                [2, 3, 6], [3, 6, 7],     // side C
                [3, 0, 7], [0, 7, 4],     // side D
                
                [4, 5,  8], [5,   8,  9], // slope A
                [5, 6,  9], [6,   9, 10], // slope B
                [6, 7, 10], [7,  10, 11], // slope C
                [7, 4, 11], [4,  11,  8], // slope D
                
                [8, 9, 10], [10, 11,  8]  // top
            ]
        );
    };
};
</code></pre>

[{'answer_id': 14893, 'author': 'R.. GitHub STOP HELPING ICE', 'author_id': 11157, 'author_profile': 'https://3dprinting.stackexchange.com/users/11157', 'pm_score': 2, 'selected': False, 'text': "<p>If the polyhedron surface and top surface of the cube are exactly coplanar, which they seem to be, it won't work; OpenSCAD operates numerically rather than analytically and which is &quot;inside&quot; or &quot;outside&quot; the other is subject to numerical instability. Whenever using differences you need to make the object being subtracted extend by at least some small epsilon outside the surfact of the object you're subtracting from.</p>\n"}, {'answer_id': 14895, 'author': 'fred_dot_u', 'author_id': 854, 'author_profile': 'https://3dprinting.stackexchange.com/users/854', 'pm_score': 3, 'selected': True, 'text': '<p>Usually when there\'s an overlap in two objects during a difference action, F6 render will resolve the problem. There\'s something more than that involved here, as reducing the height of the cube creates a non-manifold object from the difference. user R..\'s answer has merit but is not going to solve the problem.</p>\n<p>Isolating the cube from the code and exporting the result as an STL allows me to determine that the faces are generated in a manner preventing a proper difference action:</p>\n<p><a href="https://i.stack.imgur.com/QEtXM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QEtXM.png" alt="meshmixer image" /></a></p>\n<p>This image from meshmixer shows the faces have inverted normals. The order of the points are critical when describing a polyhedron. From the wiki page for <a href="https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#polyhedron" rel="nofollow noreferrer">OpenSCAD</a>:</p>\n<blockquote>\n<p>It is arbitrary which point you start with, but all faces must have\npoints ordered in the same direction . OpenSCAD prefers clockwise when\nlooking at each face from outside inward. The back is viewed from the\nback, the bottom from the bottom, etc. Another way to remember this\nordering requirement is to use the right-hand rule. Using your\nright-hand, stick your thumb up and curl your fingers as if giving the\nthumbs-up sign, point your thumb into the face, and order the points\nin the direction your fingers curl.</p>\n</blockquote>\n<p>EDIT: I reversed some of the points, haphazardly and luckily picked the correct ones:</p>\n<pre><code>        faces = [\n            [0, 1, 2], [2, 3, 0],     // bottom\n            \n            [4, 1, 0], [1, 4, 5],     // side A\n            [5, 2, 1], [2, 5, 6],     // side B\n            [6, 3, 2], [3, 6, 7],     // side C\n            [7, 0, 3], [0, 7, 4],     // side D\n            \n            [8, 5, 4], [5,   8,  9], // slope A\n            [9, 6, 5], [6,   9, 10], // slope B\n            [10, 7, 6], [7,  10, 11], // slope C\n            [11, 4, 7], [4,  11,  8], // slope D\n            \n            [10, 9, 8], [8, 11, 10]  // top\n</code></pre>\n<p><a href="https://i.stack.imgur.com/GWBMo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GWBMo.png" alt="rendered code" /></a></p>\n'}]
['https://3dprinting.stackexchange.com/questions/14892', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/25482/']