Say that we have two lines in two dimensions along the points $\vec{m} + s\vec{k}$ and $\vec{n} + t\vec{j}$ and we want to find the $s$ and $t$ for where these lines intersect. The obvious solution would be to solve the equations for the vector components:
$$\begin{cases} m_x + sk_x = n_x + tj_x \\ m_y + sk_y = n_y + tj_y \\ \end{cases}$$
However, in order to solve these, we have to divide by either $k_x$, $j_x$, $k_y$ or $j_y$ at some point, which introduces a special case for where this is zero.
Clearly, however, the basic geometry of the problem only introduces the intrinsic special case where the lines are parallel; I don't think I should have to care about the lines being parallel to some arbitrary coordinate axes. In particular, in order to solve these in computer code, I'd like to avoid introducing any unnecessary special cases which make the code ugly.
How to solve this problem without introducing any such arbitrary special cases?
I have one solution, in which I multiply the vectors defining the lines by a matrix which transforms $\vec{m}$ to $(0, 0)$ and $\vec{m} + \vec{k}$ to $(1, 0)$ (or, well, actually the homogenous variants of them with a $1$-element added to each, used as I am to OpenGL), as such:
$$ A = \begin{bmatrix} lk_x & lk_y & -l(m_xk_x + m_yk_y) \\ -lk_y & lk_x & l(m_xk_y - m_yk_x) \\ 0 & 0 & 1 \\ \end{bmatrix} $$ where $$ l = \frac{1}{|k|^2} $$
When I transform $\vec{n}$ and $\vec{j}$ with the same matrix and then solve the component-wise equations, I only get the special case where $(Aj)_y = 0$, which, of course, corresponds to the intrinsic special case of the lines being parallel.
This is nice and works and all, but I feel it is both a bit inelegant, and also suboptimal performance-wise when it comes to being implemented on a computer. What I really want to ask, then, is whether there's a simpler solution to this problem than mine.