# Drawing picture from math's test

In Finnish matriculation examination there were the following problem. How can one draw those pictures using LaTeX?

1. A square ABCD is in coordinate system such that AB is on the x-axis and A=(0,0), B=(1,0). We rotate the square around B such that BC is on the x-axis, next around C, D such that A touches again the x-axis. Draw the picture of position of A with respect to the time.

2. A regular hexagon ABCDEF is in coordinate system such that AB is on the x-axis and A=(0,0), B=(1,0). We rotate the hexagon around B such that BC is on the x-axis, next around C, D and so on until A touches again the x-axis. Draw the picture of position of A with respect to the time.

Hand drawn diagrams are on http://www.mafyvalmennus.fi/images/uploads/pmyo14.pdf pages 32 and 33 (or 34 and 35 depending how to count those pages).

-
Interesting problems. Still, it would be fine if you provide your own attempts with whatever drawing tool you are used to, or at least a sketch… –  fpast Apr 7 at 19:13
I haven't used any drawing libraries. I have heard that for example tikz and asymptote can be used to draw such things. –  studying Apr 7 at 19:20
I added a link to hand-written pictures. –  studying Apr 7 at 19:37

Here's the first one:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\def\side{1cm}
\tikzset{
smalldot/.style={
circle,
fill,
inner sep=1.2pt
}
}

\begin{document}

\begin{tikzpicture}[
decoration={
markings,
mark=at position 0.5 with {\arrow{>}}
}
]
\draw
(0,0) -- ++(0,\side) --++(4*\side,0) -- ++(0,-\side);
\draw (-0.5\side,0) -- ++(5*\side,0);
\foreach \valor in {1,2,3}
\draw (\valor*\side,0) -- ++(0,\side);
\draw[postaction=decorate]
(0,0) arc [start angle=180,end angle=90,radius=\side];
\draw[postaction=decorate]
(3*\side,\side) arc [start angle=90,end angle=0,radius=\side];
\draw[postaction=decorate]
(\side,\side) arc [start angle=135,end angle=45,radius=1.4142*\side];
\foreach \xcoor/\ycoor in {0/0,\side/\side,{3*\side}/\side,{4*\side}/0}
\node[smalldot] at (\xcoor,\ycoor) {};
\draw[dashed]
(\side,\side) -- (2*\side,0) -- (3*\side,\side);
\foreach \coord in {1,2,3,4}
\node[circle,draw,font=\footnotesize,inner sep=1pt] at ({\side*(\coord-0.5)},-0.5) {\coord};
\begin{scope}[yshift=-3*\side]
\draw (-0.5\side,0) -- ++(5*\side,0);
\draw[postaction=decorate]
(0,0) arc [start angle=180,end angle=90,radius=\side];
\draw[postaction=decorate]
(3*\side,\side) arc [start angle=90,end angle=0,radius=\side];
\draw[postaction=decorate]
(\side,\side) arc [start angle=135,end angle=45,radius=1.4142*\side];
\end{scope}
\end{tikzpicture}

\end{document}


As you can see, using \draw and arc you can build your images.

The second one:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\def\side{1cm}% the length of the side of the polygons

\tikzset{
smalldot/.style={
circle,
fill,
inner sep=1.2pt
}
}

\begin{document}

\begin{tikzpicture}[
decoration={
markings,
mark=at position 0.5 with {\arrow{>}}
}
]
% the hexagons
\foreach \inicio in {0,...,5}
{
\draw
(\inicio*\side,0) -- ++(0:\side) -- ++(60:\side) -- ++(120:\side) --
++(180:\side) -- ++(240:\side) -- ++(300:\side);
}

% the horizontal axis
\draw (-0.5\side,0) -- ++(7*\side,0);

% the arcs and small filled dots
\draw[postaction=decorate]
node[smalldot] {} (0,0) arc [start angle=180,end angle=120,radius=\side] node[smalldot] {};
\draw[postaction=decorate]
(60:\side) arc [start angle=150,end angle=90,radius=1.717*\side] node[smalldot] {};
\draw[postaction=decorate]
(2*\side,1.717*\side) arc [start angle=120,end angle=60,radius=2*\side] node[smalldot] {};
\draw[postaction=decorate]
(4*\side,1.717*\side) arc [start angle=90,end angle=30,radius=1.717*\side] node[smalldot] {};
\begin{scope}[xshift=5*\side]
\draw[postaction=decorate]
(60:\side) arc [start angle=60,end angle=0,radius=\side] node[smalldot] {};
\end{scope}

% the dashed lines
\draw[dashed]
(60:\side) -- (2*\side,0) -- ++(0,1.717*\side);
\draw[dashed]
(4*\side,1.717*\side) -- ++(0,-1.717*\side) -- +(30:1.717*\side);

% the circled labels
\foreach \coord in {1,...,6}
\node[circle,draw,font=\footnotesize,inner sep=1pt] at ({\side*(\coord-0.5)},-0.5) {\coord};

% the bottom figure showing only the path
\begin{scope}[yshift=-3*\side]
\draw (-0.5\side,0) -- ++(7*\side,0);
\draw[postaction=decorate]
(0,0) arc [start angle=180,end angle=120,radius=\side];
\draw[postaction=decorate]
(60:\side) arc [start angle=150,end angle=90,radius=1.717*\side];
\draw[postaction=decorate]
(2*\side,1.717*\side) arc [start angle=120,end angle=60,radius=2*\side];
\draw[postaction=decorate]
(4*\side,1.717*\side) arc [start angle=90,end angle=30,radius=1.717*\side];
\begin{scope}[xshift=5*\side]
\draw[postaction=decorate]
(60:\side) arc [start angle=60,end angle=0,radius=\side];
\end{scope}
\end{scope}

\end{tikzpicture}

\end{document}


-
Bravo... bravo! –  Steven B. Segletes Apr 7 at 22:47
Another thing you could do is start the dashed lines from the other side, so they end in the bullets. I think the result would be a bit better (a little bit :P). –  Manuel Apr 8 at 6:48

This answer generalizes the number of vertexes of the regular polygon and defines macro \RotateRegularPolygon with the number of vertexes as argument. If the optional argument is false, then only the arcs for point A are drawn.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}

