Smooth CSG
SmoothUnion, SmoothIntersection and SmoothDifference blend two objects over a length instead
of meeting at a sharp crease (see Constructive solid geometry). The source is at
Examples/SmoothCSG/main.cpp.
Fig. 19 Sharp operations at the back, smooth ones in front: union, intersection, difference.
Blending
Each smooth function takes the blend length after its operands, and optionally a BlendKind:
const Expr smooth = SmoothUnion(left, right, blend); // BlendKind::Polynomial
const Expr exponential = SmoothUnion(left, right, blend, BlendKind::Exponential);
The polynomial blend changes the value only within a band of the blend length around the crease; the exponential blend changes it everywhere, most near the crease, and rounds the result a little more. Where the two spheres’ surfaces meet the sharp union is zero, and the program prints how far below zero each smooth union is there: the material the blend adds.
Looking at it
The viewer shows the sharp union, intersection and difference in a row at the back, and the smooth ones in front, all in one tape.
The window needs SDL2 and is built with make VIEWER=SDL2 or cmake -DEBGEOMETRY_VIEWER=SDL2 (see
The viewer window (EBGEOMETRY_VIEWER)); otherwise, and with --no-view or without a display, view() prints why
and returns. Drag to orbit and scroll to zoom; the window lists its other keys (see
The viewer’s keys).
Building and running
See Building for how to compile it with CMake, GNU Make, or a direct compiler invocation. Built for a GPU (see Running on a GPU), the window renders on the device.
cd Examples/SmoothCSG
./SmoothCSG.ex