Constructive Solid Geometry (CSG) is a modeling technique that allows the modeler to create complex geometry using set operations (such as union, intersection, and difference) on primitive objects (such as spheres, cones, and boxes) or other objects created from CSG.
We can create even more complex geometry be performing set operations on other CSG objects and have a CSG tree:
The following algorithms assume that v1 and v2 are non-empty lists of disjoint intervals in ascending order and that rtn is the list to be returned:
This is simply v1 intersected with the complement of v2.
Merge the two lists in ascending order of their lower endpoints. Call
the new list v.
run <- v[0]
for (i = 1; i < v.size; i++)
if run.high < v[i].low
rtn.append(run)
run <- v[i]
else
run <- [run.low, max(run.high, v[i].high)]
rtn.append(run)
i1 <- i2 <- 0
while i1 < v1.size and i2 < v2.size
if v1[i1].high < v2[i2].low
i1++
else if v2[i2].high < v1[i1].low
i2++
else
rtn.append([max(v1[i1].low, v2[i2].low), min(v1[i1].high, v2[i2].high)])
if v1[i1].high < v2[i2].high
i1++
else if v1[i1].high = v2[i2].high
i1++, i2++
else
i2++