Assuming $a\cdot b = |a||b|\cos( \theta)$
and that $|a| = \sqrt{(x_1)^2 + (y_1)^2}$
and that $|b| = \sqrt{(x_2)^2 + (y_2)^2}$
Let $\gamma -\theta = \alpha$
For $\theta$ is the angle between the two vectors, $a$ and $b$, and not necessarily the angle between the 'outermost' line and say the x-axis.
Thus $\gamma$ is the angle between the outermost vector and the x-axis, whilst $\alpha$ is the angle between the other line and the x-axis.
Thus $\theta=\gamma-\alpha$ and more importantly by the trig identity: $\cos(a+b) = \cos(a)\cos(b)-\sin(a)\sin(b)$
$$\begin{equation}\begin{aligned}
a\cdot b &= |a||b|\cos(\theta)\\
&=|a||b|\cos(\gamma - \alpha)\\
&=|a||b|\biggl(\cos(\gamma)\cos(\alpha) - \sin(\gamma)\sin(\alpha)\biggl)\\
&=|a||b|\cos(\gamma)\cos(-\alpha) - |a||b|\sin(\gamma)\sin(-\alpha)\\
\end{aligned}\end{equation}\tag{1}$$
Then if $|a|$ was the outermost vector you realize that
$|a|\cos(\gamma) = (x_1)$, and that
$|a|\sin(\gamma) = (y_1)$
Making $|b|$ the innermost line, and that
$|b|\cos(-\alpha) = |b|\cos(\alpha) = (x_2)$, and that
$|b|\sin(-\alpha) = -|b|\sin(\alpha) = (-y_1)$
Because $\cos(-a) = \cos(a)$ and $\sin(-a) = -\sin(a)$
Plugging all that into 1 you get that $a\cdot b = (x_1)(x_2) - (y_1)(-y_2)$
And you finally get $a\cdot b = (x_1)(x_2) + (y_1)(y_2)$