There's a really elegant solution using Geometric Algebra, that to this day is one of the most satisfying things I've ever learnt. Steven de Keninck outlines it in his 2019 Siggraph talk [1].
[1] https://youtu.be/tX4H_ctggYo?t=4795