考虑这里的最小不起作用的例子:
\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{
tangent/.style = {
in angle={(180+#1)},
Hobby finish,
designated Hobby path=next,
out angle=#1
}
}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\coordinate (y) at (0,3);
\coordinate (x) at (5,0);
\coordinate (sp0) at (1.5,0);
\coordinate (ep0) at (3.5,2);
\coordinate (csp0) at (2.5,1);
\coordinate (cep0) at (2.75,0);
\coordinate (sp1) at (ep0);
\coordinate (ep1) at (4.5,3);
\coordinate (csp1) at (4.25,4);
\coordinate (cep1) at (4.25,2);
\coordinate (sp2) at (sp0);
\coordinate (ep2) at (0,-1);
\coordinate (csp2) at (0.5,-1);
\coordinate (cep2) at (0.5,-1);
\draw[<->] (y) node[left] {$f(x)$} -- (0,0) -- (x) node[below] {$x$};
% Using \pgfmathanglebetweenpoints to calculate the angle for tangent
% tangent takes a degree unit angle
\pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
\let\angle=\pgfmathresult
\draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;
\draw[dashed] (cep0) -- (csp1);
\draw[dotted] let \p1 = (ep0) in (ep0) -- (0,\y1);
\draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1,0);
\draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
\draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
\draw let \p1 = (ep0) in (1pt,\y1) -- (-3pt,\y1) node [anchor=east] {$f(x_0)$};
\end{tikzpicture}
\caption{Newton's method in action: diagram drawn using the \texttt{hobby} package.}
\label{fig:newton_method_2}
\end{figure}
\end{document}
它产生如下输出:
但是,如果角度信息按我预期的那样工作,那么绘制的实线路径hobby
将与倾斜虚线相切。我尝试调整了一些内容,我的印象是“角度”信息影响的是相对于路径方向的路径,而不是某个标准坐标系(我预期 0 度在正 x 轴方向上,正角度表示与正 x 轴的逆时针偏差)?
我怎样才能让它按预期工作?或者,与我预期的相比,定义的切线函数如何工作?
答案1
该tangent
选项并非设计用于语法,因为它是为了修复语法没有的curve through
问题而编写的。该选项适用于快捷语法。问题是,如果想要用一条 Hobby 曲线跟踪另一条 Hobby 曲线,那么使用快捷语法很难发出信号,而使用变体则很难。该键的设计目的是使插入这样的中断变得容易。curve through
tangent
curve through
tangent
因此,您的代码可以与快捷代码一起使用:
\draw[use Hobby shortcut] (ep2) .. (sp0) .. ([tangent=\angle]ep0) .. (ep1) ;
curve through
如果我手动中断它也可以起作用:
\draw (ep2) to [curve through ={([out angle=\angle]sp0)}] (ep0);
除了曲线的第二部分(从(ep0)
到(ep1)
)没有中间点,并且curve through
不能很好地应对这一点。
因此我认为我推荐使用快捷语法来处理你正在做的事情。