Alternatively, just use geometric algebra instead of quaternions.
> Beyond 4D, you could continue using NxN rotation matrices, but since GPUs don’t support that, I’d use rotors from Geometric Algebra to simplify implementation, which is how you generalize quaternions to higher dimensions.
All hail Clifford! https://arxiv.org/abs/1401.2371 for elegant and computationally efficient methods