I have the following figure and want to find angle $\theta$ from the figure

I know the slope of the two lines can be obtained from :
\begin{align}
m1 = \frac{Y2 - Y1} {X2 - X1}
\end{align}
Similarly,
\begin{align}
m2 = \frac{Y4 - Y3}{X4 - X3}
\end{align}
Now i know that to find an angle between the given two lines is:
\begin{align}
\theta = \tan^{-1}(\frac{m2 - m1}{1 + m1*m2})
\end{align}
But i am not sure that the $\theta$ obtained is certainly the $\theta$ from my drawing.
Please help me out how I can resolve this.
From dot product between 2 vectors:
$$a \cdot b = |a||b|cos\theta \\ cos\theta = \frac{a \cdot b}{|a||b|} $$
Building vectors from coordinates:
$$a = (X1-X2, Y1-Y2) \\ b = (X3-X4, Y3-Y4) $$
To sum up it all together:
$$cos\theta = \frac{(X1 - X2)(X3-X4) + (Y1-Y2)(Y3-Y4)}{\sqrt{(X1-X2)^2 + (Y1-Y2)^2}\sqrt{(X3-X4)^2 + (Y3-Y4)^2}}$$