In the process of modelling the interaction of charged particles on circle I encountered s.c. circular values calculations.
Consider unit circle and set some point $O$ as starting.
The position of any point is defined by parameter $0 \leq t < 1$ so $t(O) = 0$.
The simplest question: what is the shortest distance (on circle in parameter sense)
between points $t_1$ and $t_2$?
The answer is not complex, but not trivial:
$$\min(|t_1-t_2|, 1-|t_1-t_2|)$$
Mathematica:
circDist = Compile[{{t1, _Real}, {t2, _Real}},
Min[{#, 1 - #} &@Abs[t1 - t2]]];
But a little more complicated question: how to find the middle point of the shortest interval between points
caused some difficulties.
Based on this article, I wrote the function:
circMid[t1_, t2_] :=
With[{\[Phi]1 = 2 \[Pi] t1, \[Phi]2 = 2 \[Pi] t2},
Mod[ .5 ArcTan[Cos@\[Phi]1 + Cos@\[Phi]2,
Sin@\[Phi]1 + Sin@\[Phi]2]/\[Pi],1]];
It gives the right results. But for my purposes I need a very fast, compact function,
only with conditions and arithmetic operations.
Looking at the contour plot, it seems that one can write a not too complicated Piecewise function:
I would appreciate your help!
Generally there is very little information about circular values calculations. I found only this library in C++.
Maybe we should write a package for Mathematica. Especially since, for example, circular time calculations in Mathematica seem to work incorrectly.
For example:
TimeObject[{1}] - TimeObject[{23}]
Out: Quantity[-22., "Hours"]
Mean[{TimeObject[{22}], TimeObject[{1}]}]
Out: TimeObject[{11, 30, 0}]


