[Math] How to turn the dot product of two normalized vectors into a percentage

vectors

When my vectors are perpendicular (90 degrees off) the dot product is 0, and when they are parallel (0 degrees off) the dot product is 1, but half way between these two states (45 degrees off) the dot product is around 0.7.

I'd like to manipulate the dot product to get a new value that represents "percentage aligned", so in the case above, half way between perpendicular and parallel, I would get the value 0.5, and the value would proceed in a linear fashion as you approach 0 or 1.

Thanks!

Best Answer

Observe that $\frac{a \cdot b}{|a||b|}=\cos{\theta}$ is the geometric definition of a dot product. Therefore $\theta = \arccos{\frac{a \cdot b}{|a||b|}}$ is the angle between the two vectors. A percentage is just a portion of a total yes? Here your total is $90^\circ$

I would then think that $\dfrac{\theta}{90^\circ}$ is your "percentage aligned". Let's test it.

Take 2 vectors at a $45^\circ$ angle say, $a = (0,1)$ and $b = (1,1)$ then $\frac{a \cdot b}{|a||b|} = \frac{(0,1) \cdot (1,1)}{1\cdot\sqrt{2}} = \frac{1}{\sqrt{2}} $

So $\theta = \arccos{\frac{1}{\sqrt{2}}} = 45^\circ$ and therefore $\frac{\theta}{90^\circ}=\frac{45^\circ}{90^\circ}=0.5$

Now you may ask why I calculated $\theta$ when I already knew it was $45^\circ$, it was just to show the full working, in general you would have to find the angle first.

Random Example

Take 2 vectors say, $a = (0,5)$ and $b = (1,5)$ then $\frac{a \cdot b}{|a||b|} = \frac{(0,5) \cdot (1,5)}{5\cdot\sqrt{26}} = \frac{25}{5\sqrt{26}} $

So $\theta = \arccos{ \frac{25}{5\sqrt{26}}} = 11.31^\circ$ and therefore $\frac{\theta}{90^\circ}=\frac{11.31^\circ}{90^\circ}=0.125$

This looks like a good "percentage aligned" as $b$ is close to the x-axis and 0.125 is small.

Random Example 2

Take 2 vectors say, $a = (0,5)$ and $b = (5,1)$ then $\frac{a \cdot b}{|a||b|} = \frac{(0,5) \cdot (5,1)}{5\cdot\sqrt{26}} = \frac{5}{5\sqrt{26}} $

So $\theta = \arccos{ \frac{1}{\sqrt{26}}} = 78.69^\circ$ and therefore $\frac{\theta}{90^\circ}=\frac{78.69^\circ}{90^\circ}=0.874$

This looks like a good "percentage aligned" as $b$ is close to the y-axis and 0.874 is large.

Here (If this is what you are asking) tending to 0 would mean parallel and tending to 1 would be perpendicular.