明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3463|回复: 7

怎样在选择多段线的同时计算得到所选的点位于多段线的哪段上

[复制链接]
发表于 2011-10-27 21:27 | 显示全部楼层 |阅读模式
1明经币
相同问题见http://bbs.mjtd.com/dispbbs_4_59025_100_1.html
在单选一个多段线时可以返回一个对象和一个选择点,但不知道怎么计算得到选择点位于或最接近于多段线哪一段。

最佳答案

查看完整内容

1 public Autodesk.AutoCAD.EditorInput.PromptEntityResult GetEntity(Autodesk.AutoCAD.EditorInput.PromptEntityOptions options) Autodesk.AutoCAD.EditorInput.Editor 的成员 2 public Autodesk.AutoCAD.Geometry.Point3d PickedPoint { get; } Autodesk.AutoCAD.EditorInput.PromptEntityResult 的成员 3 public virtual Autodesk.AutoCAD.Geometry.Point3d GetClosestPointTo(Autodesk.AutoCAD.Geometry.Point3 ...
发表于 2011-10-27 21:27 | 显示全部楼层
1 public Autodesk.AutoCAD.EditorInput.PromptEntityResult GetEntity(Autodesk.AutoCAD.EditorInput.PromptEntityOptions options)
    Autodesk.AutoCAD.EditorInput.Editor 的成员
2 public Autodesk.AutoCAD.Geometry.Point3d PickedPoint { get; }
    Autodesk.AutoCAD.EditorInput.PromptEntityResult 的成员
3 public virtual Autodesk.AutoCAD.Geometry.Point3d GetClosestPointTo(Autodesk.AutoCAD.Geometry.Point3d givenPoint, bool extend)
    Autodesk.AutoCAD.DatabaseServices.Curve 的成员
4 public virtual double GetParameterAtPoint(Autodesk.AutoCAD.Geometry.Point3d point)
    Autodesk.AutoCAD.DatabaseServices.Curve 的成员
5 将GetParameterAtPoint 返回值取整
回复

使用道具 举报

发表于 2011-10-28 09:51 | 显示全部楼层
  1.   ''' <summary>
  2.     ''' 找多段线上某一顶点到线外一点的最近顶点
  3.     ''' </summary>
  4.     ''' <param name="pt"></param>
  5.     ''' <param name="objPolID"></param>
  6.     ''' <param name="VerNum">可以传出最近点的序号</param>
  7.     ''' <returns></returns>
  8.     ''' <remarks></remarks>
  9.     Public Function NearestVerPt(ByVal pt As Point2d, ByVal objPolID As  ObjectId, Optional ByRef VerNum As Integer = 0) As Point2d
  10.         Using Trans As  Transaction = DB.TransactionManager.StartTransaction
  11.             Dim Ent As  Entity = Trans.GetObject(objPolID, clsAADS.OpenMode.ForRead)
  12.             If TypeOf Ent Is  Polyline Then
  13.                 Dim objPol As  Polyline = Ent
  14.                 Dim ptTemp As Point2d = objPol.GetPoint2dAt(0)
  15.                 Dim Dist As Double = pt.GetDistanceTo(ptTemp)
  16.                 VerNum = 0
  17.                 For I As Integer = 1 To objPol.NumberOfVertices - 1
  18.                     ptTemp = objPol.GetPoint2dAt(I)
  19.                     If pt.GetDistanceTo(ptTemp) < Dist Then
  20.                         VerNum = I
  21.                         Dist = pt.GetDistanceTo(ptTemp)
  22.                     End If
  23.                 Next
  24.                 Return objPol.GetPoint2dAt(VerNum)
  25.             Else
  26.                 NearestVerPt = Nothing
  27.             End If
  28.             Trans.Commit()
  29.         End Using
  30.     End Function

评分

参与人数 1明经币 +1 金钱 +10 收起 理由
xgr + 1 + 10 不错,有启示

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2011-10-28 10:11 | 显示全部楼层
谢谢回复
guohq,请用C#写个简单的代码
回复

使用道具 举报

发表于 2011-10-28 21:56 | 显示全部楼层
  1. public Point2d NearestVerPt(Point2d pt, ObjectId objPolID, ref int VerNum = 0)
  2. {
  3.         Point2d functionReturnValue = default(Point2d);
  4.         using (Transaction Trans = DB.TransactionManager.StartTransaction) {
  5.                 Entity Ent = Trans.GetObject(objPolID, clsAADS.OpenMode.ForRead);
  6.                 if (Ent is Polyline) {
  7.                         Polyline objPol = Ent;
  8.                         Point2d ptTemp = objPol.GetPoint2dAt(0);
  9.                         double Dist = pt.GetDistanceTo(ptTemp);
  10.                         VerNum = 0;
  11.                         for (int I = 1; I <= objPol.NumberOfVertices - 1; I++) {
  12.                                 ptTemp = objPol.GetPoint2dAt(I);
  13.                                 if (pt.GetDistanceTo(ptTemp) < Dist) {
  14.                                         VerNum = I;
  15.                                         Dist = pt.GetDistanceTo(ptTemp);
  16.                                 }
  17.                         }
  18.                         return objPol.GetPoint2dAt(VerNum);
  19.                 } else {
  20.                         functionReturnValue = null;
  21.                 }
  22.                 Trans.Commit();
  23.         }
  24.         return functionReturnValue;
  25. }
这个是自动翻译的,可能有些问题
回复

使用道具 举报

 楼主| 发表于 2011-10-29 12:20 | 显示全部楼层

其实两位的方法只是取得了选择点距离多段线端点最近点的号,我需要的是选择点所选择那一段线的方位角,这个就有些麻烦,因为所选择的位置有前有后,所以选择同一个点返回的点号可能相差1.

本帖子中包含更多资源

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

x
回复

使用道具 举报

 楼主| 发表于 2011-10-29 15:25 | 显示全部楼层
已想到完美解决办法
GetParameterAtPoint返回值的小数部分即代表所选点在多段线的位置
回复

使用道具 举报

发表于 2012-3-9 16:00 | 显示全部楼层
在单选一个多段线时可以返回一个对象和一个选择点,这句话的意思是什么啊,可以返回点的吗,可否给个例子说明一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-4 17:31 , Processed in 0.455008 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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