明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2486|回复: 12

[【IFoxCAD】] BO算法-画线求交填充法

[复制链接]
发表于 2024-8-5 17:39:51 | 显示全部楼层 |阅读模式
本帖最后由 wang2006zhi 于 2025-2-14 12:17 编辑
  1. /// <summary>
  2. /// 寻找填充边界
  3. /// </summary>
  4. [CommandMethod("tt5")]
  5. public void Tt5()
  6. {
  7.     using var tr = new DBTrans();
  8.     if (!Env.Editor.GetPoint(out Point3d point,"\n 获取一个点"))
  9.         return;
  10.     var selPtc = point.GetPointCollection(5000);
  11.     if (!Env.Editor.SelEnts(out List<Curve> curs,selPtc))
  12.         return;
  13.     var extens = curs.GetExtents();
  14.     var h = extens.GetHeight();
  15.     var w = extens.GetWidth();
  16.     double n = 100;
  17.     h /= n;
  18.     w /= n;
  19.     var pts = new List<Point3d>();
  20.     HashSet<Point3d> pos = [point];
  21.     Queue<Point3d> points = new Queue<Point3d>();
  22.     points.Enqueue(point);
  23.     while (points.Count > 0)
  24.     {
  25.         var p = points.Dequeue();
  26.         var sha = p + new Vector3d(0, h, 0);
  27.         var xia = p + new Vector3d(0, -h, 0);
  28.         var zuo = p + new Vector3d(-w, 0, 0);
  29.         var you = p + new Vector3d(w, 0, 0);
  30.         Addpoint(p, sha);
  31.         Addpoint(p, xia);
  32.         Addpoint(p, zuo);
  33.         Addpoint(p, you);
  34.     }

  35.     var newPts=pts.OrderBy(o => (point - o).AngleOnPlane())
  36.         .ThenBy(x => x.X)
  37.         .ThenBy(y => y.Y).ToList();

  38.     var pl=newPts.MakePolyline();
  39.     pl.ColorIndex = 1;
  40.     pl.ConstantWidth = 5;
  41.     pl.Closed = true;
  42.     tr.CurrentSpace.AddEntity(pl);
  43.    
  44.     bool IsIntersectWith(Curve line)
  45.     {
  46.         return curs.Any(c =>
  47.         {
  48.             var ptC = new Point3dCollection();
  49.             c.IntersectWith(line, Intersect.OnBothOperands, ptC, IntPtr.Zero, IntPtr.Zero);
  50.             if (ptC.Count<=0)
  51.                 return false;
  52.             foreach (Point3d o in ptC)
  53.             {
  54.                 pts.Add(o);
  55.             }
  56.             return true;
  57.         });
  58.     }
  59.    
  60.     void Addpoint(Point3d p, Point3d p1)
  61.     {
  62.         if (pos.Contains(p1))
  63.             return;
  64.         var line = new Line(p, p1);
  65.         if (!IsIntersectWith(line))
  66.             points.Enqueue(p1);
  67.         pos.Add(p1);
  68.     }
  69.    
  70. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2024-8-6 15:07:07 | 显示全部楼层
本帖最后由 箭头_Row 于 2024-8-6 21:48 编辑

https://www.cnblogs.com/JJBox/p/12571436.html

找邊界算法這個帖子里很詳細哦。但下面語句是整個帖子的精華濃縮:

  1. // 到了Acad2011: 就可以通过以下语句获取
  2. Editor ed = Acap.DocumentManager.MdiActiveDocument.Editor;
  3. ed.TraceBoundary(........);
复制代码


  1. // 获取Boundary 注意TraceBoundary 中 deleteisland 的设置
  2.    using DBObjectCollection dbo = Env.Editor.TraceBoundary(ppr.Value, false);
  3.    if (dbo.Count != 1)
  4.    {
  5.        Env.Print("\n闭合空间错误,调整后重试!");
  6.        return;
  7.    }
  8.    pline = (Polyline)dbo[0];
  9.    if (pline.NumberOfVertices == 0)
  10.    {
  11.        Env.Print("\n闭合空间错误,调整后重试!");
  12.        return;
  13.    }


這個自帶的Api又準又快速哦!
发表于 2024-8-6 19:15:13 来自手机 | 显示全部楼层
本帖最后由 你有种再说一遍 于 2024-8-6 19:17 编辑
crtrccrt  2024-8-6 06:10
LSP,准确又快速,还能批量

要比批量c#可太幸福了,
编辑器能够提示数据结构的修改,
还能多线程并行,
还能调用SIMD指令集,
还能注重CPU cache line的miss情况
 楼主| 发表于 2024-8-7 13:32:28 | 显示全部楼层
箭头_Row 发表于 2024-8-6 15:07
https://www.cnblogs.com/JJBox/p/12571436.html

找邊界算法這個帖子里很詳細哦。但下面語句是整個帖子 ...

自带的在非视口和后台无法使用。。所以想办法造一个。。
发表于 2024-8-5 18:27:24 | 显示全部楼层
太难得的好材料啊
发表于 2024-8-5 18:48:37 | 显示全部楼层
怎么不是按照我文章做捏
发表于 2024-8-6 06:10:59 | 显示全部楼层
LSP,准确又快速,还能批量
 楼主| 发表于 2024-8-6 12:28:06 | 显示全部楼层
你有种再说一遍 发表于 2024-8-5 18:48
怎么不是按照我文章做捏

你那文章看过,逻辑有点复杂,目前我的水平还改写不出来。。。
 楼主| 发表于 2024-8-6 12:31:41 | 显示全部楼层
crtrccrt 发表于 2024-8-6 06:10
LSP,准确又快速,还能批量

语言不是门槛,逻辑算法是核心。。。
发表于 2024-8-7 22:16:35 | 显示全部楼层
论坛是有代码块的,另外有太多你自带的函数了,别人没有一点参考性
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-3-30 01:08 , Processed in 0.288810 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表