1

Is there an easy way I can connect the vertices of these graphs using the code I have? In other words, I want to connect the first node of the smaller decagon with the first node of the larger decagon, the second node of the smaller decagon with the second node of the larger decagon, etc.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric, positioning, calc}
\tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
    \tikzset{mynode/.style={circle, radius=.25pt, draw=darkgray, fill=white}}
        \begin{center}
            \begin{tikzpicture}
                \node[draw, minimum size=2cm, regular polygon, regular polygon sides=10] (epta) {};
                \foreach \x in {1,2,...,10}{%
                \node[mynode] at (epta.corner \x) (e\x) [fill=black,scale=0.5] {};}
                
                \node[draw, minimum size=4cm, regular polygon, regular polygon sides=10] (epta) {};
                \foreach \y in {1,2,...,10} {%
                \node[mynode] at (epta.corner \y) (e\y) [fill=black,scale=0.5] {};}
            \end{tikzpicture}
        \end{center}
\end{document}

enter image description here

2
  • straight from the manual -- use graphs and sub-graphs
    – js bibra
    Oct 16, 2020 at 0:57
  • It think you display name will be changed by the site owner soon. Oct 16, 2020 at 5:41

3 Answers 3

4

Using your own tikzpicture:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric, positioning, calc}
\tikzset{main node/.style={circle,fill=black,draw,minimum size=.2cm,inner sep=0pt},}
    \tikzset{mynode/.style={circle, radius=.25pt, draw=darkgray, fill=white}}
        \begin{center}
            \begin{tikzpicture}
                \node[draw, minimum size=2cm, regular polygon, regular polygon sides=10] (epta) {};
                \foreach \x in {1,2,...,10}{%
                \node[mynode] at (epta.corner \x) (e\x) [fill=black,scale=0.5] {};}
                
                \node[draw, minimum size=4cm, regular polygon, regular polygon sides=10] (epta) {};
                \foreach \y in {1,2,...,10} {%
                \node[mynode] at (epta.corner \y) (e\y) [fill=black,scale=0.5] {};}
                \foreach \a in {1,...,10}
                  \draw (36*\a:1) -- (36*\a:2);
            \end{tikzpicture}
        \end{center}
\end{document}

Or, another short version:

\begin{tikzpicture}[dot/.style={fill,inner sep=2pt,circle}]
\foreach \a [count=\b from 0] in {1,...,10} {
  \draw (36*\a:1) node [dot]{} -- (36*\a:2) node[dot]{};
  \draw (36*\a:1) -- (36*\b:1) (36*\a:2) -- (36*\b:2);
}
\end{tikzpicture}

Or, an even shorter version from the manual as pointed out by @jsbibra:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard} 

\begin{document}

\begin{tikzpicture}
\graph [nodes={fill, circle}, clockwise, radius=1cm, empty nodes, n=10] {
subgraph C_n [name=inner] -- subgraph C_n [name=outer]
};
\end{tikzpicture}

\end{document}

enter image description here

1

A simple, short code with using graph and graph.standard TikZ libraries:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary {graphs,
                 graphs.standard}

\begin{document}
\begin{tikzpicture}
\graph [nodes={fill, circle, inner sep=1pt, outer sep=0pt}, 
        clockwise, radius=1cm, empty nodes, n=8]
           {
            subgraph C_n [name=inner] -- 
            subgraph C_n [name=outer]
            };
\end{tikzpicture}
\end{document}

enter image description here

1

A PSTricks solution only for either fun or comparison purposes.

\documentclass[pstricks,margin=5mm]{standalone}
\usepackage{pst-node,pst-plot}
\def\N{10}
\begin{document}
\begin{pspicture}[showpoints,dotscale=2,linecolor=red,plotpoints=\numexpr\N+1\relax](-4,-4)(4,4)
    \curvepnodes{0}{360}{4 t PtoC}{A}
    \curvepnodes{0}{360}{2 t PtoC}{B}
    \psnpolygon(0,\numexpr\N-1){A}
    \psnpolygon(0,\numexpr\N-1){B}
    \foreach \i in {1,2,...,\N}{\psline(A\i)(B\i)}
\end{pspicture}
\end{document}

enter image description here

Animated Version

Only for dynamic people who like seeing moving objects.

enter image description here

\documentclass[pstricks,margin=5mm]{standalone}
\usepackage{pst-node,pst-plot}
\def\N{10}
\begin{document}
\foreach \r in {0.5,1.5,...,3.5}{
\begin{pspicture}[showpoints,dotscale=2,linecolor=red,plotpoints=\numexpr\N+1\relax](-4,-4)(4,4)
    \curvepnodes{0}{360}{4 t PtoC}{A}
    \curvepnodes{0}{360}{\r\space t PtoC}{B}
    \psnpolygon(0,\numexpr\N-1){A}
    \psnpolygon(0,\numexpr\N-1){B}
    \foreach \i in {1,2,...,\N}{\psline(A\i)(B\i)}
\end{pspicture}}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .