0

I am rather new to Tikz, and I could not find this anywhere online. How would one draw this rather complex figure meant to show a wave?

enter image description here

I only know how to create points and connect them with straight lines. I do not know how to make a curved line like the wave above shows, I do not know how to put labels in all the places shown in the figure and how to rotate them like with the y1 and y2, I do not know how to fill the area in blue, and I do not know how to color the top arch green. I really have no idea where to get started on this, nor do I know if Tikz can even produce such a figure. I thank all helpers and would appreciate all help on this.

Edit: here is what I have so far and also where I am stuck

\begin{tikzpicture}[scale=2.25]
\coordinate (A) at (0cm,2cm);
\coordinate (B) at (0cm,0cm);
\coordinate (C) at (2cm,0cm);
\coordinate (D) at (2cm,2cm);
\draw (A) -- (B) -- (C) -- (D);

\end{tikzpicture}

  • 2
    Please show us what you try so far. (in form (of Minimal (not) Working Example). – Zarko Apr 13 '22 at 03:36
  • 2
    You may want to read the TikZ manual if you haven't. – user202729 Apr 13 '22 at 03:41
  • @user202729 thank you, I have, but I could not figure out how to apply it to my figure. I tried to put labels but I have failed at it –  Apr 13 '22 at 03:43
  • 2
    Searching for existing posts e.g. https://tex.stackexchange.com/questions/115554/how-to-rotate-a-tikz-label is okay too, but generally they tend to be quite complex, so stick with the manual and/or look up what each option in the answer does with the manual and pick only the useful ones may be easier – user202729 Apr 13 '22 at 03:43
  • @Zarko thank you, please see edit –  Apr 13 '22 at 03:43
  • 1
  • 1
    You can add text to the figure right? (although you may have to manually specify the coordinate instead of let it automatically computed which might look less neat) – user202729 Apr 13 '22 at 03:44
  • @user202729 is there an analogy to MS paint's bucket function where you can choose a point inside a closed contour, and then the entire region enclosed by the contour is colored/filled? –  Apr 13 '22 at 04:19
  • 1
    @kroner Unfortunately as far as I can see, TikZ (built-in) isn't that smart. https://tex.stackexchange.com/questions/326096/how-to-fill-region-defined-by-several-smooth-plot-tikz / https://tex.stackexchange.com/questions/68462/filling-a-complex-region-with-tikz just does it more-or-less manually. – user202729 Apr 13 '22 at 06:37

1 Answers1

4

You can make curves with Bezier curves and you can add labels when you use nodes. I only started learning Tikz yesterday myself, but I made the following, so I'm sure you'll also be able to catch on quick;

\documentclass{article}

\usepackage{tikz} \definecolor{water}{rgb}{0,1,1}

\begin{document}

\begin{tikzpicture} \draw[fill=water] (0,1) .. controls (1,1.5) and (2,1.5) .. (3,1) -- (3,0) -- (0,0) -- (0,1) node at (1.5,0.8)[]{g(x)} node at (1.5,1.6)[]{f(x)}; \draw (0,0) -- (0,2); \draw (3,0) -- (3,2); \end{tikzpicture}

\end{document}

Which generates:

enter image description here

EDIT: To change the colour of just the curve, I'd define the curve in a separate \draw command.

\begin{tikzpicture}
\draw[fill=water, color=water] (0,1) .. controls (1,1.5) and (2,1.5) .. (3,1) -- (3,0) -- (0,0) -- (0,1) 
node at (1.5,0.8)[black] {g(x)} 
node at (1.5,1.6)[black]{f(x)};
\draw[color=green] (0,1) .. controls (1,1.5) and (2,1.5) .. (3,1);
\draw[black] (3,0) -- (0,0) -- (0,2);
\draw (3,0) -- (3,2);
\end{tikzpicture}
arara
  • 776