$nD$ rotation around a general $(n-2)$-dimensional subspace [duplicate]
Solution 1:
Here is one way to do this.
I assume that the $(n-2)$-dimensional fixed subspace $V$ is given as the orthogonal complement of the 2-dimensional space $W:=L(\vec{e}_1,\vec{e}_2)$ spanned by orthonormal vectors $\vec{e}_1,\vec{e}_2$.
Select two vectors $\vec{u},\vec{v}$ from $W$ such that their angular separation is $\theta/2$. For example, you can use $\vec{u}=\vec{e}_1$ and $\vec{v}=\cos(\theta/2)\vec{e}_1+\sin(\theta/2)\vec{e}_2$.
Recall that the orthogonal reflection $S_\vec{w}$ w.r.t. the hyperplane with normal $\vec{w}\in\Bbb{R}^n$ is given by the recipe $$ S_\vec{w}(\vec x)=\vec x-2\,\frac{\vec x\cdot\vec w }{\Vert\vec w\Vert^2}\,\vec w. $$
Also recall that the composition of two reflections of the plane w.r.t. two lines forming an angle $\theta/2$ is a rotation by $\theta$. See the animation below. The red arrow is the mirror image of the black arrow w.r.t. the blue line, and the orange arrow is the mirror image of the red arrow w.r.t. the green line. You see that angle between the black and orange arrows is a constant, and (do it if you haven't already, it's easy!) twice the angle between the green and blue lines.
The same holds with obvious modification in higher dimensional spaces. Therefore you get the rotation you want as the composition $$ R=S_\vec u\circ S_\vec v. $$ To get the matrix of this (given that you first have identified $\vec u$ and $\vec v$) just apply the above formula for both reflections to all the basis vectors.
The 2-dimensional image of the composition of two reflections suffices here as anything orthogonal to both $\vec u$ and $\vec v$ (i.e. anything orthogonal to all of $W$, i.e. anything from $V$) is a fixed point for both reflections.
There is a clockwise/counterclockwise ambiguity hidden in the choice of the order of $\vec{e}_1$ and $\vec{e}_2$. You can revert that by considering $R^{-1}=S_\vec v\circ S_\vec u$ instead.