\makeatletter
\newif\ifDrawWithPolygon
\newcommand*{\RotateRegularPolygon}[2][true]{%
\begingroup
\def\VarN{#2}%
\edef\VarM{\the\numexpr\VarN-1\relax}%
\def\DimR{15mm}%
\csname DrawWithPolygon#1\endcsname
%
\pgfmathsetmacro\AngleN{360/\VarN}%
\pgfmathsetmacro\CurrentAngle{270+180/\VarN}%
\pgfmathsetmacro\XM{-cos(\CurrentAngle)}%
\pgfmathsetmacro\YM{-sin(\CurrentAngle)}%
\pgfmathsetmacro\Side{-2*\XM}%
\expandafter\pgfmathsetmacro\csname X0\endcsname{-\XM}%
\expandafter\pgfmathsetmacro\csname Y0\endcsname{-\YM}%
\expandafter
\let\csname X\VarN\expandafter\endcsname\csname X0\endcsname
\expandafter
\let\csname X\VarN\expandafter\endcsname\csname Y0\endcsname
\count@=1\relax
\@whilenum\count@<\VarN\do{%
\pgfmathsetmacro\CurrentAngle{\CurrentAngle-\AngleN}%
\expandafter
\pgfmathsetmacro\csname X\the\count@\endcsname{cos(\CurrentAngle)}%
\expandafter
\pgfmathsetmacro\csname Y\the\count@\endcsname{sin(\CurrentAngle)}%
}%
\begin{tikzpicture}[
x=\DimR,
y=\DimR,
]
\draw[]
let
\n1 = {\Side*\VarM*\DimR + \DimR}
in
(-\DimR, -\YM) -- (\n1, -\YM)
;
\ifDrawWithPolygon
\foreach \i in {0, ..., \VarM} {
\draw[xshift=\i*\Side*\DimR]
(\csname X0\endcsname, \csname Y0\endcsname)
\foreach \j in {1, ..., \VarM} {
-- (\csname X\j\endcsname, \csname Y\j\endcsname)
}
-- cycle;
;
%          \edef\DimSide{\the\dimexpr\Side\dimexpr\DimR\relax\relax}%
\ifnum \i<\numexpr\VarM-1\relax
\ifnum \i>0 %
\draw[
dashed,
xshift=\i*\Side*\DimR,
blue
]
let
\p1 = (\csname X\the\numexpr\i+2\endcsname + \Side,
\csname Y\the\numexpr\i+2\endcsname)
in
(\p1) --
(\csname X0\endcsname, \csname Y0\endcsname) --
(\csname X\the\numexpr\i+1\endcsname,
\csname Y\the\numexpr\i+1\endcsname)
;
\fi
\fi
}%
\foreach \i in {0, ..., \VarM} {
\draw[
xshift=\i*\Side*\DimR,
yshift=-\YM*\DimR,
]
(0,-8pt)
node[
\ifnum\i<9 circle\else ellipse\fi,
draw,
font=\footnotesize,
inner sep=1pt,
] {\the\numexpr\i+1\relax}
;
}%
\fi
\edef\ArrowPosition{\ifDrawWithPolygon 0.5\else 0.999\fi}%
\tikzset{
decoration={
markings,
mark=at position \ArrowPosition with {\arrow{>}},
},
}%
\foreach \i in {0, ..., \numexpr\VarM-1\relax} {
\draw[
postaction=decorate,
xshift=\i*\Side*\DimR,
red,
]
let
\n{x} = {\csname X\the\numexpr\i+1\endcsname-\csname X0\endcsname},
\n{y} = {\csname Y\the\numexpr\i+1\endcsname-\csname Y0\endcsname},
\n{start} = {atan2(\n{y},\n{x})},
\n{radius} = {sqrt(\n{x}*\n{x} + \n{y}*\n{y})}
in
(\csname X\the\numexpr\i+1\endcsname,
\csname Y\the\numexpr\i+1\endcsname)
;
}%
\end{tikzpicture}%
\endgroup
}

\begin{document}
\centering
\setlength{\parskip}{1ex}
\newcommand*{\test}[1]{%
\par
\vspace{4\parskip}%
\RotateRegularPolygon{#1}\par
\nopagebreak
\RotateRegularPolygon[false]{#1}\par
}
\test{4}
\test{5}
\test{6}
\test{9}
\test{12}
\end{document}


-

Here's a miniature generalized function in Metapost to draw these paths. Decorate as required.

prologues:=3;outputtemplate:="%j%c.eps";
% Corner of Rotated Polygon
vardef corp(expr n,size) =
save p; pair p[]; p[0]=(0,0);
p[0] for i=1 upto n-1:
hide(p[i] = p[i-1] rotatedabout((size*i,0),-360/n))
{((size*i,0)-p[i-1]) rotated 90} ..
{((size*i,0)-p[i]) rotated 90} p[i]
endfor
enddef;
beginfig(1);
drawarrow corp(4,3cm);
drawarrow corp(6,2cm) shifted 144up;
endfig;
end


-

A late answer, different in spirit from the previous ones: to be more illustrative, the successive positions of the square do not touch each other and the square has thick sides. This forces to cheat a little with the parameters of the trajectory of point A, such as elliptic arcs instead of (but very close to) the real arcs. I used pstricks.

 \documentclass[a4paper,10pt]{article}

\usepackage[svgnames,x11names, pdf]{pstricks}%
\usepackage{multido}

\pagestyle{empty}

\begin{document}

\def\mysquare{{\psset{linewidth = 2pt, dotsize =2pt, showpoints, labelsep = 1cm}%
\psline[linecolor=PaleVioletRed1](0.80,0)(0.80,0.80)\psline[linecolor=PaleVioletRed2](0.80,0.80)(0,0.80)%
\psline[linecolor=PaleVioletRed3](0,0.80)(0,0)\psline[linecolor=PaleVioletRed4](0,0)(0.80,0)}}%
\begin{pspicture*}(-1.25,-1)(5.95,4)
\scriptsize\sffamily
\pnodes{P}(0,0)(1,0)(2,0)(3,0)
\pnodes{Q}(1,1)(2,1)(3,1)(4,1)
%%%%%%%% Successive positions of square
\psset{labelsep = 1.16\pslinewidth}
\uput[u](0.1,0){\mysquare}%
\uput[u]{270}(1.1,0.8){\mysquare}%
\uput[u]{180}(2.9,0.8){\mysquare}%
\uput[u]{90}(3.9,0){\mysquare}%
%%%%%%%%% Labels
\uput{2pt}[d](0.1,0){\rnode{A}{A}}\uput{2pt}[d](0.90,0){B}\uput[u](0.90,0.90){C}\uput[u](0.1,0.90){D}
%%%%%%%%% Successive positions of point A
\psset{linewidth =1pt,  linecolor = Thistle3, dotsize = 2pt}
\psellipticarcn{*->}(1.1,1pt)(1.0175, 0.815 ){180}{90}
\psarcn{*->}(2,1pt){1.204}{138}{42}
\psellipticarcn{*->}(2.9,1pt)(1.035, 0.815 ){90}{0}
\psdot(3.9175,1pt)
%%%%%%%%%%%%
\psaxes[linecolor = LightSteelBlue3!90!blue, ticksize = -2pt, tickcolor= LightSteelBlue3,labels = none](0,-0.4pt)(-0.95,-0.4pt)(5.95,-0.4pt)
\end{pspicture*}

\end{document}


-