Booleans

Occt category icon with logo interpretation

Intro

Booleans are operations that are used to combine two or more shapes. There are three common types of boolean operations: union, difference, and intersection. Union is used to combine two or more shapes into one. Difference is used to subtract one shape from another. Intersection is used to keep only the common part of two or more shapes.

Union

Union is used to combine two or more shapes into one. The shapes must intersect one another. If no intersection is found union can not be constructed. Check out the picture below how unioned vs non-unioned shapes look like. Notice how unioned result gain additional edges, which delimit the faces of a newly created solid. This solid does not have intersecting faces. Edges of such solid can be filleted or chamfered.

Image showing how non-unioned result of 3 solids looks like

Non-unioned result of 3 solids

Image showing how unioned result of 3 solids looks like

Unioned result of 3 solids

In the following scripts we create three solids - a box, a cylinder and a sphere. We then apply a union operation to them. Below you will find the TypeScript, Rete and Blockly code examples:

TypeScript

Union three solids

Blockly

Union three solids

Rete

Union three solids

Difference

Difference is used to subtract one shape from another. The shapes must intersect one another. If no intersection is found difference can not be constructed. Check out the picture below how difference looks like. Notice how the result of the difference operation is a solid with cylinder and sphere subtracted from the box.

Image showing how 3 shapes look like before difference is applied

Before difference is computed

Image showing how shapes look like when difference is applied on the box and cylinder with sphere are subtracted

After difference is computed

Difference is a negative variant of union. It takes in a shape from which other shapes should be subtracted. You can use as many shapes as you'd like, but performance may suffer eventually. Check out these examples of TypeScript, Rete and Blockly code:

TypeScript

Difference of solids

Blockly

Difference of solids

Rete

Difference of solids

Intersection

Intersections leave the common part and discards the rest. The shapes must intersect one another. If no intersection is found intersection can not be constructed. Check out the picture below how intersection looks like. Notice how the result of the intersection operation is compound shape made out of two solids with only the common part of the box, bouned by the cylinder and sphere remainders.

Image showing how 3 shapes look like before intersection is applied

Before intersection is computed

Image showing how shapes look like when intersection is applied between the box and cylinder with sphere

After intersection is computed

Here you can find the scripts that create a solid box, a cylinder and a sphere and apply an intersection operation to them. Below you will find the TypeScript, Rete and Blockly code examples:

TypeScript

Intersection of solids

Blockly

Intersection of solids

Rete

Intersection of solids

Note on shape types

You can apply boolean operations on any type of shape. It is possible to union two overlaping faces. It is also possible to union two wires that share common point into one. It is also possible to use difference and intersection on these shapes. Depending on the shape type, the result of the boolean operation will be different. For example, if you union two faces, the result will be a new face. If you union two wires, the result will be a new wire.

Note on performance

While boolean commands often seem like a simple operation, they can be quite complex and computationally expensive. It is often very tempting to use booleans due to their simplicity, but we advise to try and avoid them when possible. For simple geometries boolean operations will be fast and perform well, but when complexity of geometry grows they will rapidly decrease the performance of the application. It is often better to use other methods that create solids from their composite parts.