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:
- Generate a uniform angle $\varphi \in [0, 2\pi]$.
- Set $\mathbf a = (\cos \varphi, \sin \varphi)$.
- Uniformly generate angle $\theta \in \{ \varphi + \pi/2, \varphi - \pi/2 \}$ (only two values to generate from).
- Set $\mathbf b = (\cos \theta, \sin \theta)$.
For $n=3$, the situation already becomes more complicated...
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}$.