Hi
OK ,,, I will assume that you have 4 points ( or 2 points and 2 vectors) I don't exactly know the information you have . anyway the idea would be the same ...
notice that p3 is any point lies on Line1,p4 is any point lies on Line2
Ya = m1 * Xa + b1 Yb = m2 * Xb + b2
b1 = Ya - m1 * Xa
use p1 or p3
b1 = y1 - m1 * x1
b2 = y2 - m2 * x2
m1 = (y3-y1)/(x3-x1) , x3 # x1
m2 = (y4-y2)/(x4-x2) , x4 # x2
_____________
Ya = m1 * Xa + b1
Yb = m2 * Xb + b2
to find intersection point we let Ya = Yb = y , Xa = Xb = x
Ya = Yb
m1 * x + b1 = m2 * x + b2
m1 * x - m2 * x = b2 - b1
x (m1 - m2) = b2 - b1
x = (b2 - b1)/(m1 - m2)
notice : m1 never = m2 otherwise the are || i.e. never intersect
hence ,
mx1 = 1 /(x3-x1)
mx2 = 1 /(x4-x2)
m1 = (y3-y1) * mx1
m2 = (y4-y2) * mx2
b1 = y1 - m1 * x1
b2 = y2 - m2 * x2
x = (b2 - b1)/(m1 - m2)
y = m1 * x + b1 or y = m2 * x + b2
Option Explicit
Private Type Vector2D
X As Single
Y As Single
End Type
Private Sub Form_Load()
Dim P1 As Vector2D, P2 As Vector2D, P3 As Vector2D, P4 As Vector2D
P1 = SetV2(3000, 4000)
P3 = SetV2(1000, 1000)
P2 = SetV2(3000, 1000)
P4 = SetV2(1000, 3000)
Me.AutoRedraw = True
Line (P1.X, P1.Y)-(P3.X, P3.Y)
Line (P2.X, P2.Y)-(P4.X, P4.Y)
Me.Circle (P1.X, P1.Y), 100: Print " 1"
Me.Circle (P2.X, P2.Y), 100: Print " 2"
Me.Circle (P3.X, P3.Y), 100: Print " 3"
Me.Circle (P4.X, P4.Y), 100: Print " 4"
Dim IP As Vector2D
Dim M1 As Single, M2 As Single
Dim Mx1 As Single, Mx2 As Single
Dim B1 As Single, B2 As Single
Mx1 = IIf(P3.X = P1.X, 0, 1 / (P3.X - P1.X))
Mx2 = IIf(P4.X = P2.X, 0, 1 / (P4.X - P2.X))
M1 = (P3.Y - P1.Y) * Mx1
M2 = (P4.Y - P2.Y) * Mx2
B1 = P1.Y - M1 * P1.X
B2 = P2.Y - M2 * P2.X
IP.X = (B2 - B1) / (M1 - M2)
IP.Y = M1 * IP.X + B1
Me.ForeColor = RGB(255, 0, 0): Me.DrawWidth = 3
Circle (IP.X, IP.Y), 100: Print " IP"
End Sub
Private Function SetV2(X As Single, Y As Single) As Vector2D
SetV2.X = X
SetV2.Y = Y
End Function
regards