How could I draw, using tikz, a regular heptagon of area 7 sq.units?
-
1What have you tried so far? Please show us that code ... – Mensch Sep 22 '21 at 15:54
2 Answers
For regular polygon of n sides with area S, length from center to a vertex r, we have the formula
The TikZ code is using foreach inside one \draw command. The unit here is cm - the default unit of TikZ.
\documentclass[tikz,border=5mm]{standalone}
\usepackage{amsmath}
\begin{document}
% for maths
\begin{tikzpicture}
\node{$S=\dfrac{nr^2\sin\left(\frac{360}{n}\right)}{2}$ \quad implies\quad $r=\sqrt{\dfrac{2S}{n\sin\left(\frac{360}{n}\right)}}$};
\end{tikzpicture}
\begin{tikzpicture}
\def\n{7} % number of sides of a heptagon
\def\S{7} % the area of that heptagon
\pgfmathsetmacro{\k}{360/\n}
\pgfmathsetmacro{\r}{(sqrt(2\S))/(\nsin(\k))}
\draw[violet] (90:\r)
foreach \i[parse=true] in {1,...,\n-1} {--({90+\k*\i}:\r)}--cycle;
\end{tikzpicture}
\end{document}
- 17,569
A quick search points to shapes.geometric. I let you do the math to find the appropriate radius ;-)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
{\def\PolyRadius{2cm}
\begin{tikzpicture}
% Remove next line to remove the red circle
\draw[red] (0,0) circle [radius=\PolyRadius];
\node[regular polygon,draw,regular polygon sides = 7,minimum size=2*\PolyRadius] at (0,0) {};
\end{tikzpicture}
}
\end{document}
- 8,684


