明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3431|回复: 11

[几何] 如何使生成的文字在多边形的外面!

    [复制链接]
发表于 2010-12-18 13:00 | 显示全部楼层 |阅读模式
如何使生成的文字在多边形的外面!发个图看看:

本帖子中包含更多资源

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

x

评分

参与人数 1金钱 +20 收起 理由
yxr_MJTD + 20 很好,很强大!

查看全部评分

发表于 2019-4-14 10:30 | 显示全部楼层
如果我是ssget一框选已打散的(list '(0 . "LWPOLYLINE"))线怎么分别四条线相对于其中心的方位?
发表于 2010-12-18 13:28 | 显示全部楼层
本帖最后由 lzh741206 于 2010-12-18 13:39 编辑
  1.     public enum PointOnRegionType
  2.     {
  3.         Inside,
  4.         On,
  5.         Outside,
  6.         Error
  7.     }

  8.         public static PointOnRegionType PointOnRegion(this IEnumerable<Point2d> pts, Point2d pt)
  9.         {

  10.             //遍历点集并生成首尾连接的多边形
  11.             LoopList<Point2d> ptlst = new LoopList<Point2d>(pts);
  12.             if(ptlst.Count < 3)
  13.                 return PointOnRegionType.Error;

  14.             var ls2ds = new List<LineSegment2d>();
  15.             foreach (var node in ptlst.GetNodes())
  16.             {
  17.                 ls2ds.Add(new LineSegment2d(node.Value, node.Next.Value));
  18.             }
  19.             var cc2d = new CompositeCurve2d(ls2ds.ToArray());

  20.             //在多边形上?
  21.             if (cc2d.IsOn(pt, new Tolerance(1e-4, 1e-4)))
  22.                 return PointOnRegionType.On;

  23.             //在最小包围矩形外?
  24.             var bb2d = cc2d.BoundBlock;
  25.             if (!bb2d.Contains(pt))
  26.                 return PointOnRegionType.Outside;

  27.             //
  28.             bool flag = false;
  29.             foreach (var node in ptlst.GetNodes())
  30.             {
  31.                 var pt1 = node.Value;
  32.                 var pt2 = node.Next.Value;
  33.                 if (pt.Y < pt1.Y && pt.Y < pt2.Y)
  34.                     continue;
  35.                 if (pt1.X < pt.X && pt2.X < pt.X)
  36.                     continue;
  37.                 Vector2d vec = pt2 - pt1;
  38.                 double t = (pt.X - pt1.X) / vec.X;
  39.                 double y = t * vec.Y + pt1.Y;
  40.                 if (y < pt.Y && t >= 0 && t <= 1)
  41.                     flag = !flag;
  42.             }

  43.             return flag ? PointOnRegionType.Inside : PointOnRegionType.Outside;

  44.         }
复制代码
LoopList类在这里找http://bbs.mjtd.com/thread-82110-1-1.html
测试代码:
  1.         [CommandMethod("t4")]
  2.         public static void Test4()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Editor ed = doc.Editor;
  6.             
  7.             PromptEntityOptions optsEnt = new PromptEntityOptions("\nSelect a LWPolyLine:");
  8.             optsEnt.SetRejectMessage("\nNot a LWPolyLine!");
  9.             optsEnt.AddAllowedClass(typeof(LWPolyline), false);
  10.             PromptEntityResult resEnt = ed.GetEntity(optsEnt);


  11.             if (resEnt.Status == PromptStatus.OK)
  12.             {
  13.                 Database db = doc.Database;
  14.                 using (Transaction tr = db.TransactionManager.StartTransaction())
  15.                 {

  16.                     LWPolyline pl = tr.GetObject(resEnt.ObjectId, OpenMode.ForRead) as LWPolyline;
  17.                     var ptlst =
  18.                         Enumerable
  19.                         .Range(0, pl.NumberOfVertices)
  20.                         .Select(i => pl.GetPoint2dAt(i));

  21.                     PromptPointOptions optPnt = new PromptPointOptions("\nInput a Point:");
  22.                     optPnt.AllowNone = true;
  23.                     PromptPointResult resPnt = ed.GetPoint(optPnt);
  24.                     while (resPnt.Status == PromptStatus.OK)
  25.                     {
  26.                         var res = ptlst.PointOnRegion(resPnt.Value.Convert2d(new Plane()));
  27.                         ed.WriteMessage("\nPoint:{0},Result:{1}" ,resPnt.Value, res);
  28.                         resPnt = ed.GetPoint(optPnt);
  29.                     }

  30.                 }
  31.             }
  32.         }
发表于 2010-12-18 20:38 | 显示全部楼层
本帖最后由 河伯 于 2010-12-18 20:44 编辑

支持版主的解决方案,学习一下。
VB.NET 2010不能在调试期间编辑lambda表达式代码,必须停止调试退出AutoCAD,C#是这样吗?
如果这个问题不能解决,势必限制了Linq的应用,反复启动AutoCAD实在太麻烦。
发表于 2010-12-18 20:40 | 显示全部楼层
高难,还不懂,学习一下。
发表于 2010-12-18 21:17 | 显示全部楼层
太厉害了。
学习中
发表于 2010-12-18 21:54 | 显示全部楼层
很少在调试阶段编辑代码,一般只有在Cad爆掉才,呵呵
现在总是不断地开Cad的,哎
习惯了,汗
发表于 2010-12-19 23:40 | 显示全部楼层
我经常在调试阶段编辑代码,如果编辑的代码不是当前运行的那行,一般调试是不会中断的,可以实时的看到效果,这样就不用重复启动CAD了。
发表于 2010-12-19 23:49 | 显示全部楼层
lambda在C#里也无法调试。呵呵
发表于 2010-12-20 18:44 | 显示全部楼层
lzh741206 发表于 2010-12-19 23:49
lambda在C#里也无法调试。呵呵

又多了一个调试阶段不能编辑的因素。
AutoCAD .NET其它方面都还不错,就是这个调试,比起lisp和VBA的方便程度差太多。
最要命的是调试时不能修改窗体,难以想象大量的对话框迁移起来该多麻烦。
发表于 2011-10-27 09:12 | 显示全部楼层
学习一下!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-26 10:14 , Processed in 2.508730 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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