之前有人回答过关于两条画线之间的间距的问题,但我发现他们的答案无法适用于我,也不知道剪辑如何工作,也不知道我需要将它们改成什么。为了写这份报告,我实际上使用了 latex,所以我知道它不会完美。
我正在尝试填充两个抛物线之间的空间,使其看起来像水流入容器。任何帮助都值得感激 :)
\documentclass[10pt, twocolumn]{revtex4}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
% water
\fill [ fill = cyan!40 ] (0, 1.75) -- (0, 0) -- (2, 0) -- (2, 1.75) (2, .45) -- (2, .55) -- (2.5, .55) -- (2.5, .45);
\draw [domain = 2.5:3.2, samples=50] plot (\x, {-2*(\x-2.5)^2+.45});
\draw [domain = 2.5:3.3, samples=50] plot (\x, {-2*(\x-2.5)^2+.55});
% box, tube
\draw [thick] (2,.45) -- (2,0) -- (0,0) -- (0,2) (2, 2) -- (2, .55);
\draw [thick] (1.5, .45) -- (2.5, .45) (1.5, .55) -- (2.5, .55);
% height information
\draw[dashed] (1.5, .45) -- (0, .45);
\draw (-.25, .45) -- (0, .45) (-.25, 1.75) -- (0, 1.75);
\draw (-.125, .45) -- (-.125, .9) node[above] {$h$} (-.125, 1.3) -- (-.125, 1.75);
% stand
\draw [thick] (.5, 0) -- (1.5, -.5) (.5, -.5) -- (1.5, 0);
\draw (.4, -.5) -- (1.6, -.5) -- (1.6, -.55) -- (.4, -.55);
\fill [ fill=gray ] (.4, -.5) -- (1.6, -.5) -- (1.6, -.55) -- (.4, -.55);
% jug
\fill [ fill=cyan!50 ] (2.7, -.5) -- (2.7, -.8) -- (3.7, -.8) -- (3.7, -.5);
\draw (2.7, .2) -- (2.7, -.8) -- (3.7, -.8) -- (3.7, .2);
\end{tikzpicture}
\end{document}
答案1
\documentclass[10pt, twocolumn]{revtex4}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
% water
\fill [ fill = cyan!40 ] (0, 1.75) -- (0, 0) -- (2, 0) -- (2, 1.75) (2, .45) -- (2, .55) -- (2.5, .55) -- (2.5, .45);
\fill[ fill = cyan!40 ] plot[domain = 2.45:3.25, samples=50] (\x, {-2*(\x-2.5)^2+.45}) --
plot[domain = 3.2:2.45, samples=50] (\x, {-2*(\x-2.5)^2+.55});
% box, tube
\draw [thick] (2,.45) -- (2,0) -- (0,0) -- (0,2) (2, 2) -- (2, .55);
\draw [thick] (1.5, .45) -- (2.5, .45) (1.5, .55) -- (2.5, .55);
% height information
\draw[dashed] (1.5, .45) -- (0, .45);
\draw (-.25, .45) -- (0, .45) (-.25, 1.75) -- (0, 1.75);
\draw (-.125, .45) -- (-.125, .9) node[above] {$h$} (-.125, 1.3) -- (-.125, 1.75);
% stand
\draw [thick] (.5, 0) -- (1.5, -.5) (.5, -.5) -- (1.5, 0);
\draw (.4, -.5) -- (1.6, -.5) -- (1.6, -.55) -- (.4, -.55);
\fill [ fill=gray ] (.4, -.5) -- (1.6, -.5) -- (1.6, -.55) -- (.4, -.55);
% jug
\fill [ fill=cyan!40 ] (2.7, -.5) -- (2.7, -.8) -- (3.7, -.8) -- (3.7, -.5);
\draw (2.7, .2) -- (2.7, -.8) -- (3.7, -.8) -- (3.7, .2);
\end{tikzpicture}
\end{document}
答案2
像这样?
% <---
代码和建议的解决方案之间的差异通过以下简短描述来表示:
\documentclass[10pt, twocolumn]{revtex4}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
% water
\fill [ fill = cyan!40 ] (0, 1.75) -- (0, 0) -- (2, 0) -- (2, 1.75) (2, .45) -- (2, .55) -- (2.5, .55) -- (2.5, .45);
\path [name path=A, domain = 2.5:3.2, samples=50] plot (\x, {-2*(\x-2.5)^2+.45}); % <-- added name
\path [name path=B, domain = 2.5:3.3, samples=50] plot (\x, {-2*(\x-2.5)^2+.55}); % <-- added
\tikzfillbetween[of=A and B]{cyan!50}; % <-- added fill between paths A and B
% box, tube
\draw [thick] (2,.45) -- (2,0) -- (0,0) -- (0,2) (2, 2) -- (2, .55);
\draw [thick] (1.5, .45) -- (2.5, .45) (1.5, .55) -- (2.5, .55);
% height information
\draw[dashed] (1.5, .45) -- (0, .45);
\draw (-.25, .45) -- (0, .45) (-.25, 1.75) -- (0, 1.75);
\draw (-.125, .45) -- (-.125, .9) node[above] {$h$} (-.125, 1.3) -- (-.125, 1.75);
% stand
\draw [thick] (.5, 0) -- (1.5, -.5) (.5, -.5) -- (1.5, 0);
\draw (.4, -.5) -- (1.6, -.5) -- (1.6, -.55) -- (.4, -.55);
\fill [ fill=gray ] (.4, -.5) -- (1.6, -.5) -- (1.6, -.55) -- (.4, -.55);
% jug
\fill [ fill=cyan!50 ] (2.7, -.5) -- (2.7, -.8) -- (3.7, -.8) -- (3.7, -.5);
\draw (2.7, .2) -- (2.7, -.8) -- (3.7, -.8) -- (3.7, .2);
\end{tikzpicture}