tikz - 在曲线上指定更多控制

tikz - 在曲线上指定更多控制

我绘制了给定水体的温度曲线:

\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]}; 
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]};
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} 
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};} 
\draw (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0);
\end{tikzpicture}

从这里我想复制曲线,即深度温度增加 +2 摄氏度和 -2 摄氏度但水面保持不变的曲线。例如:

\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]};
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]};
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} 
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};}    
\draw (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0); 
\draw[dashed,red](8,-20) .. controls (8,-4)  and (17,-6) .. (17.5,0); 
\draw[dashed,blue] (4,-20) .. controls (4,-4)  and (17,-6) .. (17.5,0);
\end{tikzpicture}

这将生成两条额外的曲线,但问题是温度在整个剖面中并没有按指定的量相差,即在底部,线条之间的差异为 2 摄氏度,但在 10 米深度处,它们线性增加到 2 摄氏度。我意识到这个问题可能是由于使用的控制点数量造成的,但我似乎无法解决这个问题。

修正:工作示例

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc,shapes,arrows,snakes,shapes.geometric,patterns}

\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]}; % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]}; % draw yaxis
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};} % depth for graph

\draw (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0); % draw temperature profile i.e. curved line
\draw[dashed,red](8,-20) .. controls (8,-4)  and (17,-6) .. (17.5,0); % temp profile = 1degC
\draw[dashed,blue] (4,-20) .. controls (4,-4)  and (17,-6) .. (17.5,0); % draw new temperature profile
\end{tikzpicture}
\end{figure}
\end{document}

生产:

在此处输入图片描述

从这里,您可以看到,在较低的深度处,曲线之间的差异并不像指定的那样。我想生成一个图表,其中三条线在深度 = 0m 时相同,但此后它们相差 2 摄氏度。我该怎么做?

答案1

做到这一点的“简单”方法是用眼睛看。选择一个合理的猜测,然后反复修改,直到“看起来正确”,这对于绝对精确并不重要的一次性情况来说更简单。我在这里所做的是有效地在 -2m 深度点处分割弯曲路径,然后复制虚线图案中的下部,并将顶部弯曲以使其看起来不错。

我建议使用相对控制点,因为它可以使调整变得更容易,因为控制点会随着移动端点而移动。

\documentclass{article}
%\url{http://tex.stackexchange.com/q/99999/86}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] {Depth [m]};
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] {Temperature [$^{o}$C]};
\foreach \x in {0,4,10,20} { \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} 
\foreach \y in {0,-5,-10,-15,-20} { \draw(-2mm,\y)--(2mm,\y) node[left]{\y};}    
\draw[ultra thick,cyan] (6,-20) .. controls (6,-4)  and (17,-6) .. (17.5,0);
\draw (6,-20) .. controls (6,-6.3)  and (14,-6) .. (16.8,-2) .. controls +(.28,.4) and +(.05,-.6) .. (17.5,0) coordinate (a);
\draw[dashed,red,xshift=2cm] (6,-20) .. controls (6,-6.3)  and (14,-6) .. (16.8,-2) .. controls +(1.12,1.6) and +(.05,-.6) .. (a);
\draw[dashed,blue,xshift=-2cm] (6,-20) .. controls (6,-6.3)  and (14,-6) .. (16.8,-2) .. controls +(1.12,1.6) and +(.05,-.6) .. (a);

\end{tikzpicture}
\end{document}

我把原来的线保留为青色,以显示分割线非常接近它。

分割曲线

答案2

这是你想要的吗?

图形

我发现最简单的方法是使用 kewyword plot。为了获得正确的坐标,我在你的曲线上画了一个网格。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway] 
     {Depth [m]}; % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] 
     {Temperature [$^{o}$C]}; % draw yaxis
\foreach \x in {0,4,10,20} { 
    \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\foreach \y in {0,-5,-10,-15,-20} { 
    \draw(-2mm,\y)--(2mm,\y) node[left]{\y};} % depth for graph

\draw[black] plot[smooth,tension=.2]
  coordinates{(6,-20) (6.5,-15) (7,-13) (8,-10.6) (9,-9)
    (10,-7.8) (12, -6) (14,-4.6) (15,-3.8) (16,-3) (17,-1.8) (17.5,0)};
\draw[red, dashed] plot[smooth, tension=.2] coordinates
  { (8,-20) (8.5,-15) (9,-13) (10,-10.6) (11,-9)
    (12,-7.8) (14, -6) (16,-4) (17,-2.5) (17.5,0)};
\draw[blue, dashed] plot[smooth, tension=.2]
  coordinates{(4,-20) (4.5,-15) (5,-13) (6,-10.6) (7,-9)
    (8,-7.8) (10, -6) (12,-4.6) (13,-3.9) (14,-3.4) (15,-2.8) 
    (16,-2.3) (17, -1.4)    (17.5,0)
  };
\end{tikzpicture}
\end{document}

另一种解决方案是使用普通的贝塞尔曲线,但使用相对控制点(以及控制点的极坐标,相对于极点)。使用这种语法,我觉得更容易猜出结果:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[scale=0.3]
\draw [>=stealth, ->,thick](0,0) -- (0,-22) node[left = 7mm, midway]
     {Depth [m]}; % draw xaxis for the diagram
\draw [>=stealth, ->,thick](0,0) -- (22,0) node[above = 7mm, midway] 
     {Temperature [$^{o}$C]}; % draw yaxis
\foreach \x in {0,4,10,20} { 
    \draw(\x,-2mm)--(\x,2mm) node[above]{\x};} % temperatures for graph
\foreach \y in {0,-5,-10,-15,-20} { 
    \draw(-2mm,\y)--(2mm,\y) node[left]{\y};} % depth for graph

\draw[black]        (6,-20) .. controls +(90:15) and +(-110:8) .. (17.5,0);
\draw[blue,dashed]  (4,-20) .. controls +(90:16) and +(-120:8) .. (17.5,0);
\draw[red,dashed]   (8,-20) .. controls +(90:14) and +(-95:7) .. (17.5,0);
\end{tikzpicture}
\end{document}

这样曲线就平滑多了。我更喜欢这个结果:

贝塞尔

相关内容