summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/rubik/examples.tex
blob: 9f5a1512175ca5d6da6a7fef8f032a9502c17f90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
%%
%% examples.tex
%% examples using the rubikrotation package v3.0
%% Requires  rubik packages (v3.0) and also the tikz package
%% Part of the Rubik bundle (www.ctan.org/pkg/rubik)
%% RWD Nickalls & A Syropoulos
%% September 25, 2015
%%--------NOTE-------------------------------------------
%% USAGE:   (pdf)latex  --shell-escape   example-rot1.tex
%% run three times to get all labels and fig nos correct
%%-------------------------------------------------------
\documentclass[a4paper]{article}
\usepackage{tikz}   %% load tikz BEFORE rubikcube
\usepackage{rubikcube,rubikrotation} 
\usepackage{url}
%-------------
\pagestyle{myheadings}
\markright{\textsc{rubikrotation} package v3.0 (Sept 2015) \hspace{0.5cm}\texttt{www.ctan.org/pkg/rubik} \hspace{0.5cm}examples.tex}
%-----------
%% some well known sequences (see the web page of Reid)
\newcommand{\sixTs}{*sixTs,F2,R2,U2,Fp,B,D2,L2,F,B}
\newcommand{\CubeInCube}{*CubeInCube,F,L,F,Up,R,U,F2,L2,Up,Lp,B,Dp,Bp,L2,U}
\newcommand{\sixspot}{[sixspot],U,Dp,R,Lp,F,Bp,U,Dp}
\newcommand{\superflip}{U,R2,Fp,R,Dp,L,Bp,R,Up,R,Up,D,%
Fp,U,Fp,Up,Dp,B,Lp,Fp,Bp,Dp,Lp}
%--------------------
%% brace and bracket 
\newcommand{\Rubikbracket}[1]{$\left(\mbox{#1}\right)$}
\newcommand{\Rubikbrace}[1]{$\left\{\mbox{#1}\right\}$}
%---------------
%% increase text space to make room 
\addtolength{\oddsidemargin}{-1.5cm}
\addtolength{\textwidth}{3cm}
\addtolength{\textheight}{1cm}
%%==================

\begin{document}

\begin{center}
\Huge{Rubikrotation  examples}\,\footnote{These examples  are part of the 
\textsc{rubikrotation} package, and assume some  familiarity with the Rubik bundle 
documentation \texttt{rubikcube.pdf} and \texttt{rubikrotation.pdf}.}
\end{center}

\bigskip

\textsc{note}: Since the   \verb!\RubikRotation! command   calls the perl script 
\texttt{rubikrotation.pl} this \texttt{.tex}~file needs to be run using 
the \verb!--shell-escape! command-line switch, as follows:
\begin{quote}
\begin{verbatim}
latex   --shell-escape  example-tex
\end{verbatim}
\end{quote}
If you forget to use the command-line switch, the file will run OK, but the cubes 
will remain in the initial `solved' configuration. The \texttt{tikz} package must be 
loaded before the two \texttt{rubik..} packages.

%%------------------
\section*{Example~1}

In Figure~\ref{fig:cubeincube} we show  the so-called ``sixspot'' configuration,
 generated from a solved cube using the rotation sequence 
\rr{U}, \rr{Dp}, \rr{R}, \rr{Lp}, \rr{F}, \rr{Bp}, \rr{U}, \rr{Dp}\
(see the website of Reid at \url{www.cflmath.edu/~reid/Rubik/patterns.html}).
%%--------FIGURE 1 -----------
\begin{figure}[hbt]
\centering
\RubikCubeSolved
\RubikRotation{\sixspot}
\ShowCube{7cm}{0.7}{\DrawRubikCubeFlat}
\caption{\label{fig:cubeincube}The  so-called `sixspot' configuration (Reid).}
\end{figure}
%----------------

{\noindent}Creating a macro to hold  a rotation sequence greatly facilitates their 
use, as follows:
\begin{quote}
\begin{verbatim}
\newcommand{\sixspot}{[sixspot],U,Dp,R,Lp,F,Bp,U,Dp}
\end{verbatim}
\end{quote}
We can now process this sequence  using its macro name as an argument for the 
\verb!\RubikRotation! command. The code used for the above Figure  uses the 
\verb!\ShowCube{}{}{}! command for which \verb!#1! is the minipage width, \verb!#2! 
is the tikzpicture scale factor (0--1), and \verb!#3! is  a  Rubik  \verb!\Draw..! command
(see \textsc{rubikrotation} documentation for details).
\begin{quote}
\begin{verbatim}
\usepackage{tikz,rubikcube,rubikrotation}
\thispagestyle{empty} %% disables pagenumbers
...
\begin{figure}[hbt]
  \centering
  \RubikCubeSolved
  \RubikRotation{\sixspot}
  \ShowCube{7cm}{0.7}{\DrawRubikCubeFlat}
  \caption{...}
\end{figure}
\end{verbatim}
\end{quote}
Note that running the `sixspot' sequence 3 times returns the cube to its original `solved' 
state (it is a so-called `order~3' sequence). The~command for processing it three times 
is    \verb!\RubikRotation[3]{\sixspot}!.


\pagebreak
%%-------------------------
\section*{Example~2}

 In this example we demonstrate  the use of the  \verb!\ShowRubikErrors! command, which
 places a copy of   the Perl output file \verb!rubikstateERRORS.dat! underneath the graphic 
 so you can see a list of all the  errors, if any (in this example we have introduced a few  
 errors---wrong minipage width, typos and some animals---into the rotation sequence). 
 It is important to note that  the  \verb!\ShowRubikErrors! command must be 
 placed \textit{after}  the TikZ picture environment (i.e.,~in this case after 
the \verb!\ShowCube! command). Note   that full details of all 
 errors are also included in the .log file. 

%%--------FIGURE 2 -----------

\RubikCubeSolved
\RubikRotation{[sixspot],U,Dp,R,Lp,F,Bp,U,Dpppp,cat,dog}

\begin{figure}[hbt]
  \centering
  \ShowCubeF{4.5cm}{0.7}{\DrawRubikCubeFlat}
  \ShowRubikErrors
\parbox{0.7\textwidth}{%
\caption{\label{fig:cubeincubeE}The same `sixspot' sequence of rotations as shown in 
Example~1,  but now with some   errors (wrong minipage-width, typos \& animals\,!) in the 
rotation sequence (it should be just \texttt{U,Dp,R,Lp,F,Bp,U,Dp}).}
}
\end{figure}
{\noindent}In this example we have used the F version of the \verb!\ShowCube! 
command (\verb!\ShowCubeF!)  which places an fbox around the image so you can see the 
extent of any white space etc. This reveals that the set minipage-width (4.5cm) in the 
\verb!\ShowCubeF! command---see code below---is too narrow: it should be 7cm ($10 \times 0.7$) 
to just include the whole image. Once fixed, we can remove the F from the \verb!\ShowCubeF! command.
Note also  that only `\verb!\Draw...!' commands really need to be inside the TikZ picture environment 
(i.e.,~inside the \verb!\ShowCube! command). The above figure was generated by the following code.
%-----------------
\begin{quote}
\begin{verbatim}
\RubikCubeSolved
\RubikRotation{[sixspot],U,Dp,R,Lp,F,Bp,U,Dpppp,cat,dog}
\begin{figure}[hbt]
  \centering
  \ShowCubeF{4.5cm}{0.7}{\DrawRubikCubeFlat}
  \ShowRubikErrors
\caption{....}
\end{figure}
\end{verbatim}
\end{quote}
Even if the \verb!\ShowRubikErrors! command is not used, it is always a good idea to check the 
file \verb!rubikstateERRORS.dat! after a \LaTeX\ run, since this file will reveal any  errors.



\pagebreak
%-------------------------------
\section*{Example~3}

In this example we use the \verb!\RubikRotation! command to scramble a `solved' Rubik 
cube via  a sequence of 120 random rotations, using the following  command (the details 
of the process can be seen in the \texttt{.log} file):
\begin{quote}
\begin{verbatim}
\RubikRotation{random,120}
\end{verbatim}
\end{quote}
In this example, we also save the final  configuration (state) to a file 
(\texttt{exampfig4.tex}) using the command
\verb!\SaveRubikState{exampfig4.tex}!
so we can  display the cube in the same state later (see Example~4) but 
in  a different format.
Note that since we are using a random sequence, it follows that each 
time this file is run not only will a visually different  cube  be generated,  
but the same state  will be shown in both Figures~\ref{fig:randomone} and \ref{fig:randomtwo}.
%%--------FIGURE 3 -----------
\begin{figure}[hbt]
  \centering
  \RubikCubeSolved
  \RubikRotation{random,120}
  \SaveRubikState{exampfig4.tex}  
  \ShowCube{8.4cm}{0.7}{\DrawRubikFlat}
\parbox{0.7\textwidth}{%
\caption{\label{fig:randomone}This shows a cube  generated by 120 random rotations}}
\end{figure}
%----------------
\begin{quote}
\begin{verbatim}
\usepackage{tikz,rubikcube,rubikrotation}
...
\begin{figure}[hbt]
  \centering
  \RubikCubeSolved
  \RubikRotation{random,120}
  \SaveRubikState{exampfig4.tex}  
  \ShowCube{8.4cm}{0.7}{\DrawRubikFlat}
\caption{....}
\end{figure}
\end{verbatim}
\end{quote}

Q: How do we determine the minipage-width (8.4cm) in the \verb!\ShowCube! command?

A: The object is 12 cubie squares  wide (1\,cm each). Since the specified TikZ scale factor is~$0.7$ 
here, then the true width of the image is $12 \times 0.7 = 8.4$\,cm. If you change the scale then 
the size of the  image will change, and a new width will be required to just fit the image. 

Note that in this particular case (only a single image in the `figure' environment), since 
the \verb!\ShowCube! command places the image centrally inside the minipage, the image will 
in fact be centrally placed in  the \verb!\textwidth! provided the image is \textit{smaller} 
than the fbox---i.e.,~if we used instead a minipage-width of, say, 12\,cm  the image would still
 appear centered in the \verb!\textwidth! in this case.
However, when there are several images in the `figure', then the spacing may appear strange 
unless each image closely fits its own minipage-width etc.
It is often useful, therefore, to check the size of the fbox (using the \verb!\ShowCubeF! command).
  


\pagebreak

%----------------------
\section*{Example~4}

In this example we display a cube having the same state as that shown in 
Figure~\ref{fig:randomone}. The configuration state was saved from 
Figure~\ref{fig:randomone} using the  command 
\verb!\SaveRubikState{exampfig4.tex}!, and then input here  
using \verb!\input{exampfig4.tex}!. These commands therefore allow  the 
state of a previous cube to be saved to a file, and then  displayed again 
later in  a different format.
%%-----------FIGURE 4 -----------
\begin{figure}[hbt]
  \centering
  \input{exampfig4.tex}
  \ShowCube{4cm}{0.8}{\DrawRubikCubeLD}
\parbox{0.7\textwidth}{%
\caption{\label{fig:randomtwo}This shows a Rubik cube in exactly the  same 
state as  the one shown in Figure~\ref{fig:randomone}} }
\end{figure}
%%---------------------------------
\begin{quote}
\begin{verbatim}
\usepackage{tikz,rubikcube,rubikrotation}
...
\begin{figure}[hbt]
  \centering
  \input{exampfig4.tex}
  \Showcube{4cm}{0.8}{\DrawRubikCubeLD}
\caption{....} 
\end{figure}
\end{verbatim}
\end{quote}


\pagebreak
%----------------------
\section*{Example~5}

Here we show a convenient way of displaying a series of small cubes showing 
a sequence of rotations (\rr{U}, \rr{R}, \rr{F}). 

\begin{figure}[hbt]
\centering
\RubikCubeSolved 
\ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
\Rubik{U}
\RubikRotation{U}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} 
\Rubik{R}
\RubikRotation{R}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} 
\Rubik{F}
\RubikRotation{F}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} 
\caption{The rotations \rr{U}, \rr{R}, \rr{F}\ on a solved cube.} 
\end{figure}
The code for the above sequence is as follows:
\begin{quote}
\begin{verbatim}
\usepackage{tikz,rubikcube,rubikrotation}
...
\begin{figure}[hbt]
  \centering
  \RubikCubeSolved 
  \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
  \Rubik{U}
  \RubikRotation{U}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} 
  \Rubik{R}
  \RubikRotation{R}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} 
  \Rubik{F} 
  \RubikRotation{F}\ShowCube{2cm}{0.5}{\DrawRubikCubeRU} 
\caption{The rotations \rr{U}, \rr{R}, \rr{F}\ on a solved cube.} 
\end{figure}
\end{verbatim}
\end{quote}


\pagebreak
%----------------------
\section*{Example~6}

In this example we highlight the fact that commands used inside a TikZ picture 
environment remain local to that environment. Note that this applies with other 
environments too;  for example, with both the \verb!\minipage! the \verb!\figure! environments.
Consequently, it is generally best when drawing a sequence of cubes  to reserve the TikZ 
picture environment (i.e.,~the \verb!\ShowCube! command)  only  for Rubik \verb!\Draw..! 
commands and TikZ commands.

In this example the first cube uses the \verb!\RubikCubeSolved! \textit{inside} the TikZ environment.
However, if we then perform the rotation  \textRubik{R}\  the command \verb!RubikRotation{R}! 
results in  something quite unexpected (and obviously not correct). This is because 
 the effect of the \verb!\RubikCubeSolved! command is not visible outside its TikZ environment, 
and hence the \verb!RubikRotation{R}! command has to  operate on the current globally available 
colour state information; i.e.,~that following the action of the 
\textbackslash\texttt{RubikRotation\{[sixspot],....\}} command in the earlier  Example~2
(shown in Figure~2) which was executed \textit{before, and outside} the \texttt{figure} environment 
 in that example, and hence the strange form of the second cube below.


\medskip

\begin{minipage}{0.4\textwidth}
\ShowCube{2cm}{0.5}{%
      \RubikCubeSolved
      \DrawRubikCubeRU
     }
   \hspace{4mm}\Rubik{R}\hspace{5mm}%
   \RubikRotation{R}%
   \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
\end{minipage}
%---------------
\hspace{1cm}
\begin{minipage}{0.5\textwidth}
\begin{verbatim}
\usepackage{tikz,rubikcube,rubikrotation}
...
\begin{minipage}{0.4\textwidth}
   \ShowCube{2cm}{0.5}{%
       \RubikCubeSolved
       \DrawRubikCubeRU
     }
   \hspace{4mm}\Rubik{R}\hspace{5mm}%
   \RubikRotation{R}%
   \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
\end{minipage}
\end{verbatim}
\end{minipage}

\bigskip

If we now bring the \verb!\RubikCubeSolved! command out and place it before 
the \verb!\ShowCube! command then its  `state' information  becomes globally 
accessable, and  can therefore be  acted upon (\&~updated) by the  \verb!\RubikRotation{R}! 
command, and  hence is rendered (correctly for us) by the next  \verb!\DrawRubikCubeRU! command. 

\bigskip


\begin{minipage}{0.4\textwidth}
   \RubikCubeSolved
   \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
   \hspace{4mm}\Rubik{R}\hspace{5mm}%
   \RubikRotation{R}%
   \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
\end{minipage}
%---------------
\hspace{1cm}
\begin{minipage}{0.5\textwidth}
\begin{verbatim}
\begin{minipage}{0.4\textwidth}
   \RubikCubeSolved
   \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
   \hspace{4mm}\Rubik{R}\hspace{5mm}%
   \RubikRotation{R}%
   \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
\end{minipage}
\end{verbatim}
\end{minipage}




\pagebreak
%----------------------
\section*{Example~7}

\subsection*{The `superflip' configuration}

Once you have mastered Rubik's cube, then an interesting exercise is to generate 
the so-called `superflip' configuration, in which all the corners are correctly 
solved, while all the edges are flipped.

For the impatient,  the  superflip sequence of 24  quarter-turn rotations (listed on 
Randelshofer's website (\url{www.randelshofer.ch/rubik/patterns/U080.01.html}) is as follows. 
This  converts the solved cube on the left into the configuration shown on the right.

\bigskip

\begin{center}
\Rubik{U}\Rubik{R}\Rubik{R}\Rubik{Fp}\Rubik{R}\Rubik{Dp}\Rubik{L}\Rubik{Bp}\Rubik{R}%
\Rubik{Up}\Rubik{R}\Rubik{Up}\Rubik{D}\Rubik{Fp}\Rubik{U}\Rubik{Fp}\Rubik{Up}\Rubik{Dp}%
\Rubik{B}\Rubik{Lp}\Rubik{Fp}\Rubik{Bp}\Rubik{Dp}\Rubik{Lp}
\end{center}
  
\medskip

{\noindent}Surprisingly,  this sequence is actually equivalent to
\Rubikbrace{\Rubikbracket{\Rubik{M}\Rubik{Up}}4, \Rubik{yp}, \Rubik{x}}3

%--------draw the images-------------
\begin{figure}[hbt]
  \centering
  \RubikCubeSolved%
  \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
  \hspace{5mm}$\Longrightarrow$\hspace{5mm}%
  \RubikRotation{\superflip}%
  \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
  \hspace{1cm}%
  \ShowCube{5cm}{0.5}{\DrawRubikCubeFlat}
\caption{Two representations of the superflip configuration.}
\end{figure}
%----------------------

%\pagebreak

{\noindent}The full code for the figure above is as follows:
\begin{quote}
\begin{verbatim}
\usepackage{tikz,rubikcube,rubikrotation}
...
\begin{center}
\Rubik{U}\Rubik{R}\Rubik{R}\Rubik{Fp}\Rubik{R}\Rubik{Dp}\Rubik{L}\Rubik{Bp}%
\Rubik{R}\Rubik{Up}\Rubik{R}\Rubik{Up}\Rubik{D}\Rubik{Fp}\Rubik{U}\Rubik{Fp}%
\Rubik{Up}\Rubik{Dp}\Rubik{B}\Rubik{Lp}\Rubik{Fp}\Rubik{Bp}\Rubik{Dp}\Rubik{Lp}
\end{center}
  
\medskip

%% brace and bracket macros
\newcommand{\Rubikbracket}[1]{$\left(\mbox{#1}\right)$}
\newcommand{\Rubikbrace}[1]{$\left\{\mbox{#1}\right\}$}

{\noindent}Surprisingly,  this sequence is actually equivalent to
\Rubikbrace{\Rubikbracket{\Rubik{M}\Rubik{Up}}4, \Rubik{yp}, \Rubik{x}}3

\newcommand{\superflip}{U,R2,Fp,R,Dp,L,Bp,R,Up,R,Up,D,%
Fp,U,Fp,Up,Dp,B,Lp,Fp,Bp,Dp,Lp}

\begin{figure}[hbt]
  \centering
  \RubikCubeSolved%
  \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
  \hspace{5mm}$\Longrightarrow$\hspace{5mm}%
  \RubikRotation{\superflip}%
  \ShowCube{2cm}{0.5}{\DrawRubikCubeRU}
  \hspace{1cm}%
  \ShowCube{5cm}{0.5}{\DrawRubikCubeFlat}
\caption{...}
\end{figure}
\end{verbatim}
\end{quote}
\begin{center}
------ END ------
\end{center}

\end{document}