Given two points $\mathcal{A}$ and $\mathcal{B}$ in $\mathbb{R^3}$ whose position and velocity vectors are, respectively:
$$\mathbf{r_A}=\begin{pmatrix}r_{A_{x}}\\r_{A_{y}}\\r_{A_{z}}\end{pmatrix}$$
$$\mathbf{r_B}=\begin{pmatrix}r_{B_{x}}\\r_{B_{y}}\\r_{B_{z}}\end{pmatrix}$$
$$\mathbf{v_A}=\begin{pmatrix}v_{A_{x}}\\v_{A_{y}}\\v_{A_{z}}\end{pmatrix}$$
$$\mathbf{v_B}=\begin{pmatrix}v_{B_{x}}\\v_{B_{y}}\\v_{B_{z}}\end{pmatrix}$$
How would you calculate the relative velocity of $\mathcal{A}$ with respect to $\mathcal{B}$ and the opposite, given random position and velocity?
For example: if the two points are moving in the same direction, you would calculate the velocity of $\mathcal{A}$ relative to $\mathcal{B}$ with the following formula: $$\mathbf{v_{AB}}=\begin{pmatrix}v_{A_{x}}\\v_{A_{y}}\\v_{A_{z}}\end{pmatrix}-\begin{pmatrix}v_{B_{x}}\\v_{B_{y}}\\v_{B_{z}}\end{pmatrix}=\begin{pmatrix}v_{A_{x}}-v_{B_{x}}\\v_{A_{y}}-v_{B_{y}}\\v_{A_{z}}-v_{B_{z}}\end{pmatrix}$$