sgf1234 发表于 2006-1-10 13:14:00

巧妙构思,求出直线上距已知点距离最近的点

<P>在明经通道函数下载栏中,发现了一个求直线上离已知点距离最近的点的函数,感到特别复杂,特用以下方法实现,请朋友们提意见</P>
<P>Public Function nearestPoint2Line(point As Variant, lineobj As AcadLine) As Variant<BR></P>
<P>Dim pt1 As Variant, pt2 As Variant, pt3 As Variant, intpt As Variant<BR>Dim pointobj1 As AcadPoint, pointobj2 As AcadPoint<BR>Dim lineobjtemp As AcadLine<BR>Dim mosapce As AcadModelSpace</P>
<P>Set mospace = ThisDrawing.ModelSpace</P>
<P>pt1 = lineobj.StartPoint: pt2 = lineobj.EndPoint<BR>Set pointobj1 = mospace.AddPoint(point)<BR>Set pointobj2 = pointobj1.Mirror(pt1, pt2)<BR>Set lineobjtemp = mospace.AddLine(pointobj1.Coordinates, pointobj2.Coordinates)<BR>intpt = lineobjtemp.IntersectWith(lineobj, acextendno)</P>
<P>lineobjtemp.Delete<BR>pointobj1.Delete<BR>pointobj2.Delete</P>
<P>nearestPoint2Line = intpt</P>
<P>End Function</P>

mountains 发表于 2006-1-12 14:35:00

页: [1]
查看完整版本: 巧妙构思,求出直线上距已知点距离最近的点