Sorry about formatting, this is my first question here, and I have no idea how to do it properly.
Assuming I have two lines
$\displaystyle l_1 = \binom{x_1}{y_1} + a\binom{u_1}{v_1}$
$\displaystyle l_2 = \binom{x_2}{y_2} + b\binom{u_2}{v_2}$
Thus the intersection holds
$\displaystyle \binom{x_1}{y_1} + a\binom{u_1}{v_1} = \binom{x_2}{y_2} + b\binom{u_2}{v_2}$
and have made sure those two lines will intercept (so $u_1,v_1$ and $u_2,v_2$ aren't parallel), how do I find the intersection point elegantly?
Currently (I am using this in a C++ code), I need to do a lot of if() cases, since I cannot divide by 0, but in order to find the point, I need to substitute b in the formula
I get
$a = \dfrac{x_2-x_1+bu_2}{u_1}$
so here I have to check for $u_1\neq0$, and then substitute in the second line, where I then need to check for $v_2\neq0$, and this creates one hell a lot of code.
Is there a better way, am I just missing something easy?
((x1-x0)*v1 - u1*(y1-y0)) / (u0*v1 - u1*v0)after cancelling out some negatives. The subscripts are now zero-based as it's code, not maths. – fadedbee Jul 28 '22 at 18:05(x0,y0)->(x0+u0, y0+v0)the intersection happens. (I assume that this is in units of the segment length, but I haven't confirmed it as I'm using unit segments.) If the denominator is zero, there is no intersection. – fadedbee Aug 29 '22 at 10:38