public class CSG extends Object
Node.clipTo(Node)
and Node.invert()
,
which remove parts of a BSP tree inside another BSP tree and swap solid and
empty space, respectively. To find the union of a
and b
, we
want to remove everything in a
inside b
and everything in
b
inside a
, then combine polygons from a
and
b
into one solid:
The only tricky part is handling overlapping coplanar polygons in both trees. The code above keeps both copies, but we need to keep them in one tree and remove them in the other tree. To remove them froma.clipTo(b); b.clipTo(a); a.build(b.allPolygons());
b
we can clip the
inverse of b
against a
. The code for union now looks like
this:
Subtraction and intersection naturally follow from set operations. If union isa.clipTo(b); b.clipTo(a); b.invert(); b.clipTo(a); b.invert(); a.build(b.allPolygons());
A | B
, differenceion is A - B = ~(~A | B)
and intersection
is A & B =
~(~A | ~B)
where ~
is the complement operator.Constructor and Description |
---|
CSG(List<Polygon> polygons)
Creates a new CSG file based on the given polygons.
|
Modifier and Type | Method and Description |
---|---|
CSG |
difference(CSG csg)
Return a new CSG solid representing the difference of this csg and the
specified csg.
|
static CSG |
fromPolygons(Polygon... polygons)
Constructs a CSG from the specified
Polygon instances. |
List<Coords3d> |
getPoints()
Get all the points this CSG holds.
|
List<Polygon> |
getPolygons() |
CSG |
intersect(CSG csg)
Return a new CSG solid representing the intersection of this csg and the
specified csg.
|
List<Facet> |
toFacets()
Returns with all the facet this CSG object holds.
|
CSG |
transformed(ITransformation transform)
Returns a transformed copy of this CSG.
|
CSG |
union(CSG csg)
Return a new CSG solid representing the union of this csg and the
specified csg.
|
public static CSG fromPolygons(Polygon... polygons)
Polygon
instances.polygons
- polygonspublic List<Coords3d> getPoints()
public CSG union(CSG csg)
A.union(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +----+ +----+--+ | +----+ | | B | | | | | | | +-------+ +-------+
csg
- other csgpublic CSG difference(CSG csg)
A.difference(B) +-------+ +-------+ | | | | | A | | | | +--+----+ = | +--+ +----+--+ | +----+ | B | | | +-------+
csg
- other csgpublic CSG intersect(CSG csg)
A.intersect(B) +-------+ | | | A | | +--+----+ = +--+ +----+--+ | +--+ | B | | | +-------+ }
csg
- other csgpublic List<Facet> toFacets()
public CSG transformed(ITransformation transform)
transform
- the transform to applyCopyright © 2014–2020, Printing in 3D. All rights reserved.