How to calculate the angle between two vectors without using the dot product?

1.1k Views Asked by At

Recently I needed to perform the convolution between a matrix and several predefined kernels, this can be broken down into point product operations. My problem then is this: given a vector $v$ compute the following products points: $v.u_{1}$, $v.u_{2}$ ...$v.u_{i}$ .... $v.u_{n}$. My idea to program this in an optimal way is the following: supposing that I have precalculated the norms $|u_{1}|$, $|u_{1}|$...$|u_{i}|$ ..... $|u_{n}|$ and that I calculate the norm of V (this is only necessary to do it once in time of execution) then each product point would be reduced to $|v_{1}||u_{1}|cos(alfa_{vu_{i}})$, where $alfa_{vu_{i}}$ is the angle between $v$ and $u_{i}$. However until now I have not found a more optimal way than the same dot product to calculate the angle between 2 vectors, or at least approximate it.

Extra information

To perform the convolution between an image $I$ and several kernels $U$, it is required to calculate the dot product between all the sub rectangle of $I$ and all the kernels $U$ (I assume the same size for all the kernels: width $w$ and height $h$). To calculate the norm of each sub-rectangle $|rect_{wh}(V)|$ in time of execution is very simple, for this first one calculates $I*I$ (multiplication of array) and then the integral image $S$ of $I*I$, in this way it can be calculated optimally $|rect_{wh}(V)|$ in each sub-angle in the following way: $\sqrt{S(i,j)+S(i+h,j+w)-(S(i,j+w)+S(i+h,j))}$, where $i$, $j$ are the kernel evaluation coordinates (top left) and $w$ and $h$ are the dimensions of the kernel.

Next I show how the convolution of a single kernel with an image is performed, in each position the operation $Rect_{wh}(I).u_{i}$ is performed.

enter image description here

Now suppose that this same image $I$ have to convolve with many kernels $u_{1}$, $u_{2}$ ... $u_{i}$ ... $u_{n}$, assuming you have an approximation of the $alfa$ angle, an efficient way that I have thought is to compute $|Rect_{wh}(I)||u_{i}|*cos(alfa)$, the norms of each kernels are pre-computed and the norm of each $Rect$ of $I$ is calculated using the integral image technique described in the following example:

enter image description here