# Perpendicular vectors in 3d

Suppose a vector $v$ in $\mathbb{R}^3$

How can I find two arbitrary unit vectors $u$ and $u^*$, that are perpendicular to each other and $v$ ?

There are infinitely many solutions, but I cannot hand pick them. I need some function $Q(v)$ = $(u, u^*)$ that deterministically finds a solution, for all non-zero vectors in $\mathbb{R}^3$.

This is probably a quaternion question, but I would prefer notation in terms of linear algebra.

$$u^\star = a \times u$$

Pick an arbitrary vector $a$ which is not parallel to $u$ and do a cross product. The result is perpendicular to both vectors. You can use a fixed vector such as $a=\hat{x}$, $a=\hat{y}$ or $a=\hat{z}$ by selecting the least parallel (lowest $a\cdot u$ value).

Alternatively pick any point is space with coordinates $(a,b,c)$ and construct a 3×3 rotation matrix where each column is a unit mutually perpendicular vector

\begin{align} E(a,b,c) & = \begin{bmatrix} \frac{\sqrt{b^2+c^2}}{\sqrt{a^2+b^2+c^2}} & 0 & \frac{a}{\sqrt{a^2+b^2+c^2}} \\ \frac{-a b}{\sqrt{a^2+b^2+c^2}\sqrt{b^2+c^2}} & \frac{c}{\sqrt{b^2+c^2}} & \frac{b}{\sqrt{a^2+b^2+c^2}} \\ \frac{-a c}{\sqrt{a^2+b^2+c^2}\sqrt{b^2+c^2}} & \frac{-b}{\sqrt{b^2+c^2}} & \frac{c}{\sqrt{a^2+b^2+c^2}} \end{bmatrix} \end{align}

• You can pick a random $a$ and then subtract the parallel projection to $u$. Like $$a \leftarrow a - u \frac{a \cdot u}{u \cdot u}$$ – ja72 May 21 '15 at 18:59
• Or you can pick from $a=\hat{x}$, $a=\hat{y}$ or $a=\hat{z}$ depending which one gives the lowest $a \cdot u$. – ja72 May 21 '15 at 19:00

One way would be to apply (slightly modified) Grahm Schmidt to the vectors $v,e_1,e_2,e_3$. Any basis will do, of course.

The slight modification is to ignore an intermediate vector that ends up being zero, such as would happen if, for example, $v = e_2$.

(The resulting function will not be continuous.)

First pick vector $w$ which is non-parallel to $v$.

As long as $w\neq r*v$, where $r \in \Bbb R$, $w$ is non-parallel to $v$.

Let $u =w\times v$, this guarantee u is perpendicular to $v$ and $w$ vectors.

Then $u' =v\times u$, this guarantee $u'$ perpendicular to $v$ and $u$.

You have found $u$, $u'$ and $v$ which are mutually perpendicular.