- UID
- 134087
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-5-6
- 最后登录
- 1970-1-1
|
发表于 2004-6-26 11:26:26
|
显示全部楼层
Public Function Fun直线是否穿过三角形(SO As Acad3DPolyline, L1 As Variant, L2 As Variant, ByRef tmpPnt() As pPoint) As Integer
Dim Pnt1(2) As Double, Pnt2(2) As Double, Pnt3(2) As Double, i As Integer, tCd As Variant
Dim P1(2) As Double, P2(2) As Double, P3(2) As Double
tCd = SO.Coordinates: ReDim tmpPnt(i) '求直线L1 L2是否穿过三角网
P1(0) = tCd(0): P1(1) = tCd(1): P1(2) = tCd(2)
P2(0) = tCd(3): P2(1) = tCd(4): P2(2) = tCd(5)
P3(0) = tCd(6): P3(1) = tCd(7): P3(2) = tCd(8)
Set tCd = Nothing
tCd = Fun检查两直线是否相交(L1, L2, P1, P2)
If tCd(0) = 0 And tCd(1) = 0 And tCd(2) = 0 Then GoTo 1
tmpPnt(i).x = tCd(0): tmpPnt(i).Y = tCd(1): tmpPnt(i).Z = tCd(2): tmpPnt(i).pN = 12: i = i + 1
1:
Set tCd = Nothing
tCd = Fun检查两直线是否相交(L1, L2, P1, P3)
If tCd(0) = 0 And tCd(1) = 0 And tCd(2) = 0 Then GoTo 2
ReDim Preserve tmpPnt(i)
tmpPnt(i).x = tCd(0): tmpPnt(i).Y = tCd(1): tmpPnt(i).Z = tCd(2): tmpPnt(i).pN = 12: i = i + 1
2:
Set tCd = Nothing
tCd = Fun检查两直线是否相交(L1, L2, P3, P2)
If tCd(0) = 0 And tCd(1) = 0 And tCd(2) = 0 Then GoTo 3
ReDim Preserve tmpPnt(i)
tmpPnt(i).x = tCd(0): tmpPnt(i).Y = tCd(1): tmpPnt(i).Z = tCd(2): tmpPnt(i).pN = 12: i = i + 1
3:
Fun直线是否穿过三角形 = i
End Function
Public Function Fun直线是否穿过立体线(SO As AcadLine, L1 As Variant, L2 As Variant, ByRef tmpPnt() As pPoint) As Integer
Dim i As Integer, tCd As Variant, PStart As Variant, PEnd As Variant
PStart = SO.StartPoint: PEnd = SO.EndPoint: ReDim tmpPnt(i) '.SO.Coordinates: ReDim tmpPnt(i) '求直线L1 L2是否穿过三角网
If PStart(2) = 0 And PEnd(2) = 0 Then Exit Function
tCd = Fun检查两直线是否相交(L1, L2, PStart, PEnd)
If tCd(0) = 0 And tCd(1) = 0 And tCd(2) = 0 Then Exit Function
tmpPnt(i).x = tCd(0): tmpPnt(i).Y = tCd(1): tmpPnt(i).Z = tCd(2): tmpPnt(i).pN = "CRS": i = i + 1
Fun直线是否穿过立体线 = i
End Function
Public Function Fun检查两直线是否相交(L1 As Variant, L2 As Variant, P1 As Variant, P2 As Variant) As Variant
Dim Pnt1(2) As Double, TrueIn As Boolean: Fun检查两直线是否相交 = Pnt1: TrueIn = False
Dim a1 As Double, a2 As Double, b1 As Double, b2 As Double
Call GetLineV(L1, L2, a1, b1) '求两条直线相交的交点
Call GetLineV(P1, P2, a2, b2)
If Abs(a1) = Abs(a2) Then
If b1 = 0 And b2 = 0 Then
Exit Function
ElseIf Not b1 = 0 And Not b2 = 0 Then
Exit Function
End If
End If
If a1 = 0 And b1 = 0 Then
Pnt1(0) = L1(0): Pnt1(1) = a2 * Pnt1(0) + b2
ElseIf a2 = 0 And b2 = 0 Then
Pnt1(0) = P1(0):: Pnt1(1) = a1 * Pnt1(0) + b1
Else
Pnt1(0) = (b1 - b2) / (a2 - a1): Pnt1(1) = a1 * Pnt1(0) + b1
End If
If Fun确定点在直线上(Pnt1, L1, L2) = True And Fun确定点在直线上(Pnt1, P1, P2) = True Then Fun检查两直线是否相交 = Pnt1
End Function
Public Function GetLineV(L1 As Variant, L2 As Variant, ByRef a1 As Double, ByRef b1 As Double)
Dim Dx As Double, dY As Double '求两点之间的直线斜率
Dx = L2(0) - L1(0): dY = L2(1) - L1(1)
Dx = GetDblPrice(Dx, 5)
If Dx = 0 Then a1 = 0: b1 = 0 Else a1 = dY / Dx: b1 = L1(1) - a1 * L1(0)
End Function
Public Function GetDist(L1 As Variant, L2 As Variant) As Double
Dim Dx As Double, dY As Double '求两点之间的距离
Dx = L1(0) - L2(0): dY = L1(1) - L2(1)
GetDist = Sqr(Dx * Dx + dY * dY)
End Function
Public Function Fun确定点在直线上(ByRef Pnt1 As Variant, P1 As Variant, P2 As Variant) As Boolean '(L1 As Variant, L2 As Variant, ByRef a1 As Double, ByRef b1 As Double)
Dim a As Double, b As Double, x As Double, Y As Double, s As Double, dH As Double: Fun确定点在直线上 = False
Dim v1 As Double, v2 As Double, Su As Double
Call GetLineV(P1, P2, a, b) 'If Pnt1(0) >= P1(0) Then If Pnt1(0) <= P2(0) Then X = True
Su = GetDist(P1, P2): v1 = GetDist(Pnt1, P1): v2 = GetDist(Pnt1, P2)
s = a * Pnt1(0) + b 'If Pnt1(0) >= P2(0) Then If Pnt1(0) <= P1(0) Then X = True
s = Abs(s - Pnt1(1)): Su = Abs(Su - v1 - v2) 'If Pnt1(1) >= P1(1) Then If Pnt1(1) <= P2(1) Then Y = True 'If Pnt1(1) >= P2(1) Then If Pnt1(1) <= P1(1) Then Y = True
If s < 0.002 And Su < 0.002 Then '确定计算出的点是否的确是与直线P1 P2相交点且在直线上
Fun确定点在直线上 = True
dH = P1(2) - P2(2): s = dH / GetDist(P1, P2) 'dX = Pnt1(0) - P2(0): dY = Pnt1(1) - P2(1)
Pnt1(2) = P2(2) + s * GetDist(Pnt1, P2)
End If
End Function |
|