怎样在选择多段线的同时计算得到所选的点位于多段线的哪段上
相同问题见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.Point3d givenPoint, bool extend)
Autodesk.AutoCAD.DatabaseServices.Curve 的成员
4 public virtual double GetParameterAtPoint(Autodesk.AutoCAD.Geometry.Point3d point)
Autodesk.AutoCAD.DatabaseServices.Curve 的成员
5 将GetParameterAtPoint 返回值取整 ''' <summary>
''' 找多段线上某一顶点到线外一点的最近顶点
''' </summary>
''' <param name="pt"></param>
''' <param name="objPolID"></param>
''' <param name="VerNum">可以传出最近点的序号</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function NearestVerPt(ByVal pt As Point2d, ByVal objPolID AsObjectId, Optional ByRef VerNum As Integer = 0) As Point2d
Using Trans AsTransaction = DB.TransactionManager.StartTransaction
Dim Ent AsEntity = Trans.GetObject(objPolID, clsAADS.OpenMode.ForRead)
If TypeOf Ent IsPolyline Then
Dim objPol AsPolyline = Ent
Dim ptTemp As Point2d = objPol.GetPoint2dAt(0)
Dim Dist As Double = pt.GetDistanceTo(ptTemp)
VerNum = 0
For I As Integer = 1 To objPol.NumberOfVertices - 1
ptTemp = objPol.GetPoint2dAt(I)
If pt.GetDistanceTo(ptTemp) < Dist Then
VerNum = I
Dist = pt.GetDistanceTo(ptTemp)
End If
Next
Return objPol.GetPoint2dAt(VerNum)
Else
NearestVerPt = Nothing
End If
Trans.Commit()
End Using
End Function 谢谢回复
guohq,请用C#写个简单的代码 public Point2d NearestVerPt(Point2d pt, ObjectId objPolID, ref int VerNum = 0)
{
Point2d functionReturnValue = default(Point2d);
using (Transaction Trans = DB.TransactionManager.StartTransaction) {
Entity Ent = Trans.GetObject(objPolID, clsAADS.OpenMode.ForRead);
if (Ent is Polyline) {
Polyline objPol = Ent;
Point2d ptTemp = objPol.GetPoint2dAt(0);
double Dist = pt.GetDistanceTo(ptTemp);
VerNum = 0;
for (int I = 1; I <= objPol.NumberOfVertices - 1; I++) {
ptTemp = objPol.GetPoint2dAt(I);
if (pt.GetDistanceTo(ptTemp) < Dist) {
VerNum = I;
Dist = pt.GetDistanceTo(ptTemp);
}
}
return objPol.GetPoint2dAt(VerNum);
} else {
functionReturnValue = null;
}
Trans.Commit();
}
return functionReturnValue;
}这个是自动翻译的,可能有些问题
其实两位的方法只是取得了选择点距离多段线端点最近点的号,我需要的是选择点所选择那一段线的方位角,这个就有些麻烦,因为所选择的位置有前有后,所以选择同一个点返回的点号可能相差1.
已想到完美解决办法
GetParameterAtPoint返回值的小数部分即代表所选点在多段线的位置
在单选一个多段线时可以返回一个对象和一个选择点,这句话的意思是什么啊,可以返回点的吗,可否给个例子说明一下
页:
[1]