Esempio n. 1
0
        /// <summary>
        /// Return a new CSG solid representing the union of this csg and the specified csgs.
        /// </summary>
        ///
        /// <b>Note:</b> Neither this csg nor the specified csg are weighted.
        ///
        /// <blockquote><pre>
        ///    A.union(B)
        ///
        ///    +-------+            +-------+
        ///    |       |            |       |
        ///    |   A   |            |       |
        ///    |    +--+----+   =   |       +----+
        ///    +----+--+    |       +----+       |
        ///         |   B   |            |       |
        ///         |       |            |       |
        ///         +-------+            +-------+
        /// </pre></blockquote>
        ///
        ///
        /// <param name="csgs">other csgs</param>
        ///
        /// <returns>union of this csg and the specified csgs</returns>
        ///
        public CSG union(List <CSG> csgs)
        {
            CSG result = this;

            foreach (CSG csg in csgs)
            {
                result = result.union(csg);
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Return a new CSG solid representing the intersection of this csg and the specified csgs.
        /// </summary>
        ///
        /// <b>Note:</b> Neither this csg nor the specified csgs are weighted.
        ///
        /// <code>
        ///     A.intersect(B)
        ///
        ///     +-------+
        ///     |       |
        ///     |   A   |
        ///     |    +--+----+   =   +--+
        ///     +----+--+    |       +--+
        ///          |   B   |
        ///          |       |
        ///          +-------+
        /// }
        /// </code>
        ///
        /// <param name="csgs">other csgs</param>
        /// <returns>intersection of this csg and the specified csgs</returns>
        ///
        public CSG intersect(List <CSG> csgs)
        {
            if (csgs.Count == 0)
            {
                return(this.clone());
            }

            CSG csgsUnion = csgs[0];

            for (int i = 1; i < csgs.Count; i++)
            {
                csgsUnion = csgsUnion.union(csgs[i]);
            }

            return(intersect(csgsUnion));
        }
Esempio n. 3
0
        public List <Polygon> toPolygons()
        {
            CSG spherePrototype
                = new Sphere(getCornerRadius(), getResolution() * 2, getResolution()).toCSG();

            double x = dimensions.x() / 2.0 - getCornerRadius();
            double y = dimensions.y() / 2.0 - getCornerRadius();
            double z = dimensions.z() / 2.0 - getCornerRadius();

            CSG sphere1 = spherePrototype.transformed(Transform.unity().translate(-x, -y, -z));
            CSG sphere2 = spherePrototype.transformed(Transform.unity().translate(x, -y, -z));
            CSG sphere3 = spherePrototype.transformed(Transform.unity().translate(x, y, -z));
            CSG sphere4 = spherePrototype.transformed(Transform.unity().translate(-x, y, -z));

            CSG sphere5 = spherePrototype.transformed(Transform.unity().translate(-x, -y, z));
            CSG sphere6 = spherePrototype.transformed(Transform.unity().translate(x, -y, z));
            CSG sphere7 = spherePrototype.transformed(Transform.unity().translate(x, y, z));
            CSG sphere8 = spherePrototype.transformed(Transform.unity().translate(-x, y, z));

            List <Polygon> result = sphere1.union(
                sphere2, sphere3, sphere4,
                sphere5, sphere6, sphere7, sphere8).hull().getPolygons();

            Transform locTransform = Transform.unity().translate(center);

            foreach (Polygon p in result)
            {
                p.transform(locTransform);
            }

            if (!centered)
            {
                Transform centerTransform = Transform.unity().
                                            translate(dimensions.x() / 2.0,
                                                      dimensions.y() / 2.0,
                                                      dimensions.z() / 2.0);

                foreach (Polygon p in result)
                {
                    p.transform(centerTransform);
                }
            }

            return(result);
        }