# How can I compute a rotation-invariant angle of a vector connecting two other vectors?

Suppose I have the vectors $$\mathbf{x}_1 = \begin{bmatrix} -1 \\ 1\end{bmatrix}$$ and $$\mathbf{x}_2 = \begin{bmatrix} 1 \\ 1\end{bmatrix}.$$ I want to compute the "orientation" of the vector $$\mathbf{x}_2 - \mathbf{x}_1 = \begin{bmatrix} 2 \\ 0\end{bmatrix}.$$ such that this "orientation" is rotation-invariant. That is, if $$\mathbf{x}_1$$ and $$\mathbf{x}_2$$ are rotated, then the value of this orientation would be the same. An unsuccessful way of doing this would be to compute the angle between $$\mathbf{x}_2 - \mathbf{x}_1$$ and the x-axis, but this angle will not be rotation-invariant. How can I compute the orientation of $$\mathbf{x}_2 - \mathbf{x}_1$$ such that it is rotation-invariant?

We are looking for a vector $$\mathbf{v}$$ such that the angle between $$\mathbf{v}$$ and $$\mathbf{x}_2 - \mathbf{x}_1$$ before rotation of $$\mathbf{x}_1$$ and $$\mathbf{x}_2$$, which is $$\arccos\left(\frac{\mathbf{v} \cdot (\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{x}_2 - \mathbf{x}_1||}\right),$$ is equal to the angle between $$\mathbf{v}$$ and $$\mathbf{x}_2 - \mathbf{x}_1$$ after rotation of $$\mathbf{x}_1$$ and $$\mathbf{x}_2$$, which is $$\arccos\left(\frac{\mathbf{v} \cdot (\mathbf{R}\mathbf{x}_2 - \mathbf{R}\mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{R}\mathbf{x}_2 - \mathbf{R}\mathbf{x}_1||}\right),$$ where $$\mathbf{R}$$ is a rotation matrix. Equating these two expressions yields \begin{align} \arccos\left(\frac{\mathbf{v} \cdot (\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{x}_2 - \mathbf{x}_1||}\right) &= \arccos\left(\frac{\mathbf{v} \cdot (\mathbf{R}\mathbf{x}_2 - \mathbf{R}\mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{R}\mathbf{x}_2 - \mathbf{R}\mathbf{x}_1||}\right) \\ \\ \frac{\mathbf{v} \cdot (\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{x}_2 - \mathbf{x}_1||} &= \frac{\mathbf{v} \cdot (\mathbf{R}\mathbf{x}_2 - \mathbf{R}\mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{R}\mathbf{x}_2 - \mathbf{R}\mathbf{x}_1||} \\ \\ \frac{\mathbf{v} \cdot (\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{x}_2 - \mathbf{x}_1||} &= \frac{\mathbf{v} \cdot \mathbf{R}(\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{R}(\mathbf{x}_2 - \mathbf{x}_1)||} \end{align} Since $$||\mathbf{x}|| = \sqrt{\mathbf{x}\cdot\mathbf{x}}$$, and since the dot product is invariant to rotation, then \begin{align} \frac{\mathbf{v} \cdot (\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{x}_2 - \mathbf{x}_1||} &= \frac{\mathbf{v} \cdot \mathbf{R}(\mathbf{x}_2 - \mathbf{x}_1)}{||\mathbf{v}|| \times ||\mathbf{x}_2 - \mathbf{x}_1||} \\ \\ \mathbf{v} \cdot (\mathbf{x}_2 - \mathbf{x}_1) &= \mathbf{v} \cdot \mathbf{R}(\mathbf{x}_2 - \mathbf{x}_1) \end{align} Again, since the dot product is invariant to rotation, then this equation is true when:
• the vector $$\mathbf{v}$$ on the left-hand side is $$\mathbf{x}_1$$ and the vector $$\mathbf{v}$$ on the right-hand side is $$\mathbf{R}\mathbf{x}_1$$, or
• the vector $$\mathbf{v}$$ on the left-hand side is $$\mathbf{x}_2$$ and the vector $$\mathbf{v}$$ on the right-hand side is $$\mathbf{R}\mathbf{x}_2$$.
In other words, the angle between $$\mathbf{x}_1$$ or $$\mathbf{x}_2$$ and $$\mathbf{x}_2 - \mathbf{x}_1$$ is invariant to rotation.