我需要在一个固定点上画一条椭圆曲线的切线,这是曲线和点的代码,我不知道如何绘制切线。
\begin{tikzpicture}
\begin{axis}[
xmin=-4,
xmax=5,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
domain=-2.279018:3,
samples=201,
smooth,
clip=false,
% use same unit vectors on the axis
axis equal image=true,
]
\addplot[blue] {sqrt(x^3-3*x+5)} node[right] {$E$};
\addplot[blue] {-sqrt(x^3-3*x+5)};
\begin{scriptsize}
%== P ==
\draw [fill=black] (-1.2,2.6) circle (2pt);
\draw[color=black] (-1.4,2.7) node [left]{$P$};
\end{scriptsize}
\end{axis}
\end{tikzpicture}
答案1
一种方法是使用计算机代数系统计算导数,然后绘制线条。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-4,
xmax=5,
ymin=-5,
ymax=5,
xlabel={$x$},
ylabel={$y$},
scale only axis,
axis lines=middle,
domain=-2.279018:3,
samples=201,
smooth,
clip=false,
% use same unit vectors on the axis
axis equal image=true,
]
\addplot[blue] {sqrt(x^3-3*x+5)} node[right] {$E$};
\addplot[blue] {-sqrt(x^3-3*x+5)};
\addplot[red] {2.621+0.251*(x+1.2)};
%\begin{scriptsize}
%== P ==
\draw [fill=black] (axis cs:-1.2,2.6) circle (2pt);
\draw[color=black] (axis cs:-1.4,2.7) node [left]{$P$};
%\end{scriptsize}
\end{axis}
\end{tikzpicture}
\end{document}
答案2
你可以通过节点携带衍生信息
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-4,xmax=5,
ymin=-5,ymax=5,
xlabel={$x$},ylabel={$y$},
scale only axis, axis lines=middle,
domain=-2.279018:3,
samples=201,smooth,clip=false,
axis equal image=true
]
\addplot[blue] {sqrt(x^3-3*x+5)} node[right] {$E$}
node[sloped,fill=black,circle,inner sep=1pt,pos=0.27,label={[absolute]180:$P$}] (a) {};
\draw ($(a.west)!-2cm!(a.east)$) -- ($(a.west)!2cm!(a.east)$);
\addplot[blue] {-sqrt(x^3-3*x+5)};
\end{axis}
\end{tikzpicture}
\end{document}
如果你用pos
调性演奏,切线也会随之移动。但请记住
\begin{scriptize}...\end{scriptsize}
在 TikZ 环境中没有效果。
答案3
用 MetaPost 来实现这一点的方法,可能会有人感兴趣。MetaPost 能够利用其direction
宏计算出给定点上的路径切线。
集成在LuaLaTeX程序中,方便排版。
\documentclass[12pt, border=3mm]{standalone}
\usepackage{luatex85, luamplib}
\mplibnumbersystem{double}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
% Macro creating a function graph
vardef function(expr xmin, xmax, xstep)(text f_x) =
save x; x := xmin;
(x, f_x) forever: hide(x := x + xstep) exitif x > xmax; .. (x, f_x) endfor
if x - xstep < xmax: hide(x := xmax) .. (x, f_x) fi
enddef;
vardef f(expr x) = sqrt(x**3 - 3x + 5) enddef;
u = cm; xmin = -4; xmax = 5; xstep = .1; ymax = -ymin = 5; root = -2.279018;
path curve; curve = function(root, 3, xstep)(f(x));
% Tangent computation
beginfig(1);
draw (reverse curve reflectedabout (origin, (1, 0)) .. curve) scaled u withcolor red;
x = -1.2; y = f(x); label.top("$P$", z*u);
pair v; v = 2.5unitvector direction (x-root)/xstep of curve;
drawdot z*u withpen pencircle scaled 3bp;
draw (z - v -- z + v) scaled u withcolor blue;
draw ((x, 0) -- z) scaled u dashed evenly;
label.bot("$" & decimal x & "$", (x*u, 0)); label.lrt("$O$", origin);
drawarrow (xmin*u, 0) -- (xmax*u, 0); label.bot("$x$", (xmax*u, 0));
drawarrow (0, ymin*u) -- (0, ymax*u); label.lft("$y$", (0, ymax*u));
endfig;
\end{mplibcode}
\end{document}
答案4
采用 PSTricks 的首选解决方案。
\documentclass[pstricks]{standalone}
\usepackage{pstricks-add}
\newcommand\f{t|sqrt(t^3-3*t+5)}
\newcommand\g{t|-sqrt(t^3-3*t+5)}
\begin{document}
\begin{pspicture}[algebraic,plotpoints=150](-5.5,-5.5)(5.5,5.5)
\psaxes{->}(0,0)(-5,-5)(5,5)[$x$,0][$y$,90]
\psparametricplot[linecolor=cyan,linewidth=2pt]{-2.279}{3}{\f}
\psparametricplot[linecolor=cyan,linewidth=2pt]{-2.279}{3}{\g}
\psplotTangent[linecolor=red,linewidth=2pt]{-1.2}{3}{\f}
\curvepnode{-1.2}{\f}{P}
\multido{\i=-40+15}{4}{\rput(P){\pcline[nodesepB=-3,linecolor=green](3;\i)(0,0)}}
\pscircle*[linecolor=blue](P){2pt}
\end{pspicture}
\end{document}