Calculating pairwise distance of two N-dimensional vectors given their length and angle

113 Views Asked by At

I am not a mathematician, so apologies in advance for any nomenclature blasphemy. Given the magnitudes of two vectors $b$ and $c$ and the angle between them $A$, I can calculate their distance in 2-D as:

enter image description here

($b$ and $c$ don't have directions in the image but assume both are vectors and pointing upward.)

$a^2 = b^2 + c^2 - 2bc*cos(A) $

Now, I have N of these and I am trying to find the overall distance between $b$ and $c$. In other words, my matrix looks something like

   Dim(1,2) | Dim(3,4) | Dim(5,6) | ... | Dim(N,N-1)   
b     3          2          5                1
c     4          1          9       ...      11
A     30        140         45      ...      90

As given above, focusing just on column Dim(1,2), which is my 1st feature, I can calculate the distance $a_1$ as above. Does this generalise in anyway to N features? In other words, can I come oup with a distance function that is analogous to $a^2 = b^2 + c^2 - 2ab*cos(A)$ but applies to N dimensions? I hope the question is clear enough.

P.S: Obviously, I can find $a_i$ per each feature ($column_i$) and then take the average, but I was hoping there would be a more principled way to solve this mathematically?