0

How could I draw, using tikz, a regular heptagon of area 7 sq.units?

2 Answers2

5

For regular polygon of n sides with area S, length from center to a vertex r, we have the formula

enter image description here

The TikZ code is using foreach inside one \draw command. The unit here is cm - the default unit of TikZ.

enter image description here

\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}

Black Mild
  • 17,569
4

A quick search points to shapes.geometric. I let you do the math to find the appropriate radius ;-)

enter image description here

\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}

tobiasBora
  • 8,684