我希望一点一点地揭开一条曲线(势能与距离),同时解释正在发生的事情。
下面的代码还可以,问题是曲线从幻灯片 3 到幻灯片 4 的形状发生了变化。我可以忍受它,并且不会因此而失眠太多;)但我想找到一个明显简单的解决方案。
我意识到这与我绘制曲线的方式有关。我将每张幻灯片上的曲线绘制为一条单独的曲线,只带有额外的坐标点。(每张幻灯片都给出了完整的曲线坐标,并注释掉了“额外的点”)。
理想情况下,我应该只揭示曲线的某些部分。
这些解决方案在 Beamer 中发现 TikZ 图的线段和在 Beamer 中发现 TikZ 路径的片段使用直线而不是曲线......
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{frame}{Real Gases}
\begin{tikzpicture}
\onslide<6->{\draw[green!20, pattern color =green!20, thin,pattern=north west lines] (0,-5) rectangle (2,2) node[rotate=90,midway,above] {\tiny{\textcolor{green!30!black}{repulsive forces dominant}}};}% drawn first so appear as underlay
\onslide<6->{\draw[red!0, pattern color =red!20, thin,pattern=north west lines] (2,-5) rectangle (10,2) node[midway,above] {\tiny{\textcolor{red!30!black}{attractive forces dominant}}};}
\onslide<1->{\draw[thick,->] (0,0) --(10,0) node[above left=0.2] {\tiny{Separation}};}
\onslide<1->{\draw[thick,->] (0,-5) --(0,2) node[rotate=90, near end,above] {\tiny{Potential Energy}};}
\onslide<2>{\draw[color=blue, thick,-] plot[smooth] coordinates{%(1.35,2)(1.4,1.75)(1.5,1.5) (2,0) (3,-3) (4,-5)(5,-4.5)(6,-2)(7,-0.8)
(8,-0.3)(9,-0.1) (10,0)};}
\onslide<3>{\draw[color=blue, thick,-] plot[smooth] coordinates{%(1.35,2)(1.4,1.75)(1.5,1.5)(2,0)(3,-3)
(4,-5)(5,-4.5)(6,-2)(7,-0.8)(8,-0.3)(9,-0.1) (10,0)};}
\onslide<4>{\draw[color=blue, thick,-] plot[smooth] coordinates{%(1.35,2)(1.4,1.75)(1.5,1.5)
(2,0) (3,-3) (4,-5)(5,-4.5)(6,-2)(7,-0.8)(8,-0.3)(9,-0.1) (10,0)};}
\onslide<5->{\draw[color=blue, thick,-] plot[smooth] coordinates{(1.35,2)(1.4,1.75)(1.5,1.5)(2,0) (3,-3) (4,-5)(5,-4.5)(6,-2)(7,-0.8)(8,-0.3)(9,-0.1) (10,0)};}
\end{tikzpicture}
\end{frame}
\end{document}
答案1
如果你愿意把流畅的剧情换成hobby
curve,那么您可以使用该包的一个功能来仅绘制曲线的一部分。简而言之,我希望能够计算曲线但只绘制部分曲线。所以我添加了一个blank
键,这意味着当前段未绘制。然而,它仍然用作曲线计算的一部分,这意味着无论是否绘制该段,曲线都是相同的。
通过blank
按正确的顺序将键应用于坐标,我可以按您的要求依次显示曲线的各个部分。在特定幻灯片上应用样式的机制来自马修·莱因冈的 回答到如何使用 Tikz 节点制作投影仪覆盖。
我尝试拟合曲线的基本概念。如果您需要更精确的拟合,则需要添加更多控制点。
\documentclass{beamer}
%\url{https://tex.stackexchange.com/q/116482/86}
\usepackage{tikz}
\usetikzlibrary{patterns,hobby}
\tikzset{
onslide/.code args={<#1>#2}{%
\only<#1>{\pgfkeysalso{#2}}%
},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}%
}
}
\begin{document}
\begin{frame}{Real Gases}
\begin{tikzpicture}
\draw<6->[green!20, pattern color =green!20, thin,pattern=north west lines] (0,-5) rectangle (2,2) node[rotate=90,midway,above,font=\tiny,text=green!30!black] {repulsive forces dominant};
% drawn first so appear as underlay
\draw<6->[red!0, pattern color =red!20, thin,pattern=north west lines] (2,-5) rectangle (10,2) node[midway,above,font=\tiny,text=red!30!black] {attractive forces dominant};
\draw[thick,->] (0,0) --(10,0) node[above left=0.2,font=\tiny] {Separation};
\draw[thick,->] (0,-5) --(0,2) node[rotate=90, near end,above,font=\tiny] {Potential Energy};
\draw<2->[color=blue, thick,-,use Hobby shortcut] ([out angle=-70]1.35,2) .. ([onslide=<-4>{blank}]2,0) .. ([onslide=<-3>{blank}]3,-4) .. ([onslide=<-3>{blank}]4,-5) .. ([onslide=<-2>{blank}]5,-4.5) .. ([onslide=<-2>{blank}]8,-0.3) .. ([in angle=180]10,0);
\end{tikzpicture}
\end{frame}
\end{document}
答案2
下一个代码展示了如何使用 Jake 的答案来如何为路径制作动画或如何绘制复杂但线性路径的起始部分?用你的例子。
因为此解决方案绘制的是路径的第一部分,所以我反转了您的坐标。主要问题是调整您想在每张幻灯片中绘制哪一部分。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations}
% A simple empty decoration, that is used to ignore the last bit of the path
\pgfdeclaredecoration{ignore}{final}
{
\state{final}{}
}
% Declare the actual decoration.
\pgfdeclaremetadecoration{middle}{initial}{
\state{initial}[
width={0pt},
next state=middle
]
{\decoration{moveto}}
\state{middle}[
width={\pgfdecorationsegmentlength*\pgfmetadecoratedpathlength},
next state=final
]
{\decoration{curveto}}
\state{final}
{\decoration{ignore}}
}
% Create a key for easy access to the decoration
\tikzset{middle segment/.style={decoration={middle},decorate, segment length=#1}}
\newcommand{\mypath}{(10,0)(9,-0.1)(8,-0.3)(7,-0.8)(6,-2)(5,-4.5)(4,-5)(3,-3)(2,0)(1.5,1.5)(1.4,1.75)(1.35,2)}
\begin{document}
\begin{frame}{Real Gases}
\begin{tikzpicture}
\onslide<6->{\draw[green!20, pattern color =green!20, thin,pattern=north west lines] (0,-5) rectangle (2,2) node[rotate=90,midway,above] {\tiny{\textcolor{green!30!black}{repulsive forces dominant}}};}% drawn first so appear as underlay
\onslide<6->{\draw[red!0, pattern color =red!20, thin,pattern=north west lines] (2,-5) rectangle (10,2) node[midway,above] {\tiny{\textcolor{red!30!black}{attractive forces dominant}}};}
\onslide<1->{\draw[thick,->] (0,0) --(10,0) node[above left=0.2] {\tiny{Separation}};}
\onslide<1->{\draw[thick,->] (0,-5) --(0,2) node[rotate=90, near end,above] {\tiny{Potential Energy}};}
\onslide<3>{\draw[middle segment=0.3,color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\onslide<4>{\draw[middle segment=0.6,color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\onslide<5>{\draw[middle segment=0.8,color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\onslide<6>{\draw[color=blue, thick,-] plot[smooth] coordinates{\mypath};}
\end{tikzpicture}
\end{frame}
\end{document}