I want to draw a sine wave below an image. Following is the code I tried:
\documentclass{article}
\usepackage{graphicx,tikz}
\tikzset{
% Tikz style used to work in relative coordinates to the underlying picture
% From https://tex.stackexchange.com/a/445311/141947
use bounding box relative coordinates/.style={
shift={(current bounding box.south west)},
x={(current bounding box.south east)},
y={(current bounding box.north west)}
},
}
\begin{document}
\begin{figure}[htp!]
\centering
\begin{tikzpicture}
% Import picture and select it as bounding box
\node[use as bounding box]{\includegraphics[width = 0.4\linewidth]{Figure.png}};
\begin{scope}[use bounding box relative coordinates]
\draw[red, domain = 0.128:0.961] plot [smooth] (\x,{0.1 * sin(\x * pi/0.5 r)});
% Grid lines
% \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
% \foreach \x in {0,1,...,9} { \node [anchor=south] at (\x/10,0) {0.\x}; }
% \foreach \y in {0,1,...,9} { \node [anchor=west] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
The output is:
As apparent from the image, I am not able to get one complete cycle of the sine wave. I tried different with inputs for the draw command i.e.,
\draw[red, domain = 0.128:0.961] plot [smooth] (\x,{0.1 * sin(\x * pi/0.5 r)});
Desired output
I want to plot one complete cycle of sine wave between x = 0.0
and x = 1.0
in the image. Also, I want to shift this sine wave to y = -0.1
. Is this possible? The image without the sine wave can be found here.
Furthermore, is there any function in TikZ
that takes the wavelength
and amplitude
as input and produces a sine
wave? If yes, this will be very helpful as it provides a general solution.
r
in{0.1 * sin(\x * pi/0.5 r)}
?r
I am not completely sure. I think it stands for radians. That line of code is borrowed from here.