- 积分
- 6030
- 明经币
- 个
- 注册时间
- 2016-10-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 wang2006zhi 于 2025-2-14 12:17 编辑
 - /// <summary>
- /// 寻找填充边界
- /// </summary>
- [CommandMethod("tt5")]
- public void Tt5()
- {
- using var tr = new DBTrans();
- if (!Env.Editor.GetPoint(out Point3d point,"\n 获取一个点"))
- return;
- var selPtc = point.GetPointCollection(5000);
- if (!Env.Editor.SelEnts(out List<Curve> curs,selPtc))
- return;
- var extens = curs.GetExtents();
- var h = extens.GetHeight();
- var w = extens.GetWidth();
- double n = 100;
- h /= n;
- w /= n;
- var pts = new List<Point3d>();
- HashSet<Point3d> pos = [point];
- Queue<Point3d> points = new Queue<Point3d>();
- points.Enqueue(point);
- while (points.Count > 0)
- {
- var p = points.Dequeue();
- var sha = p + new Vector3d(0, h, 0);
- var xia = p + new Vector3d(0, -h, 0);
- var zuo = p + new Vector3d(-w, 0, 0);
- var you = p + new Vector3d(w, 0, 0);
- Addpoint(p, sha);
- Addpoint(p, xia);
- Addpoint(p, zuo);
- Addpoint(p, you);
- }
- var newPts=pts.OrderBy(o => (point - o).AngleOnPlane())
- .ThenBy(x => x.X)
- .ThenBy(y => y.Y).ToList();
- var pl=newPts.MakePolyline();
- pl.ColorIndex = 1;
- pl.ConstantWidth = 5;
- pl.Closed = true;
- tr.CurrentSpace.AddEntity(pl);
-
- bool IsIntersectWith(Curve line)
- {
- return curs.Any(c =>
- {
- var ptC = new Point3dCollection();
- c.IntersectWith(line, Intersect.OnBothOperands, ptC, IntPtr.Zero, IntPtr.Zero);
- if (ptC.Count<=0)
- return false;
- foreach (Point3d o in ptC)
- {
- pts.Add(o);
- }
- return true;
- });
- }
-
- void Addpoint(Point3d p, Point3d p1)
- {
- if (pos.Contains(p1))
- return;
- var line = new Line(p, p1);
- if (!IsIntersectWith(line))
- points.Enqueue(p1);
- pos.Add(p1);
- }
-
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|