- 积分
- 5966
- 明经币
- 个
- 注册时间
- 2003-1-7
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2005-5-12 14:36:00
|
显示全部楼层
' 判断点是否在直线的右侧 ' 输入参数:pt:点;ptStart:直线的起点;ptEnd:直线的终点;bRight:点是否在直线的右侧 ' 输出参数:函数执行是否成功(如果不成功,是因为直线是水平的) Private Function PtToLine(ByVal pt As Variant, ByVal ptStart As Variant, ByVal ptEnd As Variant, ByRef bRight As Boolean) As Boolean ' 如果直线水平 If Abs(ptStart(1) - ptEnd(1)) < 0.0000001 Then PtToLine = False Exit Function End If ' 创建一个辅助的水平构造线 Dim objXLine As AcadXline Dim ptTemp(0 To 2) As Double ptTemp(0) = pt(0) + 1: ptTemp(1) = pt(1): ptTemp(2) = pt(2) Set objXLine = ThisDrawing.ModelSpace.AddXline(pt, ptTemp) ' 获得构造线和已知直线的交点 Dim ptIntersect As Variant Dim objLine As AcadLine Set objLine = ThisDrawing.ModelSpace.AddLine(ptStart, ptEnd) ptIntersect = objLine.IntersectWith(objXLine, acExtendBoth) ' 判断交点和已知点的位置关系 If pt(0) > ptIntersect(0) Then bRight = True Else bRight = False End If PtToLine = True End Function
Public Sub Test() Dim pt(0 To 2) As Double Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double pt(0) = 100: pt(1) = 100: pt(2) = 0 pt1(0) = 101: pt1(1) = 100: pt1(2) = 0 pt2(0) = 102: pt2(1) = 50: pt2(2) = 0 Dim bRight As Boolean If PtToLine(pt, pt1, pt2, bRight) Then If bRight Then MsgBox "点在直线的右侧" Else MsgBox "点在直线的左侧" End If End If End Sub |
|