沿曲线的归一化切向量

沿曲线的归一化切向量

我使用以下代码在曲线上的各个点添加切向量。我想对每个向量进行归一化,从而得到单位长度相等的切向量。我该如何实现这一点?

\documentclass[11pt]{article}   
\usepackage{tikz}       
 \usetikzlibrary{arrows}      
\begin{document}

 \begin{tikzpicture}[allow upside down,x=1.5cm,y=1.4cm]
    \draw[red,thick] (0,0)
    .. controls +(right:6cm) and +(left:4cm) .. (2,6)
    \foreach \p in {0,10,...,100} {
      node[sloped,inner sep=0cm,above,pos=\p*0.01,
      anchor=south west,
      minimum height=(10+\p)*0.03cm,minimum width=(10+\p)*0.03cm]
      (N \p){}
    }
    .. controls +(right:2cm) and +(right:3cm) .. (6,2)
    \foreach \p in {0,10,...,100} {
      node[sloped,inner sep=0cm,above,pos=\p*0.01,
      anchor=south west,
      minimum height=(110-\p)*0.03cm,minimum width=(110-\p)*0.03cm]
      (N2 \p){}
    }
    ;
    \foreach \p in {0,10,...,100} {
      \draw[-latex,color=black] (N \p.south west) -- (N \p.south east);
    }
    \foreach \p in {0,10,...,100} {
      \draw[-latex,color=black] (N2 \p.south west) -- (N2 \p.south east);
    }
  \end{tikzpicture}
 \end{document}

答案1

使用calctikz 库,语法

($A!1cm!B$)

1cm表示从A方向的一个点B。利用这个,我们可以轻松地将切向量表达式修改为

\foreach \p in {0,10,...,100} {
  \draw[-latex,color=black] (N \p.south west)
    -- ($(N \p.south west)!1cm!(N \p.south east)$);
  }
  \foreach \p in {0,10,...,100} {
  \draw[-latex,color=black] (N2 \p.south west)
    -- ($(N2 \p.south west)!1cm!(N2 \p.south east)$);
  }

产生

示例输出

\documentclass[11pt]{article}   
\usepackage{tikz}       
\usetikzlibrary{arrows,calc}      

\begin{document}

\begin{tikzpicture}[allow upside down,x=1.5cm,y=1.4cm]
  \draw[red,thick] (0,0)
  .. controls +(right:6cm) and +(left:4cm) .. (2,6)
  \foreach \p in {0,10,...,100} {
    node[sloped,inner sep=0cm,above,pos=\p*0.01,
    anchor=south west,
    minimum height=(10+\p)*0.03cm,minimum width=(10+\p)*0.03cm]
    (N \p){}
  }
  .. controls +(right:2cm) and +(right:3cm) .. (6,2)
  \foreach \p in {0,10,...,100} {
    node[sloped,inner sep=0cm,above,pos=\p*0.01,
    anchor=south west,
    minimum height=(110-\p)*0.03cm,minimum width=(110-\p)*0.03cm]
    (N2 \p){}
  }
  ;
  \foreach \p in {0,10,...,100} {
  \draw[-latex,color=black] (N \p.south west)
    -- ($(N \p.south west)!1cm!(N \p.south east)$);
  }
  \foreach \p in {0,10,...,100} {
  \draw[-latex,color=black] (N2 \p.south west)
    -- ($(N2 \p.south west)!1cm!(N2 \p.south east)$);
  }
\end{tikzpicture}


\end{document}

答案2

为了比较,这里有一个元帖子版本,其中定义路径、绘制路径和标记切线是分开完成的。

在此处输入图片描述

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);
u = 2cm;
% define the curve
path curve; 
curve = ( origin .. controls (6,0) and (-2,6)
        .. (2,6) .. controls (4,6) and (9,2) 
        .. (6,2) ) scaled u;

% draw it in pink
draw curve withpen pencircle scaled 1.44 withcolor .67[red,white];

% mark it with tangents at regular intervals
pair p, q;
A := arclength curve;
s := A/20;
for a = 0 step s until A+eps:
  t := arctime a of curve;
  p := point t of curve;
  q := p + 1/2u * unitvector(direction t of curve);
  drawarrow p -- q;
endfor

endfig;
end.

答案3

以下是通过库获取切线的另一种方法decorations.markings

在此处输入图片描述

\documentclass[tikz]{standalone}   
\usetikzlibrary{arrows,calc,decorations.markings}      
\begin{document}
\begin{tikzpicture}[x=1.5cm,y=1.4cm]
  \tikzset{
    draw tangents/.style={decorate,decoration={
        markings,mark=between positions 0 and 1 step .04 with
        {\draw[-latex,black,thin] (0,0) -- (1cm,0);},
      }
    }
  }
  \draw[red,thick,postaction=draw tangents]
  (0,0) .. controls +(right:6cm) and +(left:4cm) .. (2,6)
  .. controls +(right:2cm) and +(right:3cm) .. (6,2);
\end{tikzpicture}
\end{document}

相关内容