C#CAD二次开发图案填充对象边界提取

        /// 填充边界提取转化方法
        /// </summary>
        /// <param name="hat">需要转化的Hatch对象</param>
        /// <param name="trans">声明的事务对象</param>
        /// <param name="btr">数据库中的模型空间</param>
        /// <param name="numSample">提取单位曲线中样本点的数目</param>
        public static void DrawBorder(Hatch hat, Transaction trans, BlockTableRecord btr, int numSample)
        {
            //取得边界数
            int loopNum = hat.NumberOfLoops;
            Point2dCollection col_point2d = new Point2dCollection();
            BulgeVertexCollection col_ver = new BulgeVertexCollection();
            Curve2dCollection col_cur2d = new Curve2dCollection();

            for (int i = 0; i < loopNum; i++)
            {
                col_point2d.Clear();
                HatchLoop hatLoop = null;
                try
                {
                    hatLoop = hat.GetLoopAt(i);
                }
                catch (System.Exception)
                {
                    continue;
                }

                //如果HatchLoop为PolyLine
                if (hatLoop.IsPolyline)
                {
                    col_ver = hatLoop.Polyline;
                    foreach (BulgeVertex vertex in col_ver)
                    {
                        col_point2d.Add(vertex.Vertex);
                    }
                }
                //如果HatchLoop为Curves
                else
                {
                    col_cur2d = hatLoop.Curves;
                    foreach (Curve2d item in col_cur2d)
                    {
                        Point2d[] M_point2d = item.GetSamplePoints(numSample);
                        foreach (Point2d point in M_point2d)
                        {
                            if (!col_point2d.Contains(point))
                                col_point2d.Add(point);
                        }
                    }
                }
                //根据获得的Point2d点集创建闭合Polyline
                Polyline pl = new Polyline();
                pl.Closed = true;
                pl.Color = hat.Color;
                PolylineTools.CreatePolyline(pl, col_point2d);
                btr.AppendEntity(pl);
                trans.AddNewlyCreatedDBObject(pl, true);
            }
        }

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值