# Modular Visualization

I have this:

Graphics[{
Circle[],
Line[{0.9 {Cos[π/2], Sin[π/2]}, {Cos[π/2], Sin[π/2]}}],
Text["0", 1.2 {Cos[π/2], Sin[π/2]}],
Line[{0.9 {Cos[11 π/6], Sin[11 π/6]}, {Cos[11 π/6], Sin[11 π/6]}}],
Text["1", 1.2 {Cos[11 π/6], Sin[11 π/6]}],
Line[{0.9 {Cos[7 π/6], Sin[7 π/6]}, {Cos[7 π/6], Sin[7 π/6]}}],
Text["2", 1.2 {Cos[7 π/6], Sin[7 π/6]}]
}, ImageSize -> 200
]


Which gives this image:

Now, I'd like to visualize Mod[5, 3], starting with an arrow at $0$, then rotating around the outside of the circle in the clockwise direction, counting 1, 2, 3, 4, 5 as I pass each tick number, then halting the arrow.

And I think the preference would be that the distance of the arrow from the center of the circle increases as I move so it doesn't overly itself as it goes.

Any suggestions?

Update I managed to do this:

modularcount = Graphics[{
Circle[],
Line[{0.9 {Cos[\[Pi]/2], Sin[\[Pi]/2]}, {Cos[\[Pi]/2],
Sin[\[Pi]/2]}}],
Text["0", 0.8 {Cos[\[Pi]/2], Sin[\[Pi]/2]}],
Line[{0.9 {Cos[11 \[Pi]/6], Sin[11 \[Pi]/6]}, {Cos[11 \[Pi]/6],
Sin[11 \[Pi]/6]}}],
Text["1", 0.8 {Cos[11 \[Pi]/6], Sin[11 \[Pi]/6]}],
Line[{0.9 {Cos[7 \[Pi]/6], Sin[7 \[Pi]/6]}, {Cos[7 \[Pi]/6],
Sin[7 \[Pi]/6]}}],
Text["2", 0.8 {Cos[7 \[Pi]/6], Sin[7 \[Pi]/6]}]
}, ImageSize -> 200];
plt = PolarPlot[1.1 + 0.03 t, {t, Pi/2, Pi/2 + 10 Pi/3},
PlotStyle -> Red] /. Line -> Arrow;
Show[modularcount, plt,
Graphics[{Red, Line[{{0, 1.1}, {0, 1.2}}]}]]


I've put the numbers inside. Which gives this image:

So I have a good solution when moving counterclockwise, but I haven't figured out how to go clockwise yet.

Second Update: Thanks to Quantum_Oli, I now have this:

Show[modularcount, Graphics[First[plt] /. {x_, y_} :> {-x, y}],
Graphics[{Red, Line[{{0, 1.1}, {0, 1.2}}]}]]


Which gives this image:

• One simply (kinda hack-y) way would be to replace plt in your Show with Graphics[First[plt] /. {x_, y_} :> {-x, y}]. Saves having to change anything else. Apr 18, 2016 at 17:01
• @Quantum_Oli Thanks, that works. See my update to the original post. Apr 18, 2016 at 17:11
• David: If that solves your problem, why not make a self-answer instead of editing the solution into the question? (Or let @Quantum_Oli post it.) Apr 18, 2016 at 17:16
• You may be interested in ExperimentalAngularSlider[2/5 Pi 16 ]
– Kuba
Apr 19, 2016 at 6:55

So the quick hack I posted in the comment works:

Graphics[First[plt] /. {x_, y_} :> {-x, y}]


Just negates the x coordinate of all the values on the line, thus reflecting the spiral in the y-axis. However it is a bit hacky.

You can with a little maths just find the end points of your spiral such that you can use the default counterclockwise behaviour, draw the spiral backwards as it were:

m = 5;
n = 3;

{tmin, tmax} = \[Pi]/2 + {(-2 \[Pi] Mod[m, n])/n, 2 \[Pi] Floor[m/n]};

Graphics[{
Circle[],
Table[
With[{pos = {Cos[\[Pi]/2 - ( 2 \[Pi] i)/n], Sin[\[Pi]/2 - ( 2 \[Pi] i)/n]}}, {
Line[{0.9 pos, pos}],
Text[ToString@i, 0.8 pos]
}], {i, 0, n - 1}],
First@PolarPlot[1.1 + 0.2 (1 - (t - tmin)/(tmax - tmin)), {t, tmin, tmax},
PlotStyle -> Red] /. Line -> Arrow
}
}
]


I've rewritten your code such that it will work for all m and n:

m = 22;
n = 7;


Using @Quantum_Oli's nice generalization in an alternative way:

ppF = With[{tmin = π/2 - 2 π Mod[##]/#2,
tmax = π/2 + 2 π Floor[Divide@##],
epilog = Table[With[{pos = {Cos[π/2 - 2 π i/#2], Sin[π/2 - 2 π i/#2]}},
{Line[{0.9 pos, pos}], Text[ToString@i, 0.8 pos]}], {i, 0, #2 - 1}],
h = Graphics[{Thick, Line[{{0, -1}, {0, 1}}]}]},
PolarPlot[{1, 1.1 + 0.2 (1 - (t - tmin)/(tmax - tmin))}, {t, tmin, tmax},
Axes -> False, Epilog -> epilog,
PlotStyle -> {Black, ({Arrowheads[{{.01, 1, h}, {-0.05, 0}}], Red, Arrow@@#} &)}]] &;

ppF[16, 5]


An alternative way to change the direction:

reflectF = MapAt[GeometricTransformation[#, ReflectionTransform[{-1, 0}]] &, #, {1}] &;

reflectF[ppF[14, 6]]


Just a different visualization.

    clock[n_, t_, tmax_] := Module[{c},
c = {Circle[{0, 0}, 1],
Red,
Arrow[{{0, 0},
0.7 {Sin[Mod[t, n] 2 Pi/n], Cos[2 Pi  Mod[t, n]/n]}}], {Red,
ChartElementData[
"BezelSector"][{{Pi/2 - 2 Pi t/n, Pi/2}, {1,
1 + 0.1 Floor[Quotient[t, n]]}}, 0]},
Black,
Table[{Text[ n j/(2 Pi), 0.8 {Sin[j], Cos[j]}],
Line[{0.9 {Sin[j], Cos[j]}, {Sin[j], Cos[j]}}]}, {j,
0, (n - 1) 2 Pi/n, 2 Pi/n}], Orange,
Circle[{0, 0}, 1 + 0.1 #] & /@
Range[Floor[Quotient[tmax, n] - 1]]};
Column[{Graphics[c, ImageSize -> 200],
Row[Style[#, Bold, Blue, 16, FontFamily -> "Kartika"] & /@ {t,
" = "  ,
Sequence @@ ({#1, "\[Times]", n, "+", #2} & @@
QuotientRemainder[t, n]), " \[Congruent] ", Mod[t, n],
" mod ", n}]
}, Alignment -> Center, Frame -> All]
]


Visualizing (exporting the following as gif):

tab = Table[
Row[{clock[3, t, 35], clock[5, t, 35], clock[7, t, 35]}], {t, 0,
35, 1}];
`

Note clock 1 and 2 are in phase twice after start (15,30) and clock 2 and 3 only once at 35 ticks.