openscad

OpenSCAD: Add spheric indents to a box


I created a box using "boxes.scad". I subtracted a slightly thinner box to create a hollow one. Now i want to create spherical indents on the box (see picture), but if i subtract a sphere from the box i just get a hole. How can one create the indents like in the picture? Box made in Blender


Solution

  • If I understand your problem correctly, what you have now is on the right of this image and what you need is on the left :

    problem

    Then what you can do is to subtract a slightly bigger sphere from the slightly thinner box before doing the main subtraction. Here is an example of what I mean :

    a = 16;
    b = 1;
    c = 12;
    d = 6;
    difference(){ // main subtraction
        cube(a, center = true); // slightly bigger box
        
        difference(){
            cube([a - 2 * b, a - 2 * b, 2 * a], center = true); // slightly thinner box
            
            translate([c, 0, 0])
            sphere(d + b); // slightly bigger sphere
        }
        
        translate([c, 0, 0])
        sphere(d); // slightly smaller sphere
        
        translate([0, a, 0])
        cube(2 * a, center = true); // cube that hides half of the result just to see better
    }
    

    Note that the two spheres have the same translation and the difference between their radii is simply the thickness of the wall.