\documentclass[a4paper,border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{math,calc,intersections,arrows.meta}
\tikzset{every picture/.style={samples=300,smooth,line join=round,thick,>=Stealth,font=\small}}
\begin{document}
\begin{tikzpicture}[scale=.45]
\tikzmath{\ai=2;\aii=-1;}
\draw[->](-2.5,0)--(3.5,0)node[below]{$x$};
\draw[->](0,-2)--(0,3.5)node[right]{$y$};
\coordinate[label=45:$O$](O)at(0,0);
\path[cyan,name path=fx,draw,domain=-2.5:2.5]plot(\x,{abs(\x)-1});
\path[blue,name path=gx,draw,domain=0.5:3.5]plot(\x,{\x*\x-2*\ai*\x+\ai+2});
\path[name intersections={of=fx and gx,by={[label=]A}}] let \p1=(A) in
\pgfextra
\xdef\xA{\x1/28.45274}\xdef\yA{\y1/28.45274}
\endpgfextra;
\draw[red,domain=-2.5:\xA]plot(\x,{abs(\x)-1});
\draw[red,domain=\xA:3.5]plot(\x,{\x*\x-2*\ai*\x+\ai+2});
\node[below]at(-1.2,0){$-1$};
\node[below]at(1,0){$1$};
\node[below]at(2,0){$2$};
\end{tikzpicture}
\end{document}
min.tex
我想得到的结果是上面图片中两个函数中最小者的图象。现在只会利用name intersections得到交点,再分段绘制图象,不知道有没有其它绘图思路,求助各位大神,谢谢!
可以直接用pgfplots
:
\documentclass[a4paper,border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
xmin=-3, xmax=5,
ymin=-2, ymax=5,
samples=300,
smooth,thick,
grid=major,
grid style={gray!30},
]
\addplot[cyan, dashed, domain=-3:5] {abs(x) - 1};
\addplot[violet, dotted, domain=-3:5] {(x-2)^2};
\addplot[red, ultra thick, domain=-3:5] {min(abs(x)-1, (x-2)^2)};
\end{axis}
\end{tikzpicture}
\end{document}
「函数图像」和「平面欧几里得图形」是不太一样的,应该选择最合适的工具。