答案1
您的问题没有鸭子,但我喜欢围绕圆构建多边形的问题。
该键circle polygon = {<radius>}{<list of angles>}
绘制一个圆圈(作为允许通过键进行自定义的边缘circle edge
)并在其周围绘制一个与圆圈相切的多边形<list of angles>
。
它通过查找切线之间的交点来找到多边形的角,这些切线是通过turn
钥匙。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{ext.misc, quotes}
%\newcommand*\NextOf[2]{\pgfintmod{#1+1}{#2}}
\newcommand*\PrevOf[2]{\pgfintmod{#2+#1-1}{#2}}
\makeatletter
\pgfqkeys{/pgf/foreach}{% helpful key, could be solved via another ungrouped loop
global remember/.code args={#1as #2}{%
\pgfutil@append@tomacro\pgffor@remember@code{\gdef\noexpand#2{#1}}}}
\makeatother
\tikzset{
circle polygon/.style 2 args={
insert path={
foreach[count=\i from 0, global remember=\i as \totalAngles]\a in {#2}{
[overlay] (0,0) +(\a:{#1}) coordinate (t-\i)
([turn]-90:1) coordinate (tl-\i)
(0,0) (t-\i) ([turn] 90:1) coordinate (tr-\i)}
(0,0) edge[circle edge/.try, to path={circle[radius={#1}]}]()
foreach \i in {0, ..., \totalAngles}{
coordinate (p-\i) at (intersection of tl-\PrevOf{\i}{\totalAngles+1}--%
tr-\PrevOf{\i}{\totalAngles+1} and tl-\i--tr-\i)}
plot[sharp cycle, samples at = {0, ..., \totalAngles}](p-\x)}}}
\pgfmathsetseed{698632}
\begin{document}
\tikz[
d/.style={shape=circle, thin, draw, fill, inner sep=+0pt, minimum size=+3pt,#1},
every label/.append style={shape=circle, inner sep=+.15em},
circle edge/.style=thin,
] \draw[thick, circle polygon={5}{0+5*rand, 30+5*rand, ...+5*rand, 359+5*rand}]
node[d="$O$"] (O) at (0,0) {}
foreach[evaluate={\a=qanglebetween("t-\i");
\b=qanglebetween("p-\i");}] \i in {0, ..., \totalAngles}{
node[d="\a:$T_{\i}$"{anchor=\a+180}, fill=white] at (t-\i) {}
node[d="\b:$P_{\i}$"{anchor=\b+180}] at (p-\i) {} };
\tikz[
d/.style={shape=circle, draw, inner sep=+0pt, minimum size=+3pt,#1},
d/.pic={\draw (left:3pt) -- (right:3pt);},
circle edge/.style=dashed,
nodes=circle,
] \draw[circle polygon={3}{0+15*rand, 60+15*rand, ...+15*rand, 359+15*rand}]
node[d="$O$"] (O) at (0,0) {}
node foreach[count=\i from 0] \t in {A, ..., F}
[inner sep=+.15em,
anchor/.evaluated=180+qanglebetween("p-\i")] at (p-\i) {$\t$}
(O) foreach[count=\i from 0] \t in {P, ..., U}{
edge[path only] pic[sloped, at end] {d}
node[at end, anchor/.evaluated=180+qanglebetween("t-\i")] {$\t$} (t-\i) };
\end{document}