Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 1.92 KB

csg.md

File metadata and controls

97 lines (73 loc) · 1.92 KB

CSG

CSG Operations

There are three binary csg operations which can construct extremely complex objects from very simple primitives: union (\cup), intersection (\cap) and subtraction (i.e. difference).

This diagram shows the basic idea: CSG Tree visualization

The code for this in our system would look this this:

using OpticSim # hide
cyl = Cylinder(0.7)
cyl_cross = cyl ∪ leaf(cyl, Geometry.rotationd(90, 0, 0)) ∪ leaf(cyl, Geometry.rotationd(0, 90, 0))

cube = Cuboid(1.0, 1.0, 1.0)
sph = Sphere(1.3)
rounded_cube = cube ∩ sph

result = rounded_cube - cyl_cross
Vis.draw(result, numdivisions=100)

Vis.save("assets/csg_ex.png"); nothing # hide

CSG code example image

leaf
∪
∩
-

Pre-made CSG Shapes

There are also some shortcut methods available to create common CSG objects more easily:

BoundedCylinder
Cuboid
HexagonalPrism
RectangularPrism
TriangularPrism
Spider

CSG Types

These are the types of the primary CSG elements, i.e. the nodes in the CSG tree.

OpticSim.CSGTree
OpticSim.CSGGenerator
OpticSim.ComplementNode
OpticSim.UnionNode
OpticSim.IntersectionNode
OpticSim.LeafNode

Additional Functions and Types

These are the internal types and functions used for geometric/CSG operations.

Functions

surfaceintersection(::CSGTree{T}, ::AbstractRay{T,N}) where {T<:Real,N}
inside(a::CSGTree{T}, x::T, y::T, z::T) where {T<:Real}
onsurface(a::CSGTree{T}, x::T, y::T, z::T) where {T<:Real}

Intervals

Interval
EmptyInterval
DisjointUnion
OpticSim.isemptyinterval
OpticSim.ispositivehalfspace
OpticSim.israyorigininterval
OpticSim.halfspaceintersection
OpticSim.closestintersection
OpticSim.IntervalPool

Intersections

OpticSim.IntervalPoint
RayOrigin
Infinity
Intersection
OpticSim.isinfinity
OpticSim.israyorigin