For those who want details (nerds!), here's the problem statement and (the essentials of) the solution, all done mentally:
Given the following line segments expressed in parametric form, tell whether they intersect.(a + bt, c + dt), 0 <= t <= 1
(e + fs, g + hs), 0 <= s <= 1
So I set about solving for the value of s at which the two (infinite) lines would intersect.
a + bt = e + fs, c + dt = g + hs
t = (e + fs - a) / b = (g + hs - c) / d
b(g + hs - c) = d(e + fs - a)
bhs - dfs = d(e-a) - b(g-c)
s = [d(e - a) - b(g - c)] / (bh - df)
Voila!
1 comment:
You are so smart!
Post a Comment