2. Given two skew lines $a$ and $b$ forming an angle $\theta$, and their common perpendicular $A A^{\prime}$ with length $d$. Take points $E$ and $F$ on lines $a$ and $b$ respectively, with $A^{\prime} E=m$ and $A F=n$. Find $E F$ (where $A^{\prime}$ is on line $a$ and $A$ is on line $b$).
As shown in the figure, draw $b^{\prime} / / b$ through $A^{\prime}$, and draw $F H / / A A^{\prime}$, intersecting $b^{\prime}$ at $H$. Connect $H E$.

In $\triangle A^{\prime} E H$, $E H^{2}=m^{2}+n^{2}-2 m n \cos \theta$
$\Rightarrow E F^{2}=d^{2}+m^{2}+n^{2}-2 m n \cos \theta$.
When $E^{\prime}$ is on the other side of $A^{\prime}$, $E^{\prime} F^{2}=d^{2}+m^{2}+n^{2}+2 m n \cos \theta$.
In summary, $E F=\sqrt{d^{2}+m^{2}+n^{2} \pm 2 m n \cos \theta}$.