Compute the interpolation factor between the SLERP of 2 quaternions, given those quaternions and the SLERP result I am looking for a way to calculate the value of t of quaternion SLERP by having three quaternions.
Forward direction:
Eigen::Quaternionf q = q1.slerp(t, q2);

where q, q1 and q2 are quaternions from the Eigen library. And t is a float which interpolates between q1 and q2.
I am interested in the backward calculation, where q, q1 and q2 is given and the output is t.
To make it easier all quaternions are normalized and also lying on the same plane which crosses the origin. See the illustration below:

qdoes NOT need to be within q1 and q2.
I found this link here but I don't know how to use that.
We can do this mostly by measuring angles between the quaternions, with a bit of sign flip to get the orientations right. Angles between normalized quaternions are given by the arccos of their dot product (as a 4D vector).
$$
t = \frac{\arccos(q_1 \cdot q)}{\arccos(q_1 \cdot q_2)} \ \text{sign}\bigl(q \cdot [q_2 - (q_1 \cdot q_2) q_1]\bigr)
$$
The first factor is measuring the angle from $q_1$ to $q$ as a fraction of the angle from $q_1$ to $q_2$. This ensures that $t$ will be 0 at $q_1$ and 1 at $q_2$. The other factor ensures that $t$ increases as you move from $q_1$ toward $q_2$ and goes negative on the other side. The quantity in brackets is the projection of $q_2$ on the (hyper)plane perpendicular to $q_1$, then we're dotting $q$ with that to decide which side of the circle we're on.
Note that the point where $t$ swaps from negative to positive will be the point opposite $q_1$ on the circle—not a point centered across from $q_1$ and $q_2$ as your diagram has it.
(Also, it's worth noting that this boils down to essentially the same thing as the logarithm solution in the other answer. Their factor $\check p/\|\check p\|$ corresponds to our sign factor: all the quaternions in the problem are in the same plane and so will have $\check p$ along the same axis; the only thing that can differ between the normalized $\check p$s is the sign.)