[Tex/LaTex] tikz – specifying more controls on curved lines

tikz-pgf

Im drawing a temperature profile for a given body of water:

\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}

From here I would like to copy the profile i.e. the curved line where the temperature at depth is increased as +2 degC and -2degC but where the surface of the water remains the same. For example:

\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}

This will generate two additional curved lines, the problem here is that the temperatures do not differ by the amount specified all the way down the profile i.e. the difference between the lines are 2degC at the bottom but up to a depth of 10 m they linearly increase to 2degC. I realise this problem is probably due to the number of control points used, but I can't seem to solve the problem.

amended: working example

\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}

producing:

enter image description here

From here, you can see that at the lowe depths the difference between the curves lines is not as specified. I would like to generate the graph where the three lines are the same at depth = 0m but thereafter they vary by 2degC. How could I do this?

Best Answer

The "easy" way of doing this is to do it by eye. Picking a reasonable guess and then messing around with it until it "looks right" is simpler for one-off situations where being absolutely precise isn't important. What I've done here is to effectively split the curved path at the -2m depth point, then copied the lower parts in the dashed patterns and curved the tops to look okay.

I would recommend using relative control points as it makes adjusting things much easier since then the control points move as you move the end points.

\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}

I've left the original line there in cyan to show that the split line is pretty close to it.

split curves