Given:
- an $n$-dimensional vector $v = (v_1,\ldots,v_n) \in \mathbb{R}^n$
- an angle $\theta \in (0, \frac{\pi}{2})$
I am looking for a technique to construct a vector $w = (w_1,\ldots, w_n) \in \mathbb{R}^n$ such that:
$$\frac{v\cdot w}{\|v\|\|w\|} = \cos(\theta)$$
I am specifically interested in a way to do this for $n > 3$ dimensions (for $n \leq 3$, I think you could do it with rotation matrices).
I realize that when $n \geq 3$, there are an infinite number of feasible vectors $w$. I would be OK with any $w$ that satisfies the following criteria:
$v$ and $w$ are distinct: $v_i \neq w_i$ for all $i$.
all components of $w$ are non-zero: $w_i \neq 0$ for all $i$.
A "just wing it" algorithm which I think would be numerically stable is
Find a nonzero vector $u$ that is perpendicular to $v$, for example $$ u=(0,\ldots,0,v_j,0,\ldots,0,-v_i,0,\ldots,0)$$ where $v_i$ and $v_j$ are the numerically largest coordinates of $v$.
Normalize $u$ so its norm equals $\|v\|$.
Take $w=\cos(\theta)v+\sin(\theta)u$.
Note that $w$ does not depend continuously on $v$, but that is impossible when $n$ is odd, due to the hairy ball theorem. For even $n$ you can get continuity by taking $$ u = (v_2,-v_1,v_4,-v_3,\ldots) $$
If it's important to you to make all elements of $w$ nonzero, instead choose all elements of $u$ except one randomly (with some continuous distribution). Let the one you don't choose randomly correspond to the numerically largest coordinate of $v$; then you can easily solve for the value of that coordinate that will make $u\cdot v=0$.
Then each element of $ w $ will almost surely be nonzero.