我需要将 5-gone 的每个顶点与 10-gone 当前连接的顶点的对立面连接起来。参见图片(颜色必须是黑色):
到目前为止,我有以下内容,但是两个顶点没有正确连接。
\documentclass[10pt]{article}
\usepackage{amstext}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage[margin=1.5in]{geometry} % For reducing margin
\usepackage{graphicx}
\usetikzlibrary{shapes,positioning}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=10, minimum size=4cm, draw=black, shape border rotate=20, name=x] at (6,6) {};
\node[regular polygon, regular polygon sides=5, minimum size=1.5cm, draw=black, name=y] at (6,6) {};
\foreach \corner in {1,2,...,10}
\node[circle,ball color=black,inner sep=0pt,minimum size=5pt] at (x.corner \corner){};
\foreach \corner in {1,2,...,5}
\node[circle,ball color=black,inner sep=0pt,minimum size=5pt] at (y.corner \corner){};
\draw foreach[
evaluate={\cornerA=int(2*\c);
\cornerB=int(\cornerA-1);}] \c in {1,...,5}{
(x.corner \cornerB) -- (y.corner \c)
};
\draw foreach[
evaluate={\cornerA=int(2*\c);
\cornerB=int(\cornerA+4);}] \c in {1,...,5}{
(x.corner \cornerB) -- (y.corner \c)
};
\end{tikzpicture}
答案1
对原始代码的更改:
- 将外部多边形旋转 18°(180°/10),而不是 20°。
- 用于
outer sep = 0pt
多边形,以便角实际上位于指定的直径处。 - 命名球节点以便它们可以这样使用,这将使边缘停止在其边界处而不是在它们上面绘制。
- 该函数会计算对角的值
mod
,通常如果角的编号是从 0 到 9 的话就会这样<corner opposite> = mod(<corner>+5, 10)
,但是由于它们的编号是从 1 到 5,所以我们只在 Mod 函数内部添加 4,在外部添加 1。
我还通过库添加了类似的绘图graphs
,这非常接近我最近的另一个回答,我使用相同的 foreach 评估来绘制对角线边缘。
我用红色和黑色的双重函数绘制了它们,以表明它们不会穿过整个图表,而是停止在内球上。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs.standard, shapes.geometric}
\begin{document}
\begin{tikzpicture}[
rp/.style={regular polygon, regular polygon sides={#1}, outer sep=+0pt},
ball/.style={
circle, outer sep=auto, ball color=black, inner sep=0pt, minimum size=5pt}
]
\node[rp=10, minimum size=4cm, draw=black, rotate=18, name=outer] at (6,6) {};
\node[rp=5, minimum size=1.5cm, draw=black, name=inner] at (6,6) {};
\foreach \corner in {1,2,...,10}
\node[ball] (outer-corner-\corner) at (outer.corner \corner){};
\foreach \corner in {1,2,...,5}
\node[ball] (inner-corner-\corner) at (inner.corner \corner){};
\foreach[evaluate={
\cOuter=int(2*\cInner-1);
\cOpposite=int(mod(\cOuter+4,10)+1);
}]\cInner in {1,...,5}
\draw (outer-corner-\cOuter)
-- (inner-corner-\cInner)
-- (outer-corner-\cOpposite);
\end{tikzpicture}
\tikz\graph[
nodes={
circle, outer sep=+0pt, ball color=black, inner sep=+0pt, minimum size=+5pt},
counterclockwise, phase = 90, typeset =,
]{
subgraph C_n[name=inner, n= 5] -!-
subgraph C_n[name=outer, n=10],
{ [edge={double=black, red, thick}]
\foreach[evaluate={
\cOuter=int(2*\cInner-1);
\cOpposite=int(mod(\cOuter+4,10)+1);
}] \cInner in {1,...,5} {
inner \cInner -- {outer \cOuter, outer \cOpposite}},
}
};
\end{document}
输出
答案2
虽然我们找到了更自动化的解决方案,但这里有一个手动的解决方案:
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage[margin=1.5in]{geometry} % For reducing margin
\usetikzlibrary{shapes,positioning}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=10, minimum size=4cm, draw=black, shape border rotate=20, name=x] at (6,6) {};
\node[regular polygon, regular polygon sides=5, minimum size=1.5cm, draw=black, name=y] at (6,6) {};
\foreach \corner in {1,2,...,10}
\node[circle,ball color=black,inner sep=0pt,minimum size=5pt] at (x.corner \corner){};
\foreach \corner in {1,2,...,5}
\node[circle,ball color=black,inner sep=0pt,minimum size=5pt] at (y.corner \corner){};
%\draw foreach[
% evaluate={\cornerA=int(2*\c);
% \cornerB=int(\cornerA-1);
% \cornerC=int(mod(\cornerB+5,10);}] \c in {1,...,5}{
% (x.corner \cornerB) -- (y.corner \c) -- (x.corner \cornerC)
% };
\draw foreach \a/\b/\c in {1/1/6, 2/3/8, 3/5/10, 4/7/2, 5/9/4}
{(x.corner \b)--(y.corner \a)--(x.corner \c)};
\end{tikzpicture}
\end{document}
更新:
此代码应用了 Qrrbrbirlbel 提出的旋转校正和一种计算顶点连接的自动方法。此连接仍然绘制在五边形顶点处停止。
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usepackage[margin=1.5in]{geometry} % For reducing margin
\usetikzlibrary{shapes,positioning}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=10, minimum size=4cm, draw=black, shape border rotate=18, name=x] at (6,6) {};
\node[regular polygon, regular polygon sides=5, minimum size=1.5cm, draw=black, name=y] at (6,6) {};
\foreach \corner in {1,2,...,10}
\node[circle,ball color=black,inner sep=0pt,minimum size=5pt] at (x.corner \corner){};
\foreach \corner in {1,2,...,5}
\node[circle,ball color=black,inner sep=0pt,minimum size=5pt] at (y.corner \corner){};
\draw foreach[
evaluate={\cornerA=int(2*\c);
\cornerB=int(\cornerA-1);
\cornerC=ifthenelse(\cornerB+5>10, int(mod(\cornerB+5,10)), int(\cornerB+5));}] \c in {1,...,5}{
(x.corner \cornerB) -- (y.corner \c) -- (x.corner \cornerC)
};
\end{tikzpicture}
\end{document}