是否有任何巧妙的方法可以创建一个 n 边形(n 是任意整数,例如 n = 23)正多边形,内接于一个圆,使用tkz-euclide
?
或者我必须使用普通的 TikZ 函数(不像那么直观tkz-euclide
)?
答案1
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\node[regular polygon,regular polygon sides=23,draw,minimum height=5cm] (a) at (0,0) {};
\draw[red] let \p1=($(a.corner 1)-(a.center)$), \n1={veclen(\x1,\y1)} in circle (\n1);
\foreach \x[count=\xi] in {A,B,...,W}{
\node (a-\xi) at ([shift={({90+(\xi-1)*360/23}:3mm)}]a.corner \xi) {\x};
}
\end{tikzpicture}
\end{document}
答案2
PSTricks 解决方案使用pst-poly
包裹:
\documentclass{article}
\usepackage{pst-poly}
% parameters
\def\radius{4}
\def\sides{12}
\begin{document}
\begin{pspicture}[dimen = m](-\radius,-\radius)(\radius,\radius)
\rput(0,0){\PstPolygon[PolyNbSides = \sides, unit = \radius]}
\pscircle(0,0){\radius}
\end{pspicture}
\end{document}
答案3
MetaPost 解决方案使用我自己的宏。示例毫无保留地受到 Svend Tveskæg 的回答的启发。
\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
vardef regular_polygon(expr center, radius, n) =
save angl; angl := 360/n;
(right for i = 1 upto n-1: -- dir(i*angl) endfor -- cycle)
scaled radius shifted center
enddef;
beginfig(0);
draw regular_polygon(origin, 4cm, 12);
draw fullcircle scaled 8cm;
endfig;
\end{mplibcode}
\end{document}
编辑另一个版本,更详细一些,带有字母标签。峰顶数量n
必须低于 27,才能保持标签的连贯性 :-)
\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
vardef regular_polygon(expr centre, radius, n) =
clearxy; save angl; angl := 360/n;
z0 = centre + radius*right; freelabel("$A$", z0, centre);
z0 for i = 1 upto n-1:
hide(z[i] = z[i-1] rotatedaround(centre, angl);
freelabel("$" & char(65+i) & "$", z[i], centre))
-- z[i]
endfor -- cycle
enddef;
beginfig(0);
draw regular_polygon(origin, 4cm, 12) withcolor red;
draw fullcircle scaled 8cm;
endfig;
\end{mplibcode}
\end{document}