Generate two random orthogonal vectors on a unit $n$-dimensional sphere

1k Views Asked by At

I want to uniformly generate two $n$-dimensional orthogonal vectors $\mathbf a, \mathbf b \in \mathbb R^n$ on a unit $n$-dimensional sphere. In other words, the vectors should satisfy $$ \begin{cases} a_1^2 + a_2^2 + \dotsb + a_n^2 = 1, \\ b_1^2 + b_2^2 + \dotsb + b_n^2 = 1, \\ a_1 b_1 + a_2 b_2 + \dotsb a_n b_n = 0. \end{cases} $$

The problem for me is to generate them uniformly over their set.

If $n=2$, I would generate like this:

  1. Generate a uniform angle $\varphi \in [0, 2\pi]$.
  2. Set $\mathbf a = (\cos \varphi, \sin \varphi)$.
  3. Uniformly generate angle $\theta \in \{ \varphi + \pi/2, \varphi - \pi/2 \}$ (only two values to generate from).
  4. Set $\mathbf b = (\cos \theta, \sin \theta)$.

For $n=3$, the situation already becomes more complicated...

3

There are 3 best solutions below

1
On BEST ANSWER

Draw a standard $n$-dimensional Gaussian vector, and normalize it to have unit norm. This is your first vector $\mathbf{a}$.

Form an orthonormal basis $\{\mathbf{a}, \mathbf{v}_1, \ldots, \mathbf{v}_{n-1}\}$ containing $a$ (e.g. using Gram-Schmidt). Draw an $(n-1)$-dimensional Gaussian vector, normalize it to have unit norm. Let this vector be $\mathbf{u}$, and let $\mathbf{b} = u_1 \mathbf{v}_1 + \cdots + u_{n-1} \mathbf{v}_{n-1}$. This vector will have unit norm and will be uniformly drawn from the unit sphere in the $(n-1)$-dimensional subspace orthogonal to $\mathbf{a}$.

3
On

I'm not sure if this suits your purposes but here's an idea. This works well if you are intending to implement a computer algorithm.

Choose a vector $v$ uniformly in a cube centered at the origin $[-1,1]^n$. This means that you only have to choose the Cartesian components independently and uniformly on $[-1,1]$. Check the magnitude of $v$. If it's less than 1, keep it. Else, throw it away and run the same procedure over and over until it is. Now, normalize $v$ onto the unit sphere. It is clear that this scheme works better for low-dimensional spheres since the ratio of the volume of the sphere to that of its circumscribed cube goes to $0$ as the dimension goes to infinity.

Run the same procedure for a vector $u$.

At this point, you have chosen two vectors uniformly on the unit sphere. Now we simply apply the Gram-Schmidt algorithm:

Keeping $v$ fixed, let $w=v-(v\cdot u)u$ and then normalize. $\{v,w\}$ should be what you want.

0
On

There is a well-known method to generate one vector uniformly distributed on the surface of a sphere. See Can one sample uniformly from the surface of an $n$-sphere of non-unit radius using normal r.v.'s? or Algorithm to generate random points on n-Sphere?

Generate random vector $\mathbf a$ using this method.

Generate a second random vector $\mathbf v$ using the same method. Project this vector on to $\mathbf a$ to obtain $\mathbf v_{\mathbf a}.$ Let $\mathbf v' = \mathbf v - \mathbf v_{\mathbf a}.$ That is, $\mathbf v'$ is the projection of $\mathbf v$ onto the $(n-1)$-dimensional hyperplane orthogonal to $\mathbf a.$

The distribution of $\mathbf v'$ is a non-uniform distribution within the $(n-1)$-dimensional unit ball within the hyperplane. It has a higher density near the center of the ball than near the boundary. But the distribution is radially symmetric, so when you set

$$ \mathbf b = \frac{1}{\lVert\mathbf v'\rVert} \mathbf v' $$

you obtain a uniform distribution on the unit sphere in the hyperplane orthogonal to $\mathbf a,$ which is exactly what you need.