直线方程一般式:A1x+B1y+C1=0
直线方程一般式:A2x+B2y+C2=0
求解二元一次方程组的问题
没有解,两条直线平行
无数解,两条直线重合
一个解,两条直线相交
用代入法求解
X = (B1 * C2 - B2 * C1) / (B2 * A1 - B1 * A2)
Y = (A1 * C2 - A2 * C1) / (A2 * B1 - A1 * B2)
Public Shared Function 直线与直线的交点_2D(ByVal A1 As Double, ByVal B1 As Double, ByVal C1 As Double, _
ByVal A2 As Double, ByVal B2 As Double, ByVal C2 As Double) As Point2d
If A1 = 0 And B1 = 0 Then Exit Function 'A1 B1 不能同时为零
If A2 = 0 And B2 = 0 Then Exit Function 'A1 B1 不能同时为零
Dim K1 As Double ' 直线1的斜率
Dim K2 As Double ' 直线2的斜率
Dim X As Double
Dim Y As Double
If B1 * B2 <> 0 Then
K1 = -A1 / B1
K2 = -A2 / B2
If K1 = K2 Then
'Exit Function '两条直线平行
Return Nothing
Else
X = (B1 * C2 - B2 * C1) / (B2 * A1 - B1 * A2)
Y = (A1 * C2 - A2 * C1) / (A2 * B1 - A1 * B2)
End If
ElseIf B1 = 0 Then
X = (B1 * C2 - B2 * C1) / (B2 * A1 - B1 * A2)
Y = (A1 * C2 - A2 * C1) / (A2 * B1 - A1 * B2)
ElseIf B2 = 0 Then
X = (B1 * C2 - B2 * C1) / (B2 * A1 - B1 * A2)
Y = (A1 * C2 - A2 * C1) / (A2 * B1 - A1 * B2)
ElseIf B1 = 0 And B2 = 0 Then
'B1 B2 同时为零
'Exit Function '两条直线平行
Return Nothing
End If
Return New Point2d(X, Y)
End Function
[本日志由 tiancao1001 于 2018-01-06 02:29 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |