1

I am trying the create analog clock dial with roman or standard numbers on display and at the same time create another one but the mirror image of it. I managed to do that but for some reason a third one appears. Below is my attempt code.

\documentclass[tikz, margin=2mm]{standalone}
\usetikzlibrary{spy,decorations.fractals}
\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\tikzset{
hour pointer/.style={line cap=round, thick},
minute pointer/.style={thin, line cap=round},
ticks sep/.style={outer sep=-#1}, ticks sep={0pt},
ticks size/.store in=\clocktickssize,
ticks size=.25cm,
ticks/.style={thin},
main ticks/.style={very thick},
clock/.style={draw, minimum size=4cm, circle},
clock text/.code={\let\clocktext\textrm},
hour pointer size/.store in=\hourpointersize,
hour pointer size=0.5cm,
minute pointer size/.store in=\minutepointersize,
minute pointer size=0.75cm,
clock text sep/.store in=\clocktextsep,
clock text sep=1em,
pics/clock/.style args={#1:#2}{
    code={%
    \pgfmathsetmacro{\hourangle}{90-#1*30-#2*0.5}    \pgfmathsetmacro{\minuteangle}{90-#2*6}
    \node[clock] (-clock) {};
    \foreach \angle [count=\xi] in {60,30,...,-270}
    {
        \draw[clock text, ticks] (-clock.\angle) -- ++(\angle:- \clocktickssize) node[anchor=center, shift={(\angle:-\clocktextsep)}] {\clocktext{\xi}};
    };
    \foreach \angle in {0,90,180,270} \draw[ticks, main ticks] (-clock.\angle) -- ++(\angle:-\clocktickssize);
    \draw[minute pointer] (-clock.center) -- ++(\minuteangle:\minutepointersize);
    \draw[hour pointer] (-clock.center) -- ++(\hourangle:\hourpointersize);}}}
  \tikzset{
  mirror scope/.is family,
  mirror scope/angle/.store in=\mirrorangle,
  mirror scope/center/.store in=\mirrorcenter,
  mirror setup/.code={\tikzset{mirror scope/.cd,#1}},
 mirror scope/.style={mirror setup={#1},spy scope={
        rectangle,lens={rotate=\mirrorangle,yscale=-1,rotate=-1*\mirrorangle},size=80cm}},}
 \usetikzlibrary{arrows.meta}
 \newcommand\mirror[1][]{\spy[overlay,#1] on (\mirrorcenter) in node at (\mirrorcenter)}
 \begin{document}
 \begin{tikzpicture}
 \pic[left=6cm,
 clock text/.code={\let\clocktext\rom},
 clock/.style={minimum size=5cm, draw}] (Original) at (0,0)   {clock=15:00};

\begin{scope}[mirror scope={center={5,0},angle=90}]
\pic[right=3cm,
 clock text/.code={\let\clocktext\rom},
 clock/.style={minimum size=5cm, draw}] (Reversed) at (4,0) {clock=15:00};
\mirror;  
%\foreach \clock in { Reversed, Original} \node[above=.25cm] %at (\clock -clock.north) {\clock\ Clock};
\end{scope}
\end{tikzpicture}
\end{document}

And the output is enter image description here The first two on the left are okay. But the third one should not be there. Obviously my coding is not right or not efficient. Any suggestion to mirror the image alternatively or how to adjust the original code to get only first two images. Thanks.

1
  • Via \pic, you draw two clocks (Original and Reversed) then you call \mirror to mirror the Reversed one... So you get three clocks ! May 20, 2021 at 4:59

2 Answers 2

2

(Note: the analog clock code comes from https://tex.stackexchange.com/a/343524/14500 and the mirror code comes from How to mirror and position the analog clock dials)

In your example, you draw two clocks (Original and Reversed) then you call \mirror to mirror the Reversed one... So you get three clocks !

Here is a commented solution:

\documentclass[tikz,margin=2mm]{standalone}

% code from <https://tex.stackexchange.com/a/343524/14500>
\makeatletter
\newcommand*{\rom}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\tikzset{
  hour pointer/.style={line cap=round, thick},
  minute pointer/.style={thin, line cap=round},
  ticks sep/.style={outer sep=-#1}, ticks sep={0pt},
  ticks size/.store in=\clocktickssize,
  ticks size=.25cm,
  ticks/.style={thin},
  main ticks/.style={very thick},
  clock/.style={minimum size=4cm,draw,circle},
  clock text/.code={\let\clocktext\textrm},
  hour pointer size/.store in=\hourpointersize,
  hour pointer size=0.5cm,
  minute pointer size/.store in=\minutepointersize,
  minute pointer size=0.75cm,
  clock text sep/.store in=\clocktextsep,
  clock text sep=1em,
  pics/clock/.style args={#1:#2}{
    code={%
      \pgfmathsetmacro{\hourangle}{90-#1*30-#2*0.5}
      \pgfmathsetmacro{\minuteangle}{90-#2*6}
      \node[clock] (-clock) {};
      \foreach \angle [count=\xi] in {60,30,...,-270}
      {
        \draw[clock text, ticks] (-clock.\angle) -- ++(\angle:- \clocktickssize) node[anchor=center, shift={(\angle:-\clocktextsep)}] {\clocktext{\xi}};
      };
      \foreach \angle in {0,90,180,270} \draw[ticks, main ticks] (-clock.\angle) -- ++(\angle:-\clocktickssize);
      \draw[minute pointer] (-clock.center) -- ++(\minuteangle:\minutepointersize);
      \draw[hour pointer] (-clock.center) -- ++(\hourangle:\hourpointersize);}
  },
}

% code from <https://tex.stackexchange.com/q/568227/14500>
\usetikzlibrary{spy}
\tikzset{
  mirror scope/.is family,
  mirror scope/angle/.store in=\mirrorangle,
  mirror scope/center/.store in=\mirrorcenter,
  mirror setup/.code={\tikzset{mirror scope/.cd,#1}},
  mirror scope/.style={mirror setup={#1},spy scope={
      rectangle,lens={rotate=\mirrorangle,yscale=-1,rotate=-1*\mirrorangle},size=80cm}},}
\newcommand\mirror[1][]{\spy[overlay,#1] on (\mirrorcenter) in node at (\mirrorcenter)}

\begin{document}
\begin{tikzpicture}
  % to fix the bounding box
  \path (-2.5,-2.5) rectangle (8.5,2.5);
  \begin{scope}[mirror scope={center={3,0},angle=90}]
    % to draw the clock
    \pic[clock text/.code={\let\clocktext\rom},clock/.style={minimum size=5cm, draw}] at (0,0) {clock=15:00};
    % to mirror it
    \mirror;  
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

2

Another option, using a \foreach (for each clock) and inside it a \scope that changes the xscale. I also added a customizable time setting and minor cosmetic changes (the hands).

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\newcounter{hours}

% the time
\def\hour{2}
\def\minute{25}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
  \def\l {4}        % clock size
  \def\ml{0.35*\l}  % minute hand lenght
  \def\mw{0.005*\l} % minute hand width
  \def\hl{0.3*\l}   % hour hand lenght
  \def\hw{0.01*\l}  % hour hand width
  \foreach\i in {-1,1}
  {%
    \begin{scope}[shift={(0.55*\i*\l,0)},xscale=-\i,transform shape]
      \draw[clip] (-0.5*\l,-0.5*\l) rectangle (0.5*\l,0.5*\l);
      \foreach\j in {30,60,120,150}
      {%
        \draw (\j:\l) -- (180+\j:\l);
      }
      \draw[thick] ( 0:\l) -- (180:\l);
      \draw[thick] (90:\l) -- (270:\l);
      \fill[white] (-0.45*\l,-0.45*\l) rectangle (0.45*\l,0.45*\l);
      \foreach\j in {1,...,12}
      {%
        \pgfmathsetmacro\r{0.45*\l+(Mod(\j,3)==0?-0.075*\l:0}
        \ifnum\j = 4
          \node at (90-30*4:\r) {\small IIII};
        \else
          \setcounter{hours}{\j}
          \node at (90-30*\j:\r) {\small\Roman{hours}};
        \fi
      }
      \fill (0,0) circle (0.02*\l);
      \begin{scope}[rotate=90-30*(\hour+\minute/60)]
        \fill (-0.03*\l,-\hw) rectangle (\hl,\hw);
      \end{scope}
      \begin{scope}[rotate=90-6*\minute]
        \fill (-0.03*\l,-\mw) rectangle (\ml,\mw);
      \end{scope}
    \end{scope}
  }
\end{tikzpicture}
\end{document}

enter image description here enter image description here

2
  • Very very nice the drawing.
    – Sebastiano
    Jun 19, 2021 at 10:54
  • 1
    Thanks, @Sebastiano :-P Jun 19, 2021 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.