## Rounded Rectangles in OpenSCAD: Mold Positives?

A discussion on the OpenSCAD mailing list about making a rectangular solid with rounded edges having different radii eventually produced this delightful result:

Those guys make me feel dumb, because they’re generally solving problems I can’t even imagine, but I know what to do with this solution. One could slice it in half horizontally, emboss a height map defining a logo / picture into the top surface, print it out on your favorite 3D printer, maybe smooth / seal the surface a bit, define it to be a positive mold pattern, cast / pour flexible silicone around it, and get a negative mold for a pourable precious material such as, oh, chocolate.

You could make half a dozen of them, arrange them inside a suitable printed frame, pour the silicone, and get a multi-cavity mold for better manufacturing productivity.

The overall block lacks draft, because the problem it solves presumes you need a block of specific outside dimensions: it overlays three full-size rectangular blocks that define the dimensions. OpenSCAD constructs spheres such that they may be slightly smaller than the defined radius at the poles and, depending on their alignment, a face at the equator may reduce the outer dimension of a surrounding hull.

Given a sufficiently bendy silicone mold, you might not need any draft at all. If you do need draft and you don’t care about a very slightly undersized pattern, remove the internal blocks and increase the XY spacing of the lower four spheres by enough to make the draft come out right.

The grayscale logo / image should have nice smooth transitions that produce suitable draft for the fine details; a bare black-and-white image might not work well. Shallow is good, but that conflicts with 3D printing’s crappy resolution: 1 mm = 10 layers, tops. That might not matter in practice.

You’re supposed to temper the chocolate, but that’s probably more relevant for Fine Art molds.

The (slightly modified) OpenSCAD source code:

```module rcube(size=[30, 20, 10], radius=[3, 2, 1], center=true)
hull() {
translate( center ? [0,0,0] : size/2 ) {
cube(size-2*radius+[2*radius[0],0,0],center=true);
cube(size-2*radius+[0,2*radius[1],0],center=true);
cube(size-2*radius+[0,0,2*radius[2]],center=true);

for(x = [-0.5,0.5], y = [-0.5,0.5], z = [-0.5,0.5])
translate([x * ( size[0] - 2*radius[0]),
y * ( size[1] - 2*radius[1]),
z * ( size[2] - 2*radius[2])])
scale([radius[0], radius[1], radius[2]])
sphere(1.0,\$fn=4*4);
}
}

rcube();
```

When I get around to doing molds, maybe I can remember what I was thinking…