同3楼的思路,VB6的代码
Function LL_Inter(ByRef List1() As Double, ByVal p1 As Variant, ByVal p2 As Variant, Optional ByVal p3 As Variant, _ Optional ByVal p4 As Variant) As Variant Dim Line1(0 To 2) As Double Dim Line2(0 To 2) As Double If TypeName(p4) = "Error" Then If TypeName(p3) = "Error" Then Line1(0) = p1(0) Line1(1) = p1(1) Line1(2) = p1(2) Line2(0) = p2(0) Line2(1) = p2(1) Line2(2) = p2(2) Else Line_Equation Line1, p1, p2 Line_Equation Line2, p2, p3 End If Else Line_Equation Line1, p1, p2 Line_Equation Line2, p3, p4 End If Dim dlt As Double Dim DltX As Double Dim DltY As Double dlt = Line1(0) * Line2(1) - Line2(0) * Line1(1) DltX = Line1(2) * Line2(1) - Line2(2) * Line1(1) DltY = Line1(0) * Line2(2) - Line2(0) - Line1(2) If Abs(dlt) < 0.000000001 Then If Abs(DltX) < 0.0000001 And Abs(DltY) < 0.0000001 Then LL_Inter = -1 Else LL_Inter = -2 End If Else LL_Inter = 0 'List1(0) = -DltX / Dlt 'List1(1) = -DltY / Dlt List1(1) = (Line1(0) * Line2(2) - Line2(0) * Line1(2)) / (Line2(0) * Line1(1) - Line1(0) * Line2(1)) List1(0) = (Line1(1) * Line2(2) - Line2(1) * Line1(2)) / (Line2(1) * Line1(0) - Line1(1) * Line2(0)) End If End Function
Sub Line_Equation(ByRef LParam() As Double, ByVal p1 As Variant, ByVal p2 As Variant) LParam(0) = p2(1) - p1(1) LParam(1) = p1(0) - p2(0) LParam(2) = -1# * LParam(0) * p1(0) - LParam(1) * p1(1) End Sub |