为什么程序只读取一个交点?解决方法是将其分成两部分,用不同长度的切线绘制。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usetikzlibrary{decorations.markings}
\begin{document}
\pgfkeys{tikz/.cd,
tangent length/.store in=\TangentLength,
tangent length=3.14cm,
normal length/.store in=\NormalLength,
normal length=7mm}
\newcounter{tangent}
\newcounter{normal}
\tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {\stepcounter{tangent}
\draw[tangent,name path=tangent-\thetangent] (-\TangentLength,0) --
(9cm,0);
\fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {\stepcounter{normal}
\draw[normal,name path=normal-\thenormal] (0,-\NormalLength) --
(0,\NormalLength);
\fill[normal] (0,0) circle (2pt);}}}},
}
\begin{tikzpicture}
% Axes
\draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
\draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
\node at (0,0) [below left] {$0$};
% Points
\coordinate (start) at (1,-0.8);
\coordinate (c1) at (3,3);
\coordinate (c2) at (5.5,1.5);
\coordinate (c3) at (8,4);
\coordinate (end) at (10.5,-0.8);
% show the points
% \foreach \n in {start,c1,c2,c3,end} \fill [black] (\n)
% circle (2pt) node [below] {};
% join the coordinates
\draw [name path=curve,thick,tangent at/.list={0.3,0.3},
normal at/.list={}] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
\fill[name intersections={of=curve and tangent-2,total=\t},cyan]
(intersection-\t) circle (2pt);
\fill[name intersections={of=curve and tangent-1,total=\t},cyan]
(intersection-\t) circle (2pt);
\end{tikzpcicture}
\end{document}
输出:
答案1
样式tangent at=<pos>
在位置处附加一条切线pos
。因此tangent at/.list={0.3,0.3}
只会创建两条相同的切线。但是,这与交点无关。相反,您想标记切线与曲线的最后两个交点。(Ti钾Z 找到更多的交点,因为切线当然非常接近曲线,所以一些额外的交点不是真正的交点,而是由于数值不准确造成的。)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usetikzlibrary{decorations.markings}
\begin{document}
\pgfkeys{tikz/.cd,
tangent length/.store in=\TangentLength,
tangent length=3.14cm,
normal length/.store in=\NormalLength,
normal length=7mm}
\newcounter{tangent}
\newcounter{normal}
\tikzset{tangent/.style={red,thin},normal/.style={blue,thin},
tangent at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {\stepcounter{tangent}
\draw[tangent,name path=tangent-\thetangent] (-\TangentLength,0) --
(9cm,0);
\fill[tangent] (0,0) circle (2pt);}}}},
normal at/.style={postaction={decorate,decoration={markings,
mark=at position #1 with {\stepcounter{normal}
\draw[normal,name path=normal-\thenormal] (0,-\NormalLength) --
(0,\NormalLength);
\fill[normal] (0,0) circle (2pt);}}}},
}
\begin{tikzpicture}
% Axes
\draw [-latex] (-1,0) -- (11,0) node [right] {$x$};
\draw [-latex] (0,-1) -- (0,6) node [above] {$y$};
% Origin
\node at (0,0) [below left] {$0$};
% Points
\coordinate (start) at (1,-0.8);
\coordinate (c1) at (3,3);
\coordinate (c2) at (5.5,1.5);
\coordinate (c3) at (8,4);
\coordinate (end) at (10.5,-0.8);
% show the points
% \foreach \n in {start,c1,c2,c3,end} \fill [black] (\n)
% circle (2pt) node [below] {};
% join the coordinates
\draw [name path=curve,thick,tangent at=0.3] (start) to[out=70,in=180] (c1) to[out=0,in=180]
(c2) to[out=0,in=180] (c3) to[out=0,in=150] (end);
\fill[name intersections={of=curve and tangent-1,total=\t},cyan]
\pgfextra{\pgfmathtruncatemacro{\prevt}{\t-1}}
foreach \i in {\prevt,\t} {(intersection-\i) circle (2pt)};
\end{tikzpicture}
\end{document}
答案2
使用tzplot:
\documentclass{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}
\tzhelplines(-1,-1)(11,6)
\tzaxes(-1,-1)(11,6){$x$}{$y$}
\tzshoworigin
\tzcoors(1,-0.8)(start) (3,3)(c1) (5.5,1.5)(c2) (8,4)(c3) (10.5,-0.8)(end) ;
\tztos[thick]"curve"(start)[out=70,in=180]
(c1)[out=0,in=180]
(c2)[out=0,in=180]
(c3)[out=0,in=150]
(end) ;
\tztangentat[red]"tan"{curve}{3.53}[1:11]
\tzXpoint{curve}{tan}(X)
\tzdot*[red](X)
\tzdot*[red](X-5) % trial and error
\end{tikzpicture}
\end{document}