Graphics, Figures & TablesDrawing Diagonals of regular polygon

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
pufik
Posts: 10
Joined: Tue Jun 06, 2023 12:15 pm

Drawing Diagonals of regular polygon

Post by pufik »

Is there a way to use the notation \draw (p.corner /n) -- (p.corner /k) ; in tkiz instead of actually knowing the points?
This is my code. Any help would be appreciated! More specifically im trying to draw diagonals from A_1 to A_8 etc.
\begin{tikzpicture}

\node (p) [draw,rotate=90,minimum size=10cm,regular polygon, regular polygon sides=9] at (0,0) {};

\draw (0,0) circle (5 cm);

\foreach \n [count=\nu from 1, remember=\n as \lastn, evaluate={\nu+\lastn}] in {1,2,...,9}
\node[anchor=\n*(360/9)]at(p.corner \n){$A_{\nu}$};

\foreach \x in {1,2,...,9}
\fill (p.corner \x) circle[radius=1.5 pt];

\end{tikzpicture}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Drawing Diagonals of regular polygon

Post by Bartman »

Please create a Infominimal working example and mark its code so that it can be tested immediately.

If the diagonals are allowed to look the same as the sides of the polygon, then a possible solution can be kept quite simple. My suggestion uses percusse's answer:

Code: Select all

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
\newcommand{\pSides}{9}
\draw 
  node (p) [
    rotate=90,
    minimum size=10cm,
    regular polygon, 
    regular polygon sides=\pSides
  ] {}
  circle [radius=5cm]
;

\foreach \n in {1,2,...,\pSides}{
  \node[anchor=\n*(360/\pSides)] at (p.corner \n) {$A_{\n}$};
  \fill (p.corner \n) circle [radius=1.5pt];
  \ifnum\n<\pSides
    \foreach\k in {\n,...,\pSides}
      \draw (p.corner \n) -- (p.corner \k);
  \fi
}
\end{tikzpicture}
\end{document}
Post Reply