Exemple #1
0
        public static void PlaneSlice(this Brep brep, Plane sliceplane, ref List <Curve> curves)
        {
            //brep.Faces.StandardizeFaceSurfaces();
            //BrepSolidOrientation bso = brep.SolidOrientation;

            Curve[]   xCrvs;
            Point3d[] xPts;
            bool[]    inside;
            Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, sliceplane, 0.001, out xCrvs, out xPts);
            if (xCrvs == null)
            {
                return;
            }

            xCrvs  = Rhino.Geometry.Curve.JoinCurves(xCrvs);
            curves = new List <Curve>();
            inside = new bool[xCrvs.Length];
            for (int i = 0; i < xCrvs.Length; ++i)
            {
                //int sign = 1;
                Point3d  tpt = xCrvs[i].PointAtNormalizedLength(0.5);
                Vector3d n   = brep.ClosestNormal(tpt);
                n = n.ProjectToPlane(sliceplane);
                tpt.Transform(Transform.Translation(n * 0.001));
                PointContainment pcon = xCrvs[i].Contains(tpt, sliceplane, 0.0001);
                if (pcon == PointContainment.Inside)
                {
                    inside[i] = true;
                    //sign = -1;
                }
                else
                {
                    inside[i] = false;
                    //sign = 1;
                }

                curves.Add(xCrvs[i]);
                Curve[] offsets = xCrvs[i].Offset(tpt, sliceplane.ZAxis, 3.0, 0.0001, CurveOffsetCornerStyle.Sharp);
                //Curve[] offsets = xCrvs[i].Offset(sliceplane, 3.0 * sign, 0.001, CurveOffsetCornerStyle.Sharp);
                curves.AddRange(offsets);
            }

            return;
        }