How CSG Trees Work in Computer Aided Design

Constructive Solid Geometry (CSG) is a fundamental modeling method in Computer Aided Design (CAD) that constructs complex three-dimensional objects by combining simple shapes using geometric operations. This article explains how CSG trees function, breaking down the hierarchical tree structure, the role of primitive shapes and Boolean operators, and how CAD engines process these data trees to evaluate, edit, and render solid 3D models.

The Structure of a CSG Tree

At its core, a CSG model is organized as a binary tree data structure. A binary tree consists of nodes arranged in a parent-child hierarchy, where each parent node branches into at most two child nodes.

  • Leaf Nodes (Primitives): The leaves at the bottom of the tree represent basic geometric primitives. These are analytically defined shapes such as cubes, cylinders, spheres, cones, and prisms. Each primitive contains parameter data defining its size, position, and orientation in space.
  • Internal Nodes (Operators): The interior nodes of the tree represent Boolean operations or spatial transformations (like translation, rotation, and scaling).
  • The Root Node: The single node at the very top of the tree represents the final, fully assembled 3D object.

Core Boolean Operations

The CAD engine builds geometry by applying Boolean operations at the internal nodes. These operations determine how the spatial volumes of two child nodes interact:

  1. Union (\(A \cup B\)): Combines the volumes of object \(A\) and object \(B\) into a single continuous shape. Overlapping internal geometry is merged and eliminated.
  2. Difference (\(A - B\)): Subtracts the volume of object \(B\) from object \(A\). This operation is commonly used to create holes, slots, or cutouts (for example, subtracting a cylinder from a cube to create a drilled block).
  3. Intersection (\(A \cap B\)): Preserves only the volume that object \(A\) and object \(B\) share in common. Any space not occupied by both shapes simultaneously is discarded.

How the Tree is Evaluated

To display or manufacture an object, the CAD system must evaluate the tree from the bottom up (a post-order traversal):

  1. Parameter Assignment: The engine references the leaf nodes to generate the defined mathematical primitives with their assigned transformations.
  2. Sequential Merging: Moving up one level, the software applies the specified Boolean operations between pairs of primitives to create intermediate composite shapes.
  3. Root Resolution: The process repeats up through the branches until it reaches the root node, producing the final boundary of the solid object.

In modern CAD systems, this CSG tree is often converted during evaluation into a Boundary Representation (B-Rep) model, which explicitly calculates the vertices, edges, and faces for real-time viewport rendering and export.

Key Benefits in CAD Workflows

  • Parametric and Non-Destructive Editing: Because the CSG tree preserves the full history of operations, a user can modify a dimension on an initial primitive leaf node at any time. The CAD engine then recalculates the tree upward to update the final part without requiring manual rebuilding.
  • Guaranteed Solid Geometry: CSG operations are mathematically closed on solid volumes. This means the resulting models are always "watertight" (manifold) with well-defined interiors and exteriors, eliminating geometric errors like inverted normals or non-closed surfaces that disrupt 3D printing and CNC machining.
  • Compact File Sizes: Storing a CSG tree requires only the mathematical definitions of primitives and the operation sequence, making the native file structure significantly smaller than polygon mesh files that store thousands of individual surface coordinates.