我有一条在区间 [0,1] 上的抛物线图和一条在 (1,0) 和 (1,1) 之间的线段。我想将抛物线和 x 轴之间以及该垂直线段左侧的区域涂成黄色。我该怎么做?
我还在 (0, 3/4) 和 (sqrt(3/4), 3/4) 之间画了一条线段。我还想将抛物线和 y 轴之间以及该水平线段下方的区域涂成橙色。
如果不能仅使用来完成此操作TikZ
,那么如何在“轴”环境中执行相同操作?
我很好奇,为什么我需要加载“交叉点”包才能编译该图的代码?
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{center}
\begin{tikzpicture}[x=10cm, y=5cm]
\path[fill=yellow!50] (0,0) -- (1,0) -- (1,1) -- (0,0) -- cycle;
\path[draw=black, name path=parabola, domain = 0:1, variable=\x] plot ({\x}, {\x*\x});
\draw[-latex] (0,0) -- (1.25,0) node[anchor=north west, font=\normalsize]{$x$};
\draw[-latex] (0,0) -- (0,1.25) node[anchor=south west, font=\normalsize]{$y$};
\coordinate (A) at (1,1);
\coordinate (B) at ({sqrt(0.75)},0.75);
\draw[name path=vertical_line_through_A] (1,0) -- (A);
\node[anchor=north, inner sep=0, yshift=-0.15cm, font=\normalsize] at (1,0){$a$};
\draw[name path=horizontal_line_through_B] (0,0.75) -- (B);
\node[anchor=east, inner sep=0, xshift=-0.15cm, font=\normalsize] at (0,0.75){$b$};
\end{tikzpicture}
\end{center}
\end{document}
答案1
您可以使用简单的 TikZ 内置parabola
命令绘制抛物线。此命令描绘一条从指定起点开始、经过指定控制点、并结束于指定终点的抛物线。基本语法为:
\draw (starting point) parabola (ending point);
这是你的最终代码:
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}[x=10cm, y=5cm]
\coordinate (A) at (1,1);
\coordinate (B) at ({sqrt(0.75)},0.75);
\filldraw[fill=orange] (0,0) parabola (B) -- (0,0.75);
\filldraw[fill=yellow!50] (0,0) parabola (1,1) -- (1,0) -- cycle;
\draw[name path=name path=vertical_line_through_A] (1,0) -- (A);
\draw[name path=horizontal_line_through_B] (0,0.75) -- (B);
\begin{scope}[font=\normalsize]
\draw[-latex] (0,0) -- (1.25,0) node[anchor=north west]{$x$};
\draw[-latex] (0,0) -- (0,1.25) node[anchor=south west]{$y$};
\node[anchor=north, inner sep=0, yshift=-0.15cm] at (1,0){$a$};
\node[anchor=east, inner sep=0, xshift=-0.15cm] at (0,0.75){$b$};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
像这样:
代码:
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{center}
\begin{tikzpicture}[x=10cm, y=5cm]
\foreach \x in {0,.01,...,1}
\draw[yellow,line width=2pt] (\x,\x*\x)--(\x,0);
\foreach \x in {0,.01,...,.866}
\draw[orange,line width=2pt] (\x,.75)--(\x,\x*\x);
\path[draw=black, name path=parabola, domain = 0:1, variable=\x] plot ({\x}, {\x*\x});
\draw[-latex] (0,0) -- (1.25,0) node[anchor=north west, font=\normalsize]{$x$};
\draw[-latex] (0,0) -- (0,1.25) node[anchor=south west, font=\normalsize]{$y$};
\coordinate (A) at (1,1);
\coordinate (B) at ({sqrt(0.75)},0.75);
\draw[name path=vertical_line_through_A] (1,0) -- (A);
\node[anchor=north, inner sep=0, yshift=-0.15cm, font=\normalsize] at (1,0){$a$};
\draw[name path=horizontal_line_through_B] (0,0.75) -- (B);
\node[anchor=east, inner sep=0, xshift=-0.15cm, font=\normalsize] at (0,0.75){$b$};
\end{tikzpicture}
\end{center}
\end{document}
编辑:简化代码(输出相同)
\documentclass{amsart}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[x=10cm, y=5cm]
\foreach \x in {0,.01,...,1}
\draw[yellow,line width=2pt] (\x,\x*\x)--(\x,0);
\foreach \x in {0,.01,...,.866}
\draw[orange,line width=2pt] (\x,.75)--(\x,\x*\x);
\path[draw=black,domain = 0:1] plot ({\x}, {\x*\x});
\draw[-latex] (0,0) -- (1.25,0) node[anchor=north west, font=\normalsize]{$x$};
\draw[-latex] (0,0) -- (0,1.25) node[anchor=south west, font=\normalsize]{$y$};
\coordinate (A) at (1,1);
\coordinate (B) at ({sqrt(0.75)},0.75);
\draw (1,0) -- (A);
\node[anchor=north, inner sep=0, yshift=-0.15cm, font=\normalsize] at (1,0){$a$};
\draw (0,0.75) -- (B);
\node[anchor=east, inner sep=0, xshift=-0.15cm, font=\normalsize] at (0,0.75){$b$};
\end{tikzpicture}
\end{center}
\end{document}