Ejemplo n.º 1
0
        /// <summary>
        /// Generate a ruled surface that follows the glulam guide and orientation.
        /// </summary>
        /// <param name="side">0 for a vertical (Y) surface, 1 for a horizontal (X) surface.</param>
        /// <param name="offset">Offset amount from glulam axis.</param>
        /// <param name="width">Width of surface.</param>
        /// <param name="extension">Amount to extend the length of the surface by.</param>
        /// <param name="flip">Flip orientation of surface.</param>
        /// <param name="samples">Number of samples for constructing surface.</param>
        /// <returns></returns>
        public Brep GenerateSideSurface(int side, double offset, double width, double extension = 0.0, bool flip = false, int samples = 100)
        {
            side = side.Modulus(2);
            double w2 = width / 2;

            Curve c = Guide.DuplicateCurve();

            if (extension > 0.0)
            {
                c = c.Extend(CurveEnd.Both, extension, CurveExtensionStyle.Smooth);
            }

            double[] t     = c.DivideByCount(samples, true);
            Curve[]  rules = new Curve[t.Length];

            for (int i = 0; i < t.Length; ++i)
            {
                Plane p = GetFrame(t[i]);
                if (side == 0)
                {
                    rules[i] = new Line(p.Origin + p.XAxis * offset + p.YAxis * w2,
                                        p.Origin + p.XAxis * offset - p.YAxis * w2).ToNurbsCurve();
                }
                else
                {
                    rules[i] = new Line(p.Origin + p.YAxis * offset + p.XAxis * w2,
                                        p.Origin + p.YAxis * offset - p.XAxis * w2).ToNurbsCurve();
                }
            }

            Brep[] loft = Brep.CreateFromLoft(rules, Point3d.Unset, Point3d.Unset, LoftType.Normal, false);
            if (loft == null || loft.Length < 1)
            {
                throw new Exception("Glulam::GetSideSurface::Loft failed!");
            }

            Brep brep = loft[0];

            Point3d  pt  = brep.Faces[0].PointAt(brep.Faces[0].Domain(0).Mid, brep.Faces[0].Domain(1).Mid);
            Vector3d nor = brep.Faces[0].NormalAt(brep.Faces[0].Domain(0).Mid, brep.Faces[0].Domain(1).Mid);

            double ct;

            Guide.ClosestPoint(pt, out ct);
            Vector3d nor2 = Guide.PointAt(ct) - pt;

            nor2.Unitize();

            if (nor2 * nor < 0.0)
            {
                brep.Flip();
            }

            if (flip)
            {
                brep.Flip();
            }

            return(brep);
        }