Search code examples
openscad

why difference function does not work (openSCAD)?


I try to learn how to use openSCAD. I 'm reading (also watching) a lot of tutorials but I cannot get why the following code does not work. Could you please help me?

difference() {

     polygon(
             points=[[2,0],[1.6,2.6],[2.2,3.4],[5.6,4],[11.4,3.4],[11.4,0.6],[10,-1.6],[7.6,-2.4],[4.4,-1.8]]);

     polygon(// right len holder in

             points=[[2.4,0],[2,2.6],[2.5,3.1],[5.6,3.6],[11,3],[11,0.6],[9.8,-1.2],[7.6,-2],[4.4,-1.45]]);}

Solution

  • your top level object is a 2D-object, use linear_extrude to get 3D-objects:

    h = 10;
    difference() {
        linear_extrude(height=h) polygon(
             points=[[2,0],[1.6,2.6],[2.2,3.4],[5.6,4],[11.4,3.4],[11.4,0.6],[10,-1.6],[7.6,-2.4],[4.4,-1.8]]);
    
         linear_extrude(height=h) polygon(// right len holder in
    
             points=[[2.4,0],[2,2.6],[2.5,3.1],[5.6,3.6],[11,3],[11,0.6],[9.8,-1.2],[7.6,-2],[4.4,-1.45]]);
    

    }