Generate N “equally spaced” vectors on the unit sphere

geometrytrigonometryvectors

I want to generate a list of vectors $\{\mathbf{v}_i\}, i\in[1,N]$ such that

$$\mathbf{v}_i\cdot\mathbf{v}_i = 1, \forall i$$

$$\mathbf{v}_i\cdot\mathbf{v}_j = \cos\theta, \forall i\neq j$$

$$\sum_{i=1}^N \mathbf{v}_i = 0$$

$$\mathbf{v}_1=(1,0,0)$$

$$\mathbf{v}_2=(\cos\theta,0,\sin\theta)$$

For $N=2$, we have $\mathbf{v}_1=(1,0,0), \mathbf{v}_2=(-1,0,0), \theta=\pi$.

For $N=3$, we have $\mathbf{v}_1=(1,0,0), \mathbf{v}_2=(-1/2,0,\sqrt{3}/2), \mathbf{v}_2=(-1/2,0,-\sqrt{3}/2),\theta=2\pi/3$.

etc.

I would like to be able to generate this list of vectors for arbitrary $N$. I can do it by hand, but I want to add this to some python code. I tried to come up with an iterative way of doing it, but I lose track of all the vector components I have to solve for pretty quickly. What is the simplest way to do this?

$N$ is not going to be huge — let's say $N=30$ at most. Because of this, and because this generation will be done once in my code, I'm not super worried about the performance of the python code that I will implement.

Best Answer

One way to handle the problem is to let $V$ be a matrix whose columns are the desired vectors. Then the Gram matrix $M=V^\top V$ satisfies $M_{ij}=\mathbf{v}_i\cdot \mathbf{v}_j$, so the constraints specify $M_{ij}=\cos\theta$ if $i\neq j$ and $1$ otherwise. The assumption that $\sum_{i}\mathbf{v}_i=0$ further amounts to the claim that $Vu=0$ where $u$ is a column vector of 1s. But then $Mu=V^\top Vu=0$, whereas one can show that the characteristic polynomial of $M$ is $$\det(M-\lambda I_N)=(1-\cos\theta-\lambda)^{N-1} (1+(N-1)\cos\theta-\lambda).$$ So if we assume the vectors are not collinear, we must have $\cos\theta=-1/(N-1)$ for $M$ to have a zero eigenvalue. The determinant furthermore shows that $M$ will have $N-1$ eigenvectors of eigenvalue $\lambda=1-\cos\theta=N/(N-1)$. This gives us $N-1$ of the needed vectors, with the last vector being deduced from $\sum_i \mathbf{v}_i=0$. Hence the $N$ vectors must be at least $(N-1)$-dimensional, e.g., we must go up to at least dimension 29 if we want 30 such vectors.