## Operations

Now that we have the basic shapes, we need to combine them to create full scenes.

To do so, two basic shapes can be combined with an operation. Two operations can be again combined with an operation etc. This way, a tree builds up representing the final scene.

In this chapter, we just care about the operations and cover union, intersection, difference, negation and scale. They are shown in figure 1, except the scale.

The frayed edges of the difference shows that this implementation of dual marching cubes doesn’t preserve sharp edges.

Wang and Kaufman show the operations union, intersection, difference and negation on the density values in those formulas [WK94, S. 4 – 5]: $f_{a \cup b}(x, y, z) = max(f_a(x, y, z), f_b(x, y, z))$ $f_{a \cap b}(x, y, z) = min(f_a(x, y, z), f_b(x, y, z))$ $f_{a - b}(x, y, z) = min(f_a(x, y, z), 1 - f_b(x, y, z))$ $f_{\bar{a}} = 1 - f(x, y, z)$

It doesn’t seem logical, that the difference is calculated by $1 - f_b(x, y, z)$ and the negation via $1 - f(x, y, z)$ because the resulting density value is changed by 1. That’s why those formulas are changed to this: $f_{a - b}(x, y, z) = min(f_a(x, y, z), -f_b(x, y, z))$ $f_{\bar{a}} = -f(x, y, z)$

Beside the density value, the new gradient has to be calculated in a CSG operation. It is the one of the choosen density function by applying $min()$ or $max()$. For example if $f_a(x, y, z)$ has the greater density value in the union $f_{a \cup b}(x, y, z)$, its gradient is choosen. For the difference with $-f_b(x, y, z)$ being the smaller value, the gradient of $f_b(x, y, z)$ multiplied by -1 is taken.

The last operator is another unary one (taking only one input, beside the union for example taking two inputs), the scaling. It scales its input (whether its a basic shape or a whole CSG tree) by a numerical factor $sf$. First we have to bring the coordinate into the space of the original density function of the input via a division by $sf$. The resulting value is multiplied by $sf$: $f_{s}(x, y, z) = f(\frac{x}{sf}, \frac{y}{sf}, \frac{z}{sf}) \cdot sf$ If you like this work and want to support it, feel free to donate something or click on any Flattr button!