![如何在弯曲边缘的中心创建节点](https://linux22.com/image/449174/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BC%AF%E6%9B%B2%E8%BE%B9%E7%BC%98%E7%9A%84%E4%B8%AD%E5%BF%83%E5%88%9B%E5%BB%BA%E8%8A%82%E7%82%B9.png)
我希望绘制一个图形,使得红色顶点恰好位于每个蓝色边的中心。代码如下:
\begin{tikzpicture}
\tikzset{pointblue/.style={fill=blue, circle, minimum width=3pt, scale=0.6}}
\tikzset{pointred/.style={fill=red, circle, minimum width=3pt, scale=0.6}}
% blues vertices
\coordinate (X) at (-0.5,0);
\coordinate (Z) at (2,-1.5);
\coordinate (T) at (-0.5,2);
%% blues vertices.
\node at (X) [pointblue] (x) {};
\node at (Z) [pointblue] (z) {};
\node at (T) [pointblue] (t) {};
%%% blues edges
\draw[thick, blue] (z) edge[bend right=25] (x);
\draw[thick, blue] (z) edge[bend left=45] (x);
\draw[thick, blue] (x) -- (t);
\draw[thick, blue] (x) edge[bend left=60] (t);
\draw[thick, blue] (x) edge[bend right=60] (t);
% reds vertices
\coordinate (X2T2) at (-1,1);
\coordinate (X1T1) at ($(X)!.5!(T)$);
\coordinate (XT) at (0,1);
\coordinate (ZX) at (1,-0.5);
\coordinate (Z1X1) at (0.5,-1.3);
% reds vertices.
\node at (ZX) [pointred] (zx) {};
\node at (Z1X1) [pointred] (z1x1) {};
\node at (XT) [pointred] (xt) {};
\node at (X1T1) [pointred] (x1t1) {};
\node at (X2T2) [pointred] (x2t2) {};
% reds edges
\draw[thick, red] (x2t2) edge[bend right = 60] (z1x1);
\end{tikzpicture}
目前的情况如下:
我正在手动计算红色顶点的坐标(请注意,它们不在中心)。我知道如何计算没有弯曲的边缘的中心坐标(例如,在我使用的代码中:)\coordinate (X1T1) at ($(X)!.5!(T)$);
。有没有办法计算有弯曲的蓝色边缘的中心,而无需手动完成?
答案1
您不需要单独定义节点的坐标。只需使用
\node[pointblue] at (-0.5,0) (x){};
红色节点可以用作语句midway
的一部分进行定义\draw
。此外,\draw
当语句具有相同的样式时,可以将它们组合在一起,并且可以在一个语句中定义多种样式tikzset
。
\documentclass{article}
\usepackage{tikz}
\tikzset{pointblue/.style={fill=blue, circle, minimum width=3pt, scale=0.6},
pointred/.style={fill=red, circle, minimum width=3pt, scale=0.6}}
\begin{document}
\begin{tikzpicture}
% blues vertices
\node[pointblue] at (-0.5,0) (x){};
\node[pointblue] at (2,-1.5) (z){};
\node[pointblue] at (-0.5,2) (t){};
%%% blues edges
\draw[thick, blue] (z) to[bend right=25] node[pointred, midway] (zx){} (x)
(z) to[bend left=45]node[pointred, midway] (z1x1){} (x)
(x) to node[pointred, midway](x1t1){} (t)
(x) to[bend left=60] node[pointred, midway] (x2t2){} (t)
(x) to[bend right=60] node[pointred, midway] (xt){} (t);
% reds edges
\draw[thick, red] (x2t2) to[bend right = 60] (z1x1);
\end{tikzpicture}
\end{document}