Пример #1
0
    // Return a new CSG solid representing space both this solid and in the
    // solid `csg`. Neither this solid nor the solid `csg` are modified.
    //
    //     A.intersect(B)
    //
    //     +-------+
    //     |       |
    //     |   A   |
    //     |    +--+----+   =   +--+
    //     +----+--+    |       +--+
    //          |   B   |
    //          |       |
    //          +-------+
    //
    public CSG intersect(CSG csg)
    {
        CSGNode a = new CSGNode(this.clone().polygons);
        CSGNode b = new CSGNode(csg.clone().polygons);

        a.invert();
        b.clipTo(a);
        b.invert();
        a.clipTo(b);
        b.clipTo(a);
        a.addPolygons(b.allPolygons());
        a.invert();
        return(CSG.fromPolygons(a.allPolygons()));
    }
Пример #2
0
    // Return a new CSG solid representing space in either this solid or in the
    // solid `csg`. Neither this solid nor the solid `csg` are modified.
    //
    //     A.union(B)
    //
    //     +-------+            +-------+
    //     |       |            |       |
    //     |   A   |            |       |
    //     |    +--+----+   =   |       +----+
    //     +----+--+    |       +----+       |
    //          |   B   |            |       |
    //          |       |            |       |
    //          +-------+            +-------+
    //
    public CSG union(CSG csg)
    {
        CSGNode a = new CSGNode(this.clone().polygons);
        CSGNode b = new CSGNode(csg.clone().polygons);

        a.clipTo(b);
        b.clipTo(a);
        b.invert();
        b.clipTo(a);
        b.invert();

        List <CSGPolygon> result = a.allPolygons();

        result.AddRange(b.allPolygons());

        return(CSG.fromPolygons(result));
    }