如何获取路径装饰的切线坐标系?

如何获取路径装饰的切线坐标系?

我想在路径装饰的切线坐标系中绘制一些线条。特别是我想在装饰的末端绘制一条切线段,并完全控制该段,即以该段的起点和终点作为坐标。

我尝试了以下内容(改编自如何在 TikZ 中绘制路径上任意点的切线):

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings,decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[tangent/.style={
        decoration={
            markings,% switch on markings
            mark=
                at position #1
                with
                {
                    \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
                    \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
                    \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
                }
        },
        postaction=decorate
    },
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
        y=(tangent orthogonal unit vector-#1)
    },
    use tangent/.default=1]     


    \draw[decorate,tangent=0,decoration={coil,amplitude=20,segment length=20,post length=0}] (0,0) coordinate (X) -- ++(5,5);

 \node[below] at (X) {$x$};
 %want a tangent line at (X) with start end end coordinates 
 \draw[use tangent] (0,0) -- ++(1,0);



\end{tikzpicture}
\end{document}

但是我收到一个错误:

ERROR: Package pgf Error: No shape named tangent unit vector-1 is known.

不完整图片的输出:

输出

知道如何实现这一点吗?我想应该有更简单的方法来实现它。

答案1

我认为不能在同一路径上同时使用两种装饰。

更具体地说你的问题:

\tikzset{%
tangent/.style args={#1 at #2}{%
    decoration={%
    markings,% switch on markings
    % can not not work at 0 exactly for obvious resons 
    mark=at position #2 with {#1}},
    postaction={decorate}
    }
}

还有切线本身,或者任何你想要的东西:

\draw[use path=bob,tangent={%
    {
    % what ever you want, as if you were in a scope
    \draw[blue,thick,->,>=stealth] (0,0)--(1,0) ;
    } at .0001}] ;
\node[below] at (X) {$x$};
\end{tikzpicture}

在此处输入图片描述

在此处输入图片描述

\documentclass[tikz]{standalone}
\usepackage[active,tightpage]{preview}

\usetikzlibrary{decorations.markings,decorations.pathmorphing,intersections}

    %%%%                        ---- Use path several times
    %%%%                        ---- thanks to Andrew Stacey
    \makeatletter
    \tikzset{
      use path for main/.code={%
        \tikz@addmode{%
          \expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
        }%
      },
      use path for actions/.code={%
        \expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
      },
      use path/.style={%
        use path for main=#1,
        use path for actions=#1,
      }
    }


\tikzset{%
tangent/.style args={#1 per #2 at #3}{%
    decoration={%
    markings,% switch on markings
    % can not not work at 0 exactly for obvious resons 
    mark=at position #3 with {\draw[red] (#2,0)--(0,0)--(0,#1) ;}
                },
    postaction={decorate}
    }
}


\begin{document}

\foreach \x in {0.0001,.01,0.02,...,1} {%
\begin{preview}
\begin{tikzpicture}

\draw (-1.5,-.5) rectangle (5.5,5.5) ;

\path [decorate,decoration={coil,amplitude=20,segment length=20,post length=0},name path=bob]   (0,0) coordinate (X) -- ++(5,5);

\draw[use path=bob,tangent={.5 per .7 at \x}] ;
\node[below] at (X) {$x$};
\end{tikzpicture}
\end{preview}}

\end{document}

相关内容