Disclaimer: first time using quaternions.
I needed to determine the distance between a orientation given by quaternion $q_1$ and a target orientation $q_t$. Both quaternions are normalized. Therefore: $$d = 2(1-q_1 \cdot q_t)$$
This works very well, but now I need to extend the problem to ignore one axis of rotation (the z-axis in my illustration, pardon my bad drawing skills).
Instead of the distance to a single orientation, drawn as one arrow, I require to know the distance to the entire circle of possibilities.
I figured I need to remove the yaw part of the two quaternions. Is this possible, preferably without converting to euler angles? Thank you in advance!

Although the following solution doesn't answer how to solve this problem using quaternions, it does solve how to find the shortest rotation when ignoring one axis.
Using two of the three Euler angles (roll/pitch/yaw), this problem can be solved simply. In my case, I used roll and pitch.
My thought process:
It turns out, this can all be done with one equation, the Great-circle distance equation. See the linked formula.
Code: