How to deterministically pick a vector that is guaranteed to be non-parallel to the given one?

589 Views Asked by At

I have a unit vector $u = (x1, y1, z1)$ in $R^3$, given $(x1, y1, z1)$ are known rational numbers.

I need to deterministically pick a unit vector $v = (x2, y2, z2)$, such that $v$ and $u$ are not parallel, so ||${\bf u} \times {\bf v}$|| $\neq 0$.

$x2, y2, z2$ values can likely be derived from $x1, y1, z1$, but I can't figure out how exactly.

3

There are 3 best solutions below

1
On BEST ANSWER

If $z1=\pm 1$, then the unit vector is completely determined, $u=(0, 0,\pm 1)$, so you can take $v=(0, \pm 1,0)$ for example. Note that this is an equivalence, $|z1| =1 \Longleftrightarrow x1=y1=0$

If $z1 \neq \pm 1$ then take $v=(-y1, x1, z1) $. The $z$ coordinate in the cross product is $x1^2 +y1^2$ which is different from zero.

1
On

Based on the answer you accepted, your notion of “deterministic” allows conditional evaluation. In that case, for any vector $\mathbf v = (x,y,z)\ne0$, the vectors $(0,z,-y)$, $(-z,0,x)$ and $(y,-x,0)$ (which are the cross products of $\mathbf v$ with the standard basis vectors) are all orthogonal to $\mathbf v$. At least two of them are nonzero: choose one. You can make this choice deterministic by always taking, say $(0,z,-y)$ unless that is zero, in which case take $(-z,0,x)$.

2
On

Option 1:

Unless $x1=y1=z1$, the permuted vector $(y1, z1, x1)$ is guaranteed to not be parallel to $(x1, y1, z1)$.

Intuitively this is achieved by rotating $u$ 90° in the x-axis and then 90° in the y-axis.

In 3D the rotation matrices are:

$\begin{alignat}{1} R_x(\theta) &= \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\[3pt] 0 & \sin \theta & \cos \theta \\[3pt] \end{bmatrix} \\[6pt] R_y(\theta) &= \begin{bmatrix} \cos \theta & 0 & \sin \theta \\[3pt] 0 & 1 & 0 \\[3pt] -\sin \theta & 0 & \cos \theta \\ \end{bmatrix} \\[6pt] R_z(\theta) &= \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\[3pt] \sin \theta & \cos \theta & 0\\[3pt] 0 & 0 & 1\\ \end{bmatrix} \end{alignat}$

The resulting rotation is

$\begin{alignat}{1} R_x(\theta) &= \begin{bmatrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\[3pt] 0 & 1 & 0 \\[3pt] \end{bmatrix} \\[6pt] \end{alignat}$

This has eigenvector $(1, 1, 1)$ and so only vectors with $x1=y1=z1$ will end up parallel (or antiparallel) to themselves under this transformation.

In the case where $x1=y1=z1$, you can just use $(-x1, y1, z1)$.

Option 2:

Convert to spherical coordinates, and then just add $\frac{\pi}{2}$ to either of the angles, say $\theta$.