2.3. CSG Operations¶
- class raysect.primitive.csg.CSGPrimitive¶
Bases:
raysect.core.scenegraph.primitive.Primitive
Constructive Solid Geometry (CSG) Primitive base class.
This is an abstract base class and can not be used directly.
CSG is a modeling technique that uses Boolean operations like union and intersection to combine 3D solids. For example, the volumes of a sphere and box could be unified with the ‘union’ operation to create a primitive with the combined volume of the underlying primitives.
- Parameters
primitive_a (Primitive) – Component primitive A of the compound primitive.
primitive_b (Primitive) – Component primitive B of the compound primitive.
parent (Node) – Scene-graph parent node or None (default = None).
transform (AffineMatrix3D) – An AffineMatrix3D defining the local co-ordinate system relative to the scene-graph parent (default = identity matrix).
material (Material) – A Material object defining the CSG primitive’s material (default = None).
- class raysect.primitive.csg.Union¶
Bases:
raysect.primitive.csg.CSGPrimitive
CSGPrimitive that is the volumetric union of primitives A and B.
All of the original volume from A and B will be in the new primitive.
- Parameters
primitive_a (Primitive) – Component primitive A of the union operation.
primitive_b (Primitive) – Component primitive B of the union operation.
parent (Node) – Scene-graph parent node or None (default = None).
transform (AffineMatrix3D) – An AffineMatrix3D defining the local co-ordinate system relative to the scene-graph parent (default = identity matrix).
material (Material) – A Material object defining the new CSG primitive’s material (default = None).
Some example code for creating the union between two cylinders.
from raysect.core import rotate, translate from raysect.primitive import Cylinder, Union from raysect.optical import World from raysect.optical.material import AbsorbingSurface world = World() cyl_x = Cylinder(1, 4.2, transform=rotate(90, 0, 0)*translate(0, 0, -2.1)) cyl_y = Cylinder(1, 4.2, transform=rotate(0, 90, 0)*translate(0, 0, -2.1)) csg_union = Union(cyl_x, cyl_y, world, material=AbsorbingSurface(), transform=translate(-2.1, 2.1, 2.5)*rotate(30, -20, 0))
- class raysect.primitive.csg.Intersect¶
Bases:
raysect.primitive.csg.CSGPrimitive
CSGPrimitive that is the volumetric intersection of primitives A and B.
Only volumes that are present in both primtives will be present in the new CSG primitive.
- Parameters
primitive_a (Primitive) – Component primitive A of the intersection operation.
primitive_b (Primitive) – Component primitive B of the intersection operation.
parent (Node) – Scene-graph parent node or None (default = None).
transform (AffineMatrix3D) – An AffineMatrix3D defining the local co-ordinate system relative to the scene-graph parent (default = identity matrix).
material (Material) – A Material object defining the new CSG primitive’s material (default = None).
Some example code for creating the intersection between two cylinders.
from raysect.core import rotate, translate from raysect.primitive import Cylinder, Sphere, Intersect from raysect.optical import World from raysect.optical.material import AbsorbingSurface world = World() cyl_x = Cylinder(1, 4.2, transform=rotate(90, 0, 0)*translate(0, 0, -2.1)) sphere = Sphere(1.5) csg_intersection = Intersect(cyl_x, sphere, world, material=AbsorbingSurface(), transform=translate(-2.1, 2.1, 2.5)*rotate(30, -20, 0))
- class raysect.primitive.csg.Subtract¶
Bases:
raysect.primitive.csg.CSGPrimitive
CSGPrimitive that is the remaining volume of primitive A minus volume B.
Only volumes that are unique to primitive A and don’t overlap with primitive B will be in the new CSG primitive.
- Parameters
primitive_a (Primitive) – Component primitive A of the subtract operation.
primitive_b (Primitive) – Component primitive B of the subtract operation.
parent (Node) – Scene-graph parent node or None (default = None).
transform (AffineMatrix3D) – An AffineMatrix3D defining the local co-ordinate system relative to the scene-graph parent (default = identity matrix).
material (Material) – A Material object defining the new CSG primitive’s material (default = None).
from raysect.core import rotate, translate, Point3D from raysect.primitive import Box, Sphere, Subtract from raysect.optical import World from raysect.optical.material import AbsorbingSurface world = World() cube = Box(Point3D(-1.5, -1.5, -1.5), Point3D(1.5, 1.5, 1.5)) sphere = Sphere(1.75) csg_subtraction = Subtract(cube, sphere, world, material=AbsorbingSurface(), transform=translate(-2.1, 2.1, 2.5)*rotate(30, -20, 0))