Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Polyline ClosetPly(List <Line> C, bool B) //////////////将线段组闭合成多段线
        {
            List <Point3d> last = new List <Point3d>();

            for (int i = 0; i < C.Count - 1; i++)
            {
                Point3d pt1;
                Point3d pt2;
                if (i == 0)
                {
                    ViperClass.ClosedPt(C[0], C[C.Count - 1], out pt1, out pt2);
                    last.Add((pt1 + pt2) / 2);
                }
                ViperClass.ClosedPt(C[i], C[i + 1], out pt1, out pt2);
                last.Add((pt1 + pt2) / 2);
            }
            last.Add(last[0]);

            if (B == false)                                                             //////不闭合的情况
            {
                Vector3d vc = Point3d.Subtract(C[C.Count - 1].From, C[C.Count - 1].To); //////该方向用于判断最后那个点的位置
                last[0] = C[0].From;
                if (last[1].DistanceTo(C[0].From) < last[1].DistanceTo(C[0].To))        ////最远
                {
                    last[0] = C[0].To;
                }
                last[last.Count - 1] = C[C.Count - 1].From;
                if (last[last.Count - 2].DistanceTo(C[C.Count - 1].From) < last[last.Count - 2].DistanceTo(C[C.Count - 1].To))///最远
                {
                    last[last.Count - 1] = C[C.Count - 1].To;
                }
            }
            return(new Polyline(last));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve polylineCurve = null;

            if (!DA.GetData(0, ref polylineCurve))
            {
                return;
            }
            Curve[]     seg   = polylineCurve.DuplicateSegments();
            List <Line> right = new List <Line>();//////分离出线段部分

            for (int i = 0; i < seg.Length; i++)
            {
                if (seg[i].IsLinear())
                {
                    Line test = new Line(seg[i].PointAtStart, seg[i].PointAtEnd);
                    right.Add(test);
                }
            }
            List <Point3d> last = new List <Point3d>();////重新计算交点
            Point3d        pt1  = Point3d.Unset;
            Point3d        pt2  = Point3d.Unset;

            if (polylineCurve.IsClosed)////闭合曲线
            {
                ViperClass.ClosedPt(right[0], right[right.Count - 1], out pt1, out pt2);
                last.Add((pt1 + pt2) / 2);
                for (int i = 0; i < right.Count - 1; i++)
                {
                    ViperClass.ClosedPt(right[i], right[i + 1], out pt1, out pt2);
                    last.Add((pt1 + pt2) / 2);
                }
                last.Add(last[0]);
            }
            if (!polylineCurve.IsClosed)////不闭合曲线
            {
                last.Add(right[0].From);
                for (int i = 0; i < right.Count - 1; i++)
                {
                    ViperClass.ClosedPt(right[i], right[i + 1], out pt1, out pt2);
                    last.Add((pt1 + pt2) / 2);
                }
                last.Add(right[right.Count - 1].To);
            }
            DA.SetData(0, new Polyline(last));
        }