コード例 #1
0
        /// <summary>
        /// Construct a solid by sweeping a face along a curve.
        /// </summary>
        /// <param name="outer">The perimeter of the face to sweep.</param>
        /// <param name="inner">The holes of the face to sweep.</param>
        /// <param name="curve">The curve along which to sweep.</param>
        /// <param name="material">The solid's material.</param>
        /// <param name="startSetback">The setback of the sweep from the start of the curve.</param>
        /// <param name="endSetback">The setback of the sweep from the end of the curve.</param>
        /// <returns>A solid.</returns>
        public static Solid SweepFaceAlongCurve(Polygon outer, Polygon[] inner, ICurve curve, Material material = null, double startSetback = 0, double endSetback = 0)
        {
            var solid = new Solid(material);

            var l   = curve.Length();
            var ssb = startSetback / l;
            var esb = endSetback / l;

            var transforms = curve.Frames(ssb, esb);

            if (curve is Polygon)
            {
                for (var i = 0; i < transforms.Length; i++)
                {
                    var next = i == transforms.Length - 1 ? transforms[0] : transforms[i + 1];
                    solid.SweepPolygonBetweenPlanes(outer, transforms[i].XY, next.XY);
                }
            }
            else
            {
                // Add start cap.
                Face     cap = null;
                Edge[][] openEdges;

                if (inner != null)
                {
                    cap       = solid.AddFace(transforms[0].OfPolygon(outer), transforms[0].OfPolygons(inner));
                    openEdges = new Edge[1 + inner.Length][];
                }
                else
                {
                    cap       = solid.AddFace(transforms[0].OfPolygon(outer));
                    openEdges = new Edge[1][];
                }

                // last outer edge
                var openEdge = cap.Outer.GetLinkedEdges();
                openEdge     = solid.SweepEdges(transforms, openEdge);
                openEdges[0] = openEdge;

                if (inner != null)
                {
                    for (var i = 0; i < cap.Inner.Length; i++)
                    {
                        openEdge = cap.Inner[i].GetLinkedEdges();

                        // last inner edge for one hole
                        openEdge         = solid.SweepEdges(transforms, openEdge);
                        openEdges[i + 1] = openEdge;
                    }
                }

                solid.Cap(openEdges, true);
            }

            return(solid);
        }
コード例 #2
0
        /// <summary>
        /// Extrude an Polygon along an ICurve.
        /// </summary>
        /// <param name="curve">The ICurve along which to extrude.</param>
        /// <param name="perimeter">A Polygon to extrude.</param>
        /// <param name="voids">A collection of Polygons representing voids in the extrusion.</param>
        /// <param name="capped">A flag indicating whether the extrusion should be capped.</param>
        /// <param name="startSetback">The setback trom the start of the line of the extrusion.</param>
        /// <param name="endSetback">The setback from the end of the line of the end of the extrusion.</param>
        /// <returns></returns>
        public static Mesh ExtrudeAlongCurve(ICurve curve, Polygon perimeter, IList <Polygon> voids = null, bool capped = true, double startSetback = 0.0, double endSetback = 0.0)
        {
            var mesh = new Hypar.Geometry.Mesh();

            var l   = curve.Length;
            var ssb = startSetback / l;
            var esb = endSetback / l;

            var transforms = new List <Transform>();
            var polys      = new List <Polygon>();

            transforms.AddRange(curve.Frames(ssb, esb));

            for (var i = 0; i < transforms.Count - 1; i++)
            {
                ExtrudePolygon(ref mesh, perimeter, transforms[i], transforms[i + 1]);

                if (voids != null)
                {
                    foreach (var p in voids)
                    {
                        ExtrudePolygon(ref mesh, p, transforms[i], transforms[i + 1], true);
                    }
                }
            }

            if (curve is Polygon)
            {
                ExtrudePolygon(ref mesh, perimeter, transforms[transforms.Count - 1], transforms[0]);

                if (voids != null)
                {
                    foreach (var p in voids)
                    {
                        ExtrudePolygon(ref mesh, p, transforms[transforms.Count - 1], transforms[0], true);
                    }
                }
            }

            if (capped)
            {
                mesh.AddTesselatedFace(perimeter, voids, transforms[0]);
                mesh.AddTesselatedFace(perimeter, voids, transforms[transforms.Count - 1], true);
            }

            return(mesh);
        }
コード例 #3
0
        /// <summary>
        /// Construct a solid by sweeping a face along a curve.
        /// </summary>
        /// <param name="perimeter">The perimeter of the face to sweep.</param>
        /// <param name="holes">The holes of the face to sweep.</param>
        /// <param name="curve">The curve along which to sweep.</param>
        /// <param name="startSetback">The setback distance of the sweep from the start of the curve.</param>
        /// <param name="endSetback">The setback distance of the sweep from the end of the curve.</param>
        /// <returns>A solid.</returns>
        public static Solid SweepFaceAlongCurve(Polygon perimeter,
                                                IList <Polygon> holes,
                                                ICurve curve,
                                                double startSetback = 0,
                                                double endSetback   = 0)
        {
            var solid = new Solid();

            var l = curve.Length();

            // The start and end setbacks can't be more than
            // the length of the beam together.
            if ((startSetback + endSetback) >= l)
            {
                startSetback = 0;
                endSetback   = 0;
            }

            // Calculate the setback parameter as a percentage
            // of the curve length. This will not work for curves
            // without non-uniform parameterization.
            var ssb = startSetback / l;
            var esb = endSetback / l;

            var transforms = curve.Frames(ssb, esb);

            if (curve is Polygon)
            {
                for (var i = 0; i < transforms.Length; i++)
                {
                    var next = i == transforms.Length - 1 ? transforms[0] : transforms[i + 1];
                    solid.SweepPolygonBetweenPlanes(perimeter, transforms[i], next);
                }
            }
            else if (curve is Bezier)
            {
                var startCap = solid.AddFace(transforms[0].OfPolygon(perimeter));
                for (var i = 0; i < transforms.Length - 1; i++)
                {
                    var next = transforms[i + 1];
                    solid.SweepPolygonBetweenPlanes(perimeter, transforms[i], next);
                }
                var endCap = solid.AddFace(transforms[transforms.Length - 1].OfPolygon(perimeter).Reversed());
            }
            else
            {
                // Add start cap.
                Face     cap = null;
                Edge[][] openEdges;

                if (holes != null)
                {
                    cap       = solid.AddFace(transforms[0].OfPolygon(perimeter), transforms[0].OfPolygons(holes));
                    openEdges = new Edge[1 + holes.Count][];
                }
                else
                {
                    cap       = solid.AddFace(transforms[0].OfPolygon(perimeter));
                    openEdges = new Edge[1][];
                }

                // last outer edge
                var openEdge = cap.Outer.GetLinkedEdges();
                openEdge     = solid.SweepEdges(transforms, openEdge);
                openEdges[0] = openEdge;

                if (holes != null)
                {
                    for (var i = 0; i < cap.Inner.Length; i++)
                    {
                        openEdge = cap.Inner[i].GetLinkedEdges();

                        // last inner edge for one hole
                        openEdge         = solid.SweepEdges(transforms, openEdge);
                        openEdges[i + 1] = openEdge;
                    }
                }

                solid.Cap(openEdges, true);
            }

            return(solid);
        }