
이 질문은 다음과 밀접하게 관련되어 있습니다.https://math.stackexchange.com/questions/3449433/selecting-cards-to-form-a-fair-game?noredirect=1#comment7090962_3449433. 나는 공 더미에서 3개의 공을 뽑는 방법을 시각적으로 설명하려고 합니다. N+M
여기서 N
는 파란색의 숫자이고 는 M
녹색의 숫자입니다.
tikz에서 이 작업을 수행하려는 나의 시도는 아래에서 볼 수 있습니다. 여기에서는 먼저 공을 순서대로 배열한 다음 공 하나를 제거했을 때 공이 어떻게 나타나는지 보여줍니다. 두 공 사이의 선은 이 두 공이 점선 공과 함께 선택되었음을 나타냅니다.
그러나 제가 하고 싶은 몇 가지 변화가 있습니다.
- 그래서 우리는 3개의 공을 선택합니다. 두 개는 선과 점선으로 연결되어 있습니다. 이 세 개의 공이 동일한 색상인 경우, 공을 연결하는 선을 X 스타일(점선, 빨간색 등)으로 표시하고 싶습니다.
- 세 개의 공의 색상이 서로 다른 경우 공을 연결하는 선을 Y 스타일(실선, 주황색 등)로 지정하고 싶습니다.
- 특정 경우에 내 코드가 실패하는 이유는 무엇입니까
2
? - 파란색 공과 녹색 공의 개수를 다르게 하여 코드를 작동시킬 수 있는 방법이 있나요?
- 외부 다각형의 모서리와 일치하도록 중앙 다각형의 회전을 어떻게 선택할 수 있습니까? 이제 내부를 수동으로 맞추도록 변경했습니다.
아래 코드가 작동하지 않는 특별한 이유가 있나요?
\foreach \x in {1,...,\n}{ \begin{scope}[shift={(b.corner \x)}] \missingPentagonTemp{2}{c}; \end{scope} }
제가 원하는 모습은 다음과 같습니다(페인트 제공).
MWE
\documentclass[a4paper,11pt,margin=5pt]{standalone}
\usepackage{tikz,xcolor}
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{decorations}
\usepackage{ifthenx}
\newcommand{\missingPentagon}[2]{
% draw edges
\node[draw=none, minimum size=3cm, regular polygon, regular polygon sides = \n] (#2) {};
\def\n{6}
\pgfmathsetmacro{\start}{int(min(#1+1, \n))};
\pgfmathsetmacro{\stop}{int(max(#1-1, 2))};
\ifthenelse{\equal{#1}{1}}{
\foreach\x in{2,...,\n}{
\foreach\y in{\x,...,\n}{
\draw[color = black, dashed](#2.corner \x)--(#2.corner \y);
}
}
\foreach \x in {1}{
\draw[fill=green!20,dashed](#2.corner \x) circle[radius=1em] node {\x};
}
\foreach \x in {2,...,\n}{
\draw[fill=blue!20](#2.corner \x) circle[radius=1em] node {\x};
}
}{
\foreach\x in {1,...,\stop}{
\foreach\y in {\x,...,\n}{
\ifthenelse{\equal{#1}{\y}}{}{
\draw[color = black, dashed](#2.corner \x) -- (#2.corner \y)};
}
}
\foreach\x in {\start,...,\n}{
\foreach\y in {\x,...,\n}{
\ifthenelse{\equal{#1}{\y}}{}{
\draw[color = black, dashed](#2.corner \x) -- (#2.corner \y)};
}
}
\foreach \x in {1}{
\draw[fill=green!20](#2.corner \x) circle[radius=1em] node {\x};
}
\foreach \x in {2,...,\n}{
\ifthenelse{\equal{#1}{\x}}{
\draw[fill=blue!20,dashed](#2.corner \x) circle[radius=1em] node {\x};
}{
\draw[fill=blue!20](#2.corner \x) circle[radius=1em] node {\x};
};
}
}
}
\begin{document}
\begin{tikzpicture}
\def\n{6}
\node[draw=none, minimum size=3cm, regular polygon, regular polygon sides = \n] (a) {};
\node[draw=none, minimum size=10cm, regular polygon, regular polygon sides = \n] (b) {};
\foreach \x in {4}{
\draw[fill=green!20](a.corner \x) circle[radius=1em] node {1};
}
\foreach \x in {1,...,3}{
\pgfmathparse{int(\x+3)}
\draw[fill=blue!20](a.corner \x) circle[radius=1em] node {\pgfmathresult};
}
\foreach \x in {5,...,6}{
\pgfmathparse{int(\x-3)}
\draw[fill=blue!20](a.corner \x) circle[radius=1em] node {\pgfmathresult};
}
%\foreach \x in {1,...,\n}{
% \begin{scope}[shift={(b.corner \x)}]
% \missingPentagonTemp{2}{c};
% \end{scope}
%}
\begin{scope}[shift={(b.corner 1)}]
\missingPentagon{4}{c};
\end{scope}
\begin{scope}[shift={(b.corner 2)}]
\missingPentagon{5}{c};
\end{scope}
\begin{scope}[shift={(b.corner 3)}]
\missingPentagon{6}{c};
\end{scope}
\begin{scope}[shift={(b.corner 4)}]
\missingPentagon{1}{c};
\end{scope}
\begin{scope}[shift={(b.corner 5)}]
\missingPentagon{2}{c};
\end{scope}
\begin{scope}[shift={(b.corner 6)}]
\missingPentagon{3}{c};
\end{scope}
\end{tikzpicture}
\end{document}
답변1
이것은 로 질문에 대답하려는 시도입니다 pic
. 이 코드는 정점이 누락되거나 강조 표시된 정점 목록에 있는지 여부를 확인하고(예, 이제 목록을 사용할 수 있습니다) 이에 따라 가장자리를 그립니다.
귀하의 요점은 다음과 같습니다.
- 완료.
- 완료. 이 시점에서 스타일은 견고합니다. 그것을 바꿀 수 있습니다.
- 솔직히, 나는 코드를 통해 생각하려고 노력하지 않았습니다. 죄송합니다.
- 예. 이제 이것들은 목록입니다.
- 변경되었습니다. 단순히 다각형을 회전할 수도 있지만 저는 모드 조건을 좋아합니다. ;-)
- 다시 말하지만 나는 시도하지 않았습니다. 죄송합니다.
전체 코드:
\documentclass[a4paper,11pt,margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\makeatletter
\pgfmathdeclarefunction{memberQ}{2}{%
\begingroup%
\edef\pgfutil@tmpb{0}%memberQ({\lstPast},\inow)
\edef\pgfutil@tmpa{#2}%
\expandafter\pgfmath@member@i#1\pgfmath@token@stop
\edef\pgfmathresult{\pgfutil@tmpb}%
\pgfmath@smuggleone\pgfmathresult%
\endgroup}
\def\pgfmath@member@i#1{%
\ifx\pgfmath@token@stop#1%
\else
\edef\pgfutil@tmpc{#1}%
\ifx\pgfutil@tmpc\pgfutil@tmpa\relax%
\gdef\pgfutil@tmpb{1}%
\fi%
\expandafter\pgfmath@member@i
\fi}
\makeatother
\tikzset{circ/.style={circle,minimum size=2em,draw},
pics/missing polygon/.style={code={
\tikzset{missing polygon/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/missing polygon/##1}}
\node[draw=none, minimum size=\pv{size},
regular polygon, regular polygon sides =\pv{n}] (-poly) {};
% test if the highlighted node is in the missin nodes
\edef\lsthigh{\pv{highlight}}
\foreach \XX in \lsthigh
{\pgfmathtruncatemacro{\ktest}{memberQ(\pv{miss},\XX)}
\xdef\pgfmathresult{\ktest}}
\edef\ktest{\pgfmathresult}
\foreach \XX in {1,...,\the\numexpr\pv{n}-1}
{
\foreach \YY in {2,...,\pv{n}}
{
\pgfmathtruncatemacro{\itest}{memberQ(\pv{miss},\XX)+memberQ(\pv{miss},\YY)}
\ifnum\itest=0
\pgfmathtruncatemacro{\jtest}{memberQ(\pv{highlight},\XX)+memberQ(\pv{highlight},\YY)}
\draw \ifnum\jtest=0 [dashed]\fi \ifnum\ktest=1 [solid]\fi
(-poly.corner \XX) -- (-poly.corner \YY);
\fi
}
}
\foreach \XX in {1,...,\pv{n}}
{\pgfmathtruncatemacro{\itest}{memberQ(\pv{highlight},\XX)}
\ifnum\itest=1
\node[missing polygon/highlighted] (-poly-vertex-\XX) at (-poly.corner \XX){\XX};
\else
\pgfmathtruncatemacro{\jtest}{memberQ(\pv{miss},\XX)}
\ifnum\jtest=1
\node[missing polygon/missing] (-poly-vertex-\XX) at (-poly.corner \XX){\XX};
\else
\node[missing polygon/regular] (-poly-vertex-\XX) at (-poly.corner \XX){\XX};
\fi
\fi
}
}},missing polygon/.cd,size/.initial=3cm,n/.initial=6,
miss/.initial={2},highlight/.initial={1},
highlighted/.style={circ,fill=green!20},
missing/.style={circ,fill=blue!20,dashed},
regular/.style={circ,fill=blue!20}
}
\begin{document}
\begin{tikzpicture}
\def\n{6}
\node[draw=none, minimum size=3cm, regular polygon, regular polygon sides = \n] (a) {};
\node[draw=none, minimum size=10cm, regular polygon, regular polygon sides = \n] (b) {};
\foreach \X in {1,...,\n}{
\pgfmathparse{int(1+Mod(\X-4,6))}
\draw \ifnum\X=4 [fill=green!20] \else [fill=blue!20]\fi
(a.corner \X) circle[radius=1em] node {\pgfmathresult};
}
\path foreach \X in {1,...,\n}
{ [/utils/exec=\pgfmathtruncatemacro{\mymiss}{int(1+Mod(\X-4,6))}]
(b.corner \X) pic(m\X){missing polygon={miss={\mymiss}}}};
\end{tikzpicture}
\end{document}