![我想画一个完全图的笛卡尔积,如下图所示](https://linux22.com/image/339963/%E6%88%91%E6%83%B3%E7%94%BB%E4%B8%80%E4%B8%AA%E5%AE%8C%E5%85%A8%E5%9B%BE%E7%9A%84%E7%AC%9B%E5%8D%A1%E5%B0%94%E7%A7%AF%EF%BC%8C%E5%A6%82%E4%B8%8B%E5%9B%BE%E6%89%80%E7%A4%BA.png)
答案1
你喜欢么:
上图生成方式如下:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
every node/.style = {draw=black, minimum size=2cm},
node distance = 2cm]
\node (A) {};
\node (B) [right=of A] {};
\foreach \pos [count=\i] in {north west, north east, south west, south east}
{
\fill[gray] (A.\pos) circle (2mm) (B.\pos) circle (2mm);
\ifnum\i<3
\draw[green, thick] (A.\pos) to [bend left=30] (B.\pos);
\else
\draw[green, thick] (A.\pos) to [bend right=30] (B.\pos);
\fi
}
\end{tikzpicture}
\end{document}
在上面的代码中,我利用了 TikZ 库,positioning
通过该库将第二个节点定位在node distance
第一个节点的右侧。圆和绿色圆弧通过\foreach
循环绘制,其中圆的定义位置和附加计数器\i
用于绘制圆弧:对于上面两个使用bend=left
,对于第二个使用bend=right
。
答案2
尝试这个
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[minimum size=2cm,draw, black] (A) at (0,0){};
\node[minimum size=2cm,draw, black] (B) at (4,0){};
\foreach \pos/\bend in {north east/left, south east/right, north west/left, south west/right}{
\draw[fill] (A.\pos) circle (0.1);
\draw[fill] (B.\pos) circle (0.1);
\draw[green, thick] (A.\pos) to [bend \bend=20] (B.\pos);
}
\end{tikzpicture}
\end{document}