当前版块:问答社区 > 综合讨论区

【分享】计算两条直线的交点

Public Type Point
  X As Double
  Y As Double
End Type
Public Type Lines
  P1 As Point
  P2 As Point
End Type
Const CROSS As Long = 0 '相交
Const COLINE As Long = 1 '共线
Const PARALLEL As Long = 2 '平行
Public Function GetPoint(L1 As Lines, L2 As Lines, P As Point) As Long
  Dim A1 As Double, B1 As Double, C1 As Double
  Dim A2 As Double, B2 As Double, C2 As Double
  Dim D As Double, R As Double
  
  A1 = L1.P2.Y - L1.P1.Y
  B1 = L1.P1.X - L1.P2.X
  C1 = L1.P2.X * L1.P1.Y - L1.P1.X * L1.P2.Y

  A2 = L2.P2.Y - L2.P1.Y
  B2 = L2.P1.X - L2.P2.X
  C2 = L2.P2.X * L2.P1.Y - L2.P1.X * L2.P2.Y
  
  D = A2 * B1 - A1 * B2
  If D = 0 Then
     If (A1 = A2) And (B1 = B2) Then
         GetPoint = COLINE
     Else
         GetPoint = PARALLEL
     End If
  Else
     P.X = (C1 * B2 - C2 * B1) / D
     P.Y = (A1 * C2 - A2 * C1) / D
     GetPoint = CROSS
  End If
End Function

全部评论

等级:LV30
积分:72050
奔跑蜗牛 2021-01-30 09:35
了解
回复 0
等级:LV30
积分:19099
新手572126 2021-01-30 14:41
收藏
回复 0
等级:LV30
积分:80686
五湖四海 2021-01-30 17:38
这是要干啥?
回复 0
等级:LV30
积分:38538
大海 2021-01-31 08:31
学习一下
回复 0
等级:LV25
积分:80
batty 2021-02-01 00:08
刚好遇到
回复 0
等级:LV30
积分:466
shq976 2021-02-01 07:12
感谢分享
回复 0
等级:LV30
积分:90
lengxu007 2021-02-02 08:18
了解了
回复 0
1
提交
悬赏回复规则
1、悬赏期为24小时,从发布时间起算;
2、悬赏期内提问者如设置评论为“精选评论”,视为悬赏结束,该精选评论人将获得本题全部悬赏积分;
3、悬赏期内如提问者未设置“精选评论”,则前5位评论者平分悬赏积分(如仅有一位评论,该评论者获得50%悬赏积分);
4、悬赏积分会自动发放到生态圈账户中,请留意站内信通知。
知道了

距离打开宝箱还剩7

是否花费200积分补签?
确认
取消