I am developing a software, and it is heavily reliant on "orientations" of particles in the system. Take the following diagram for example.

I have two particles at location $A$ and $B$, in 3D space. The have vector orientations $o_1$ and $o_2$ (that are also 3D). The vector $d=B-A$ is the vector joining points A and B. The two particles at $A$ and $B$ interact with each other with energy between $E^a$ (aligned) and $E^{a'}$ (not aligned). A perfectly aligned interaction is shown in the center configurations -- the orientations are antiparallel to one another, and pointing at one another. Hence, the energy of interaction between particles is $E^a$. The configuration in the right most image is perfectly not aligned and the energy of the interaction is $E^{a'}$. If the two orientation are parallel, I have the midpoint of the interactions, $(E^a+E^{a'})/2$, as seen in the leftmost figure.
- I am looking for a norm that captures how "aligned" or how "not aligned" two vectors are.
So that I can set up an energy function which goes like \begin{align} E = xE^{a'} + (1-x) E^a \text{ or } E = (1-x)E^{a'} + xE^a \end{align} where $x$ is a measure for how aligned or how misaligned the two vectors are. So far I have come with $$ x = \frac{\sin \left( \frac{\theta _2 - \theta _1}{2} \right)+1}{2}$$ where $\theta_1$ is the anticlockwise angle between $d$ and $o_1$ and $\theta _2$ is the angle between $d$ and $o_2$. This at first glance makes sense in $2D$, but I start seeing counterexamples once I hit 3D. For example, if I rotate $o_2$ goes out of plane and into the positive z-axis, the angle between d and $o_2$ is still 90, but it is further away from the tip of $o_1$. How do I account for non-planarity and the fuzziness it brings to my measure $x$? I assume I have to include angles between planes to metric $x$, but I do not how to do it.
Any advice you have for me will be appreciated!