3

I would like to draw a regual 21 polygon, where the edges are labelled and have arrows in the middle. But I don't know how to get the arrows. This is what I have done so far

\documentclass[border=5mm, tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}

\begin{tikzpicture}

\node (pol) [
  draw,
  minimum size=0.9\textwidth,
  regular polygon, regular polygon sides=21,
  rotate=270,
  ]{};
\foreach \x/\y/\i in {1/2/1,3/4/1,5/6/2,7/8/2,9/10/3,11/12/3}
  \path[auto=right]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\alpha_ {\i}$};
\foreach \x/\y/\i in {2/3/1,4/5/1,6/7/2,8/9/2,10/11/3,12/13/3}
  \path[auto=right]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\beta_ {\i}$};
 \foreach \x/\y/\i in {13/14/1, 15/16/1, 16/17/2,18/19/2,19/20/3,21/1/3}
  \path[auto=right]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\xi_ {\i}$};
      \foreach \x/\y/\i in {14/15/1,17/18/2,20/21/3}
  \path[auto=right]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\rho_ {\i}$};
\end{tikzpicture}

\end{document}

This gives me enter image description here

I would like to have something like thisenter image description here

How can I add these arrows? I would prefer to expand my existing code rather then using soomething completely different, unless I did it way too complicated?

8

Here is what I got using my personal style ->- and -<-. To make it more versatile, I also define several arrow types, try it out using say \draw[->-=6pt red 2] (0,0) -- (1,1); where 6pt is the size of the arrow, red the color and 2 the type. One good thing about ->- and -<- is that the center of the arrow is perfectly at the middle of the path, and the direction of the arrow is exactly the same as the tangential direction at the middle point of the path (works for any path type, -- line, curve to lines etc), Here is an example illustrating this point.

enter image description here

\documentclass[margin=0pt]{standalone}
\usepackage[svgnames]{xcolor}
%---------------------------- Tikz Libraries ------------------------------%
\usepackage{ifthen}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations, decorations.markings} 

