Tikz:从弯曲圆弧上的点沿垂直于弯曲圆弧切线的方向写一条线

Tikz:从弯曲圆弧上的点沿垂直于弯曲圆弧切线的方向写一条线

我正在尝试注释图形的弯曲弧。弯曲弧应该与注释文本有链接。此外,链接应该垂直于弯曲弧的切线。

下面是一个尝试执行此操作的代码示例,但必须修改以下行

($(midp-\i)$) -- +(0.33cm,0.33cm) node[above]

此代码是根据以下问题的答案改编的: tikz:如何将列表作为 tikz 宏的参数传递并在宏内的 foreach 中使用它自循环上的锚点(从该锚点画一条线)

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}

% #1: list of nodes label, #2: list of arcs annotation
\def\graphcircuit#1#2{
\foreach[count=\n] \v in {#1}; % count the number of elements
\pgfmathsetmacro{\r}{\n*0.2} % set the node distance from (0,0)
\pgfmathsetmacro{\b}{90/\n} % evaluate the bend angle
\foreach[count=\i, evaluate=\i as \a using (\i-1)*360/\n] \v in {#1} % write nodes
    \node [circle, draw, font=\scriptsize] (n-\i) at (\a:\r) {$\v$};
\foreach \i [remember=\i as \j (initially \n)] in {1,...,\n} % write arcs and create anchor points
    \path[->,bend right=\b] (n-\j) edge coordinate[pos=0.5] (midp-\j) (n-\i);
\foreach[count=\i] \annotation in {#2} % write annotations on each arc
    \path[draw=black!80,line width=0.6pt,dotted] ($(midp-\i)$) -- +(0.33cm,0.33cm) node[above] {\scriptsize\annotation};
}

\begin{tikzpicture}
\graphcircuit{1:5,7:2,3:0,4:0,9:1}{a,b,c,d,f}
\end{tikzpicture}

\end{document}

答案1

也许使用pin? 可能需要进行一些调整,但应该给出基本思想:

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{calc}

\begin{document}
  \def\graphcircuit#1#2{%
    \foreach [count=\n] \v in {#1}; % count the number of elements
    \pgfmathsetmacro {\r} {\n*0.2} % set the node distance from (0,0)
    \pgfmathsetmacro {\b} {90/\n} % evaluate the bend angle
    \pgfmathsetmacro {\p} {360/\n}
    \foreach [count=\i, evaluate=\i as \a using (\i-1)*360/\n] \v in {#1} % write nodes
      \node [circle, draw, font=\scriptsize] (n-\i) at (\a:\r) {$\v$};
    \foreach \i [remember=\i as \j (initially \n)] in {1,...,\n} % write arcs and create anchor points
      \path [->,bend right=\b] (n-\j) edge coordinate [pos=0.5] (midp-\j) (n-\i);
    \foreach [count=\i] \annotation in {#2} % write annotations on each arc
    \node [pin={[pin edge={draw=black!80,line width=0.6pt,dotted}, font=\scriptsize]\i*\p-.5*\p:\annotation}] at ($(midp-\i)$) {};
  }%
  \begin{tikzpicture}
    \graphcircuit{1:5,7:2,3:0,4:0,9:1}{a,b,c,d,f}
  \end{tikzpicture}
\end{document}

别针

相关内容