Tikz:在切线坐标系中使用水平/垂直线操作

Tikz:在切线坐标系中使用水平/垂直线操作

这个问题是基于杰克的回答这里,并从那里修改示例代码。

我正在使用该markings库来获取切线坐标系,但想将其与|-坐标规范中的命令结合起来。对于 MWE,请考虑以下几点:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\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 [
    tangent=0.4,
    tangent=0.56
] (0,0)
    to [out=20,in=120] (5,2)
    to [out=-60, in=110] (9,1);
\path (6,4) coordinate (x);
\draw [orange, thick, use tangent=2] (-2,0) -- (2,0) (0,0 -| x) -- (x);
\end{tikzpicture}
\end{document}

原始代码有

\draw [orange, thick, use tangent=2] (-2,0) -- (2,0) (0,0) -- (0,1);

代替

\draw [orange, thick, use tangent=2] (-2,0) -- (2,0) (0,0 -| x) -- (x);

并获得了一个漂亮的橙色切线坐标系。在我的例子中,我希望正交线不位于中心,(0,0)而是位于侧面某处,以便它以(命名的)节点结束x。有没有办法调整,|-以便它也使用切线坐标系而不是原始坐标系?

在图片中,我当前的代码生成一条在原始坐标系中垂直的线: 我拥有的 我希望看到的是切线坐标系中的垂直线: 我想要的是

答案1

您的图像仍然在笛卡尔坐标系中。使用的解决方案仅允许绘制图形上选定点的切线。要绘制切线投影,您需要使用calc计算Z 库。

通过使用投影坐标定义在calc(有关详细信息,请参阅第 13.5.5 节投影修改器的语法,TiZ & PGF 手册 v 3.1.9a,第 151 页):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc, % <---
                decorations.markings}

\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 [
    tangent=0.4,
    tangent=0.56
] (0,0)
    to [out=20,in=120] (5,2)
    to [out=-60, in=110] (9,1);
\path (6,4) coordinate (x);
\draw [orange, thick, use tangent=2] (-2,0) coordinate (a) -- (2,0) coordinate (b); % <---
\draw [red, thick] (x) -- ($(a)!(x)!(b)$); % <---
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

您可以更改的定义use tangent以使用真正的旋转(使用calcTikZ 库和\anglebetween宏):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings}

\makeatletter
\def\anglebetween#1#2#3{%macro, s, t
  \path let
  \p{s}=(#2), \p{t}=(#3),
  \n{angle}={atan2(\y{t}-\y{s},\x{t}-\x{s})}
  in \pgfextra {
    \pgfmathsetmacro\temp{\n{angle}}
    \xdef#1{\temp}
  };
}
\makeatother

\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 (1cm,0pt);
        \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1cm);
      }
    },
    postaction=decorate
  },
  use tangent/.style={
    /utils/exec={\anglebetween{\tangentangle}{0,0}{$(tangent unit vector-#1)-(tangent point-#1)$}},
    shift=(tangent point-#1),
    rotate=\tangentangle,
  },
  use tangent/.default=1
  ]
  
  \draw [
  tangent=0.4,
  tangent=0.56
  ] (0,0)
  to [out=20,in=120] (5,2)
  to [out=-60, in=110] (9,1);
  
  \path (6,4) coordinate (x);
  \draw[use tangent=2,orange, thick](-2,0) -- (2,0) (0,0 -| x) -- (x);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容