明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2276|回复: 4

[基础] 拾取一个点坐标,找到包围这个坐标的最小封闭区域问题

[复制链接]
发表于 2011-1-18 15:27 | 显示全部楼层 |阅读模式
本帖最后由 kuaigoumanzhu 于 2011-1-18 15:31 编辑

开始没一点思路,后来在论坛看了一天的帖子。现在是先拾取一个点坐标,然后找到所有封闭区域的顶点坐标然后再计算这个点是否在封闭区域内。
  1. BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  2.                 BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  3.                 Polyline p = new Polyline();
  4.                 Point3d a = new Point3d();
  5.                 PromptPointOptions opt = new PromptPointOptions("选择点");
  6. PromptPointResult rest = ed.GetPoint(opt);
  7. if (rest.Status == PromptStatus.OK)
  8.                 {
  9.                     a = rest.Value;
  10.                 }
  11. TypedValue[] pline ={ new TypedValue((int)DxfCode.Start, "LWPOLYLINE") };
  12.                 SelectionFilter sf = new SelectionFilter(pline);
  13.                 PromptSelectionResult res = ed.SelectAll(sf);
  14.                 SelectionSet st = res.Value;
  15.                 if (st != null)
  16.                 {
  17.                     ObjectId[] ids = st.GetObjectIds();
  18.                     Point3dCollection p3dc=new Point3dCollection();
  19.                     foreach (ObjectId id in ids)
  20.                     {
  21.                         p = trans.GetObject(id, OpenMode.ForRead) as Polyline;
  22.                         //Point3d c = new Point3d((p.c));
  23.                         int j=p.NumberOfVertices-1;
  24.                         bool result = false;
  25.                         for (int i = 0; i < p.NumberOfVertices; i++)
  26.                         {
  27.                             p3dc.Add(p.GetPoint3dAt(i));
  28.                             //nodes.Add(p.GetPoint3dAt(i));
  29.                             ed.WriteMessage(p.GetPoint3dAt(i).ToString());
  30.                            
  31.                             if (((p.GetPoint3dAt(i).Y)<=a.Y)&&(a.Y<p.GetPoint3dAt(j).Y)||((p.GetPoint3dAt(j).Y<a.Y))&&a.Y<(p.GetPoint3dAt(i).Y))
  32.                             {
  33.                                 if ((a.X - p.GetPoint3dAt(i).X) < (p.GetPoint3dAt(j).X - p.GetPoint3dAt(i).X) * (a.Y - p.GetPoint3dAt(i).Y) / (p.GetPoint3dAt(j).Y - p.GetPoint3dAt(i).Y))
  34.                                 {
  35.                                     result = !result;
  36.                                 }
  37.                             }
  38.                             j = i;
  39.                         }
  40.                         if (result)
  41.                         {
  42.                             MessageBox.Show("在封闭区域中");
  43.                         }
  44.                     }

这个是测试时候的代码。
 楼主| 发表于 2011-1-18 15:32 | 显示全部楼层
这种方法需要比较的太多,还有那个算点是否在封闭区域内的算法,也不明白。有什么更好的没有大家多多指点啊。
发表于 2011-1-18 17:55 | 显示全部楼层
发表于 2011-3-13 19:31 | 显示全部楼层
本帖最后由 dafeilang 于 2011-3-13 19:31 编辑

(bpoly (getpoint "ss"))  找输入点周围的封闭图形并创建多段线

然后可以求创建的面域的面积 (也是在网上学的,这个命令)

不好意思,搜求坐标点的方法的时候进错版了,我以为是Lisp版
发表于 2011-10-27 09:02 | 显示全部楼层
新手学习!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-3 21:21 , Processed in 0.226192 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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