Esempio n. 1
0
        private static List <Polygon> boundaryPolygonsOfPlaneGroup(
            List <Polygon> planeGroup)
        {
            List <Polygon> polygons = boundaryPathsWithHoles(
                boundaryPaths(boundaryEdgesOfPlaneGroup(planeGroup)));

            Console.Out.WriteLine("polygons: " + polygons.Count);

            List <Polygon> result = new List <Polygon>(polygons.Count);

            foreach (Polygon p in polygons)
            {
                List <Polygon> holesOfPresult
                    = p.getStorage().getValue <List <Polygon> >(Edge.KEY_POLYGON_HOLES);

                if (holesOfPresult == null)
                {
                    result.Add(p);
                }
                else
                {
                    result.AddRange(PolygonUtil.concaveToConvex(p));
                }
            }

            return(result);
        }
Esempio n. 2
0
        private static CSG extrude(IVector3d dir, Polygon polygon1)
        {
            List <Polygon> newPolygons = new List <Polygon>();

            if (dir.z() < 0)
            {
                throw new ArgumentException("z < 0 currently not supported for extrude: " + dir);
            }

            newPolygons.AddRange(PolygonUtil.concaveToConvex(polygon1));
            Polygon polygon2 = polygon1.translated(dir);

            int numvertices = polygon1.vertices.Count;

            for (int i = 0; i < numvertices; i++)
            {
                int nexti = (i + 1) % numvertices;

                IVector3d bottomV1 = polygon1.vertices[i].pos;
                IVector3d topV1    = polygon2.vertices[i].pos;
                IVector3d bottomV2 = polygon1.vertices[nexti].pos;
                IVector3d topV2    = polygon2.vertices[nexti].pos;

                List <IVector3d> pPoints = new List <IVector3d> {
                    bottomV2, topV2, topV1, bottomV1
                };

                newPolygons.Add(Polygon.fromPoints(pPoints, polygon1.getStorage()));
            }

            polygon2 = polygon2.flipped();
            List <Polygon> topPolygons = PolygonUtil.concaveToConvex(polygon2);

            newPolygons.AddRange(topPolygons);

            return(CSG.fromPolygons(newPolygons));
        }
Esempio n. 3
0
        private static List <Polygon> extrude(IVector3d dir, Polygon polygon1, bool top, bool bottom)
        {
            List <Polygon> newPolygons = new List <Polygon>();


            if (bottom)
            {
                newPolygons.AddRange(PolygonUtil.concaveToConvex(polygon1));
            }

            Polygon polygon2 = polygon1.translated(dir);

            Transform rot = Transform.unity();

            IVector3d a = polygon2.getPlane().getNormal().normalized();
            IVector3d b = dir.normalized();

            IVector3d c = a.crossed(b);

            double l = c.magnitude(); // sine of angle

            if (l > 1e-9)
            {
                IVector3d axis  = c.times(1.0 / l);
                double    angle = a.angle(b);

                double sx = 0;
                double sy = 0;
                double sz = 0;

                int n = polygon2.vertices.Count;

                foreach (Vertex v in polygon2.vertices)
                {
                    sx += v.pos.x();
                    sy += v.pos.y();
                    sz += v.pos.z();
                }

                IVector3d center = Vector3d.xyz(sx / n, sy / n, sz / n);

                rot = rot.rot(center, axis, angle * Math.PI / 180.0);

                foreach (Vertex v in polygon2.vertices)
                {
                    v.pos = rot.transform(v.pos);
                }
            }

            int numvertices = polygon1.vertices.Count;

            for (int i = 0; i < numvertices; i++)
            {
                int nexti = (i + 1) % numvertices;

                IVector3d bottomV1 = polygon1.vertices[i].pos;
                IVector3d topV1    = polygon2.vertices[i].pos;
                IVector3d bottomV2 = polygon1.vertices[nexti].pos;
                IVector3d topV2    = polygon2.vertices[nexti].pos;

                List <IVector3d> pPoints = new List <IVector3d> {
                    bottomV2, topV2, topV1, bottomV1
                };

                newPolygons.Add(Polygon.fromPoints(pPoints, polygon1.getStorage()));
            }

            polygon2 = polygon2.flipped();
            List <Polygon> topPolygons = PolygonUtil.concaveToConvex(polygon2);

            if (top)
            {
                newPolygons.AddRange(topPolygons);
            }

            return(newPolygons);
        }
Esempio n. 4
0
        /// <summary>
        /// Decomposes the specified concave polygon into convex polygons.
        /// </summary>
        /// <param name="points">the points that define the polygon</param>
        /// <returns>the decomposed concave polygon (list of convex polygons)</returns>
        ///
        public static List <Polygon> fromConcavePoints(params IVector3d[] points)
        {
            Polygon p = fromPoints(points);

            return(PolygonUtil.concaveToConvex(p));
        }