2

I want to convert this image into TikZ.

What I have

I already have the following code, but I don't know how to put the numbers at the vertices and how to put that red bar inbetween 2 and 3. Could someone please explain how to do this?

What I have

\documentclass{article}

\usepackage{xcolor}

\definecolor{navyblue}{rgb}{0.0, 0.0, 0.5}

\usepackage{
  pst-poly,
  pstricks-add
}
\usepackage[
%  locale = DE,
  round-mode = places,
  round-precision = 2
]{siunitx}

\ExplSyntaxOn
  \cs_new_eq:NN
    \calc
  \fp_eval:n
\ExplSyntaxOff

% calculations
\newcommand*\Angle{\calc{360/\sides}}
\newcommand*\sidelength{\calc{2*\radius*sin(pi/\sides)}}
\newcommand*\radiusI{\calc{\radius*cos(pi/\sides)}}
\newcommand*\areaI{\calc{pi*\radiusI^2}}%        not used
\newcommand*\areaC{\calc{pi*\radius^2}}%         not used
\newcommand*\areaRatio{\calc{cos(pi/\sides)^2}}% not used

\psset{dimen = middel}

\begin{document}

% constants
\newcommand*\sides{5}
\newcommand*\radius{3.5}

\begin{center}
\begin{pspicture}(-\radius,-\radius)(\radius,\radius)
  % centre
  \pnode(0,0){C}
  % regular polygon with dots at corners
  \rput(C){%
    \PstPolygon[
    PolyNbSides = \sides,
    unit = \radius,
    PolyRotation=18,
    linecolor = navyblue
    ]
  }
 {\psset{linecolor = gray}
  % circumscribed circle
  \pscircle(C){\radius}}

\end{pspicture}
\end{center}

\bigskip

\end{document}
3

A short code with pst-poly. I had to introduce a new ‘vertex’ counter, because the option PolyName=… allows to have numbered vertices, but their order is not the order required by the O.P.:

\documentclass[svgnames]{article}

\usepackage{pst-poly}
\usepackage{auto-pst-pdf}
\usepackage{etoolbox}
\colorlet{PolygonColor}{Thistle}
\colorlet{PolygonColor1}{red}
\colorlet{VertexColor}{NavyBlue}
\colorlet{LabelColor}{OrangeRed!80!}

\begin{document}

\psset{unit=3.5cm, dimen=middle, linejoin=1, dotsize=3.5pt, arrowinset=0.15, shortput=nab}
\begin{pspicture}(-1,-1)(1,1)
    % centre
    \pnode(0,0){C}
    % circumscribed circle
    \pscircle[linecolor =LightSlateGray!60](C){1}
    % regular polygon with dots at corners
    \psset{linecolor=PolygonColor}
    \newcounter{vertex}
    \setcounter{vertex}{4}
    \providecommand{\PstPolygonNode}{\rput * { * 0}(1.09;\INode){\addtocounter{vertex}{-1}\ifnumequal{\value{vertex}}{0}{\setcounter{vertex}{5}}{}\color{LabelColor}\thevertex}\psdots[linecolor =VertexColor](1;\INode)}
    \rput(0,0){\PstPentagon[PolyName=A, linecolor=white] }
    \psset{arrows=<-, arrowsize =2.5pt 2, nodesepA=1.7pt, nodesepB =1.75pt, linecolor=PolygonColor, linewidth=1.2pt}
    \ncline{A1}{A2}\ncline{A2}{A3}_{$\tau$}\ncline{A3}{A4}\ncline{A4}{A5}\ncline{A5}{A1}
    \ncline[offset=4pt, linecolor=PolygonColor1, arrows=<->]{A1}{A2}^{$ \sigma$}
\end{pspicture}

\end{document}

enter image description here

  • The picture simply is exactly what I'm looking for, thanks! Is there a way to manually edit the value of each vertex? And the color too, if that is possible. Thanks in advance – Heinz Doofenschmirtz Oct 31 '15 at 20:32
  • For colors, I gave them a generic name, and its value can be changed in the preamble, if I understand well what you'd like, see my updated code. For your other question, I don't see very well what you mean with ‘the value of each vertex’. Could you be more explicit? – Bernard Oct 31 '15 at 21:52
  • Sorry for the misunderstanding. By colors I meant the colors of the dots at the vertices. By 'value of each vertex' I mean the numbers at each vertex. I want to change the numbers at each vertex manually and also change the colors of the numbers at each vertex. – Heinz Doofenschmirtz Oct 31 '15 at 22:30
  • I've added the possibility of colouring individually the elements of the figure in the preamble. For the numbering question it's more delicate, as the placement has to be automatic. I introduced the vertex auxiliary counter that contains the values to be displayed, which are not the default ones. So you would have to change the rules for the computations of this counter. Note the ‘natural’ counter INode starts at the rightmost vertex, and steps counterclockwise. – Bernard Oct 31 '15 at 23:56
4

Here's a TikZ solution. It uses a foreach loop to draw the edges. The values for the loop ({2,1,a5,B,$\alpha$}) are used as labels, starting at the top and then clockwise. Furthermore count=\c tracks the current corner, and coordinates are created in each one (called c1, c2 and so on) so that you can access them easily afterwards. The markings decoration is used to place the arrow tips along the polygon, as there are five, each side represents 20% (or 0.2) of the whole path. Due to rounding inaccuracies, the placement of the arrows might be bad (for instance if the radius \r equals 1), to circumvent this one could place the tips more on the edges (easy) or change to another arrow placing facility (slightly less easy).

Code

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{decorations.markings}

\begin{document}

\begin{tikzpicture}
    \pgfmathsetmacro{\r}{3}
    \draw circle (\r);
    \draw[decoration={markings, mark=between positions 0.2 and 1 step 0.1999 with \arrow{latex}}, postaction=decorate] (162:\r)
    \foreach \l [count=\c] in {2,1,a5,B,$\alpha$}
    {   -- (162-\c*72:\r) coordinate (c\c) node at (162-\c*72:\r+0.3) {\l}
    };
    \draw[red, thick, -latex] (c3) -- (c5);
\end{tikzpicture}

\end{document}

Output

enter image description here

3

With tikz

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}

\definecolor{navyblue}{rgb}{0.0, 0.0, 0.5}

% calculations
\newcommand*\Angle{\calc{360/\sides}}

\begin{document}

% constants
\newcommand*\sides{5}
\newcommand*\radius{3.5}

\begin{center}

\begin{tikzpicture}[>=stealth]
\draw[gray,thick](0,0)circle(\radius);
\foreach \i in {1,...,5}{\node[fill,circle,inner sep=2pt,label=90-(\i-2)*\Angle:$\i$](\i) at ({90-(\i-2)*\Angle}:\radius){};}

\foreach \i/\j in {1/2,2/3,3/4,4/5,5/1}{
\draw[thick,navyblue,->](\i)--(\j);}

\draw[red,<->](2)--(3)node[midway,below]{r};

\end{tikzpicture}
\end{center}

\end{document}

Update

To change numbers at the vertices you can modify variables inside \foreach like this \foreach \i/\j in {1/2,2/4,3/5,4/1,5/3}{\node[fill,circle,inner sep=2pt,label=90-(\i-2)*\Angle:$\j$](\i) at ({90-(\i-2)*\Angle}:\radius){};} to obtain numbers arranged as follows 2,4,5,1,3.

enter image description here

  • Thanks a lot, this is exactly what I was looking for. However, I want to be able to manually change the numbers at the vertices, since I have to make three pictures which are almost the same, but with the numbers changed. How would you do that? – Heinz Doofenschmirtz Oct 29 '15 at 13:54
  • Then adapt rather first foreach in the / manner used in the second foreach – daleif Oct 29 '15 at 14:02

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.