I'm trying to implement a distance on the circle on a computer and I can't come up with an optimized way of doing it.
What I mean is that I have numbers in $[0,2\pi]$ but I'm looking at them as a segment enrolled three times on the unit circle. So, $\frac{\pi}{6}$ and $\frac{11\pi}{6}$ are only $\frac{\pi}{3}$ far from each other. What I've been doing is translating one of the two numbers left and right by two pi, and taking the minimum distance. Thus my distance function looks like:
$$dist(\theta_1,\theta_2) = \text{min}(|\theta_1-\theta_2|,|\theta_1-\theta_2+2\pi|,|\theta_1-\theta_2-2\pi|)$$
But I have the feeling that there is an smarted way of doing it. Any suggestions?