[Math] Finding an orthonormal basis with only one vector

orthonormalvectors

I'm programming a little thing to project things to my screen from a variable amount dimensions, and when I tried to implement the ability to move the origin and rotate the direction looked in strange things started happening.

As a starting point I have one polar vector, the screen vector (in my program it defines how far the screen is from the origin and in which direction it is pointing).
In my initial attempt I just generated the basis by normalizing it and subtract $ \frac{\pi}{2} $ from the second index to get the second basis vector and repeat that for the others.
Then of course I convert all polar vectors to vectors.

What really happened was that the sphere that was loaded in collapsed into an ellipsoid when the vector was rotated.

In the attempt I'm trying to make I read up on a few other questions here, and most answers suggest use of the Gram-Schmidt algorithm.

The problem I'm having is I can't really think of a way to use that with only one starting vectors and end up with $n$ basis vectors.
A thing I was thinking of to do was to use random starting vectors, but I fear that will not be consistent.

How do I apply the Gram-Schmidt algorithm to only one vector to consistently get all basis vectors?

EDIT:
By the way, that basis is then used to transform the coordinates of the points into the observers frame.
If there's a way to avoid finding a basis for the vector and transforming the points that will do fine for me.

Best Answer

(Edit: simplified the whole procedure)

What you need to do is find a basis that contains your starting vector $v\neq 0$. You can do it by starting with $S = \{ v,e_1, e_2,\ldots,e_n\}$ where $\{e_1,\ldots,e_n\}$ is a known (orthonormed) basis. Apply Gram-Schmidt to this set. Note that $S$ is generating set for $\mathbb R^n$, but not a base. This doesn't matter, since Gram-Schmidt guarantees that the superflous vector will become zero. That way we obtain orthonormed base $\{v',e_1'\ldots,\hat e'_i,\ldots,e'_n\}$ (where $\hat e_i$ means that the vector is omitted).

Now, define matrix $O = [v'\ e_1'\ldots\ \hat e'_i\ \ldots\ e'_n]$ (where the vectors are written as columns in the standard orthonormal base $\{e_1,\ldots,e_n\}$). Since columns of $O$ form orthonormal base for $\mathbb R^n$, the matrix $O$ is orthogonal. That means that it is either rotation or reflection. If $\det O = 1$, then $O$ is rotation that maps $e_1$ to $v$ and the rest of the standard orthonormal base to orthonormal base obtained by Gram-Schmidt, and we are done. If $\det O = -1$, switch any two columns in $O$ to obtain rotation.

Related Question