这个比较简单,各直线直接取2点 ,计算斜率!只有相等才是平行(这里是在一个平面)
下面是VB代码,计算的是正切 (TAN)
Option ExplicitConst xx As Double = 0.0000001Private Sub Command1_Click() MsgBox IsConnect(Line1, Line2)End Sub
Public Function IsConnect(Line1 As Line, Line2 As Line) As Boolean IsConnect = False
Dim Rate1 As Double Dim Rate2 As Double If Line1.X2 = Line1.X1 Then Rate1 = 0 Else Rate1 = (Line1.Y2 - Line1.Y1) / (Line1.X2 - Line1.X1) End If
If Line2.X2 = Line2.X1 Then Rate2 = 0 Else Rate2 = (Line2.Y2 - Line2.Y1) / (Line2.X2 - Line2.X1) End If
If Abs(Rate1 - Rate2) > xx Then IsConnect = True Else IsConnect = False End IfEnd Function