%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[->-] or \draw[->-=6pt red 1]
%-------------------------------------------------------------------------------%
\tikzset{
  ->-/.style args={#1 #2 #3}{
    decoration={
      markings,
      mark= at position 0.5 with
      {
        \ifthenelse{#3 = 1}
        {
          \fill[#2] (#1/-6.0,0pt) -- (-0.5*#1, #1/3.0) -- (0.5*#1,0pt) -- (-0.5*#1, #1/-3.0);   % stealth type
        }
        {
          \ifthenelse{#3 = 2}
          {
            \fill[#2] (#1/2.0,0pt) -- (-0.5*#1, #1/3.0) -- (-0.5*#1, #1/-3.0);   % latex type
          }
          {
            \ifthenelse{#3 = 3}
            {
              % \draw[thick, #2]  (-0.433*#1,#1/2) -- (0.433*#1, 0) -- (-0.433*#1,-#1/2);  % 60 degree arrow
              \draw[semithick, #2]  (-0.533*#1,#1/2) -- (0.433*#1, 0) -- (-0.533*#1,-#1/2);  % 40 degree arrow
            }{}
          }
        }
      },
    },
    postaction={decorate}
  },
  ->-/.default={6pt black 1}
}


%==========================  Middle & pointing arrows ==========================%
%-------------------------------------------------------------------------------%
% usage: \draw[-<-] path; or \draw[-<-=6pt red 1] path;
%-------------------------------------------------------------------------------%
\tikzset{
  -<-/.style args={#1 #2 #3}{
    decoration={
      markings,
      mark= at position 0.5 with
      {
        \ifthenelse{#3 = 1}
        {
          \fill[#2] (#1/6.0,0pt) -- (0.5*#1, #1/3.0) -- (-0.5*#1,0pt) -- (0.5*#1, #1/-3.0);   % stealth type
        }
        {
          \ifthenelse{#3 = 2}
          {
            \fill[#2] (#1/-2.0,0pt) -- (0.5*#1, #1/3.0) -- (0.5*#1, #1/-3.0);   % latex type
          }
          {
            \ifthenelse{#3 = 3}
            {
              % \draw[thick, #2]  (-0.433*#1,#1/2) -- (0.433*#1, 0) -- (-0.433*#1,-#1/2);  % 60 degree arrow
              \draw[semithick, #2]  (0.533*#1,#1/2) -- (-0.433*#1, 0) -- (0.533*#1,-#1/2);  % 40 degree arrow
            }{}
          }
        }
      },
    },
    postaction={decorate}
  },
  -<-/.default={6pt black 1}
}


\begin{document}

\begin{tikzpicture}
\draw[step=0.5cm, help lines, LightSkyBlue] (-7,-7) grid (7,7);
\node (pol) [
  draw,
  minimum size=0.9\textwidth,
  regular polygon, regular polygon sides=21,
  rotate=270,
  ]{};
\foreach \x/\y/\i in {1/2/1,3/4/1,5/6/2,7/8/2,9/10/3,11/12/3}
  \path[auto=right, ->-]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\alpha_ {\i}$};
\foreach \x/\y/\i in {2/3/1,4/5/1,6/7/2,8/9/2,10/11/3,12/13/3}
  \path[auto=right, -<-]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\beta_ {\i}$};
 \foreach \x/\y/\i in {13/14/1, 15/16/1, 16/17/2,18/19/2,19/20/3,21/1/3}
  \path[auto=right]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\xi_ {\i}$};
      \foreach \x/\y/\i in {14/15/1,17/18/2,20/21/3}
  \path[auto=right]
    (pol.corner \x)--(pol.corner \y)
      node[midway]{$\rho_ {\i}$};
\end{tikzpicture}


\end{document}
  • Thanks! This is really helpful. Unfortunately, the shape looks a bit different then the "stealth" type, which I would use for decorating a circle: \draw[decoration={markings, mark=at position 0.26 with {\arrow{stealth}}}, postaction={decorate}] (0,0) circle (20pt); How can I use your type of arrow here? Or I would like to change yours to the looking of -<- How do I do that? – mathstackuser Dec 19 '18 at 13:38
  • @mathstackuser add \usetikzlibrary{arrows, arrows.meta} in the preamble and change the definition of ->- to \tikzset{ ->-/.style args={#1 #2 #3}{ decoration={ markings, mark= at position #1 with {\arrow{Stealth[#3,length=#2]}}, }, postaction=decorate, opacity=1.0 }, ->-/.default= 0.5 6pt black }. And for the reversed style one should use Stealth[reversed, #3,length=#2] – Kevin Powell Dec 19 '18 at 14:17
4

As as a starting point, following code, based on my another answer How to draw all (or some) symmetries axes of a regular polygon, maybe useful.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, calc}
\usetikzlibrary{decorations.markings}
\usepackage{ifthen}
\begin{document}

\begin{tikzpicture}[scale=3]
\def\rps{21} % regular polygon sides
\node (a) 
[draw,  blue!0!black,rotate=90,minimum size=3cm,regular polygon, regular polygon sides=\rps] at (0, 0) {}; 

\draw (a);
\pgfmathtruncatemacro{\rpslast}{\rps+1};
\foreach \x in {1,2,...,\rps}{
%\foreach \y in {1,2,...,\rpslast}{
\pgfmathtruncatemacro{\y}{\x+1};
\ifnum\y < \rpslast
  \begin{scope}[thin,decoration={
    markings,
    mark=at position 0.5 with {\arrow{>}}}
    ] 
    \draw[postaction={decorate}] (a.corner \x)--(a.corner \y);
    \draw[postaction={decorate}] (a.corner \rps)--(a.corner 1);       
\end{scope}
    \else
\fi
}
\end{tikzpicture}
\end{document} 

enter image description here

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.