Рет қаралды 3,765
In this video, I will show you how to find the intersection of two line segments in 2D. This is a simple but important concept in geometry, and it can be used in many different applications. I will explain the method step-by-step, and I will also provide some examples.
Points:
A(x1,y1)
B(x2,y2)
C(x3,y3)
D(x4,y4)
Given two line segments AB and CD, find the point of intersection P(x0, y0).
Solution:
Vectors:
A = (x1, y1)
B = (x2, y2)
C = (x3, y3)
D = (x4, y4)
AB = (x2 - x1, y2 - y1)
CD = (x4 - x3, y4 - y3)
A + αAB = C + βCD
α = ((x4 - x3)(y3 - y1) - (y4 - y3)(x3 - x1)) / ((x4 - x3)(y2 - y1) - (y4 - y3)(x2 - x1)) = a / b
β = ((x2 - x1)(y3 - y1) - (y2 - y1)(x3 - x1)) / ((x4 - x3)(y2 - y1) - (y4 - y3)(x2 - x1)) = c / b
P = (x0, y0)
x0 = x1 + α(x2 - x1) = x3 + β(x4 - x3)
y0 = y1 + α(y2 - y1) = y3 + β(y4 - y3)
/ edgardocpu