
我對 Ti 比較陌生kZ,並且一直在拼湊數字,因為我需要它們來完成網路上各種範例的大學作業。
現在我正在從事研究,我必須寫更多的東西並製作更多更複雜的圖表,我認為可能是時候學習如何正確地做事了。
這是我想要產生的各種數字的範例:
有很多節點,它們之間也有很多連結。
我可以使用 Ti 重現這個數字kZ 透過單獨放置每個節點,然後為每個節點單獨建立連接,但這非常耗時,而且我需要使用更多連接來創建更大的圖形,這將更加耗時。
我想知道什麼是更聰明的方法來產生具有許多功能的大型圖形,但結構非常簡單(舉個例子,大型節點矩陣,其連接從一列中的每個節點到下一列中的每個節點)?
在某些事情上,我看到人們使用矩陣來定位節點,也可以在 Ti 中使用 for 迴圈和 if 語句kZ 也是如此,但必須深入研究並嘗試理解 Ti 的整個語言kZ 本人在我正在嘗試做的其他工作之上有點令人畏懼 - 因此,如果有人知道任何好的示例或資源,可以提供一些關於對我的目的有用的技術類型的良好高級信息,或者只是一些關於從哪裡開始的提示,我將不勝感激。
答案1
儘管使用多個\foreach
循環確實使網路的「語義」佈局有點不清楚,但它確實使其創建變得更容易。我對所需的連接採取了一些自由,否則網路開始看起來有點混亂。
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{arrows.meta,calc}
\begin{document}
\begin{tikzpicture}[>=Triangle,
cell/.style={circle, draw},
connection/.style={shorten >=.125cm, shorten <=.125cm},
]
\foreach \i in {1,...,8}
\foreach \x [count=\j] in {1,2,5,6,7}
\node [cell] (cell-\i-\j) at (\x*1.5, \i) {};
\node [cell, draw=none, below=1cm] (cell') at ($(cell-1-4)!0.5!(cell-1-5)$) {};
\node [cell, draw=none, above=1cm] (cell'') at ($(cell-8-4)!0.5!(cell-8-5)$) {};
\foreach \i in {1,...,8}{
\foreach \j in {1,3} \draw [->] (cell-\i-\j)++(-1,0) -- (cell-\i-\j);
\foreach \j in {2,5} \draw [<-] (cell-\i-\j)++(1,0) -- (cell-\i-\j);
}
\foreach \m/\n/\o/\p in {1/4/1/2,5/8/1/2, 3/6/1/2, 1/4/3/4, 5/8/3/4, 3/6/4/5}
\foreach \i in {\m,...,\n}
\foreach \j in {\m,...,\n} \draw [connection] (cell-\i-\o) -- (cell-\j-\p);
\foreach \m/\n/\q in {1/2/', 7/8/''}
\foreach \i in {\m,\n}{
\draw [connection] (cell-\i-4) -- (cell-\i-5);
\foreach \j in {4,5} \draw [connection] (cell\q) -- (cell-\i-\j);
}
\coordinate (@') at ($(cell') +(5/4,-1/2)$);
\coordinate (@'') at ($(cell'')+(5/4, 1/2)$);
\draw [<->] (cell'.center) |- (@') -- (@'') -| (cell''.center);
\node [above left=.5cm] at (cell-8-1) {in};
\node [above right=.5cm] at (cell-8-2) {out};
\node [above left=.5cm] at (cell-8-3) {in};
\node [above right=.5cm] at (cell-8-5) {out};
\draw [Implies-Implies, double, thick, double distance=5pt,
shorten >=1.25cm, shorten <=1.25cm]
($(cell-4-2)!0.5!(cell-5-2)$) -- ($(cell-4-3)!0.5!(cell-5-3)$)
node [midway, above=1cm, font=\large] {?};
\end{tikzpicture}
\end{document}