tikzcd 라인의 단일 웨이브

Jan 10 2021

효과적으로 늘어난 물결표 인 tikzcd에서 화살표 형식을 만들려고합니다.

이 답변 에서 옵션 1을 사용하여이 예제를 그렸지만 뱀의 올바른 세그먼트 길이를 수동으로 계산해야했습니다.

이것을 자동으로 계산하는 방법이 있습니까? 예를 들어 :

arrows={decorate, decoration={snake, segment length=DISTANCE/2, amplitude=0.5mm}}

그렇지 않은 경우 다른 방법이 있습니까?

어떤 도움이라도 대단히 감사하겠습니다.

답변

2 Dave Jan 11 2021 at 04:03

이 답변을 기반으로 부분적인 솔루션 이 있습니다.

스타일 정의의 전반부 대부분과 함께 도우미 매크로 전체를 복사했습니다. 내가 담당하는 유일한 코드는 "Draw the wave"주석 아래에 있습니다.

\makeatletter

% This helper macro finds the start and endpoints of a line between the source and target nodes and stores them in \sourcecoordinate and \targetcoordinate.
% #1 -- source node
% #2 -- target node
\def\findedgesourcetarget#1#2{
\let\sourcecoordinate\pgfutil@empty
\ifx\tikzcd@startanchor\pgfutil@empty % Check that the source doesn't have a specified anchor
    \def\tempa{\pgfpointanchor{#1}{center}}% if so, start by taking the center of that coordinate
\else
    \edef\tempa{\noexpand\pgfpointanchor{#1}{\expandafter\@gobble\tikzcd@startanchor}} % If it has an anchor, use that
    \let\sourcecoordinate\tempa
\fi
\ifx\tikzcd@endanchor\pgfutil@empty % check that the target doesn't have a specified anchor
    \def\tempb{\pgfpointshapeborder{#2}{\tempa}}% if so, our end point is the point on the boundary of node b that is in the direction of our initial start coordinate
\else
    \edef\tempb{\noexpand\pgfpointanchor{#2}{\expandafter\@gobble\tikzcd@endanchor}}% If it has a specified anchor, use that
\fi
\let\targetcoordinate\tempb
\ifx\sourcecoordinate\pgfutil@empty%
    \def\sourcecoordinate{\pgfpointshapeborder{#1}{\tempb}}%
\fi
}

\tikzset{wave/.style = {
-,
to path={\pgfextra{
        \findedgesourcetarget{\tikzcd@ar@start}{\tikzcd@ar@target} % find endpoints
    % Rotate coordinate system so that line goes in x direction
    \ifx\tikzcd@startanchor\pgfutil@empty
        \def\tikzcd@startanchor{.center}
    \fi
    \ifx\tikzcd@endanchor\pgfutil@empty
        \def\tikzcd@endanchor{.center}
    \fi
    \pgfmathanglebetweenpoints{\pgfpointanchor{\tikzcd@ar@start}{\expandafter\@gobble\tikzcd@startanchor}}{\pgfpointanchor{\tikzcd@ar@target}{\expandafter\@gobble\tikzcd@endanchor}}
    \pgftransformrotate{\pgfmathresult}
    % Draw the wave
    \newdimen\xdiff
    \pgfextractx{\xdiff}{\pgfpointdiff{\sourcecoordinate}{\targetcoordinate}}
    \newdimen\ydiff
    \pgfextracty{\ydiff}{\pgfpointdiff{\sourcecoordinate}{\targetcoordinate}}
    \newdimen\finalDist
    \pgfmathparse{abs(veclen(\xdiff,\ydiff))*0.85}
    \pgfmathsetlength\finalDist{\pgfmathresult pt}

    \pgfmathsetlength\pgfdecorationsegmentlength{\finalDist}

    \pgfmathparse{0.038*\finalDist+0.6}
    \pgfmathsetlength\pgfdecorationsegmentamplitude{\pgfmathresult pt}

    \pgfsetarrows{->}

    \pgfpathmoveto{\sourcecoordinate}
    \pgfpathsnaketo{snake}{\targetcoordinate}

    \pgfusepath{stroke}
}}}}

\makeatother

도우미 매크로를 사용하여 결합 할 점을 검색하고 그 사이의 거리를 계산합니다. 그런 다음 이것을 사용하여 뱀의 진폭과 세그먼트 길이를 정의합니다.

이 정의에서 사용하는 상수는 임의적으로 보이며 시행과 개선을 통해 찾았지만 더 엄격한 접근 방식을 사용합니다.


그때

\begin{center}
    Original method:
    \begin{tikzcd}[arrows={decorate, decoration={snake,segment length=7.3mm, amplitude=0.5mm}}]
        A \arrow[r,"",decorate=true] & B
    \end{tikzcd}
\end{center}
\hspace{2cm}
\begin{center}
    Custom style
    \begin{tikzcd}
        A \arrow[r, wave] & B & & \\
        A \arrow[rr, wave] & & B & \\
        A \arrow[rrr, wave] & & & B
    \end{tikzcd}
\end{center}

준다


내 주요 문제는 현재 화살표 위의 레이블이 더 이상 작동하지 않는다는 것입니다. 이 문제를 해결하고 가능한 경우이 답변을 업데이트하겠습니다.

누구든지 그러한 문제를 피하는 더 간단한 접근 방식을 가지고 있다면 알려주십시오!