2

I want to plot the graph of a function (say a sine) on a curve, that is to say, plot the graph above a straight line then distort it into a given curve.

Here's a minimal example :

\documentclass[pstricks,border=12pt]{standalone}  
\usepackage[left=4.0cm,right=4.0cm,top=4.0cm,bottom=4.0cm]{geometry}  
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{pgfplots}
\usepackage{caption}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{xcolor}
\usetikzlibrary{arrows}
%
%
\begin{document}
%
%
%
\begin{figure}[!h]
\centering
\captionsetup{justification=centering,margin=2cm}
\begin{tikzpicture}[scale=1.0]
%
\draw[](-4,0)--(4,0);
%
\draw [red, thick] plot [pattern = vertical lines, rotate  = 0, domain = -4:4, samples = 120] (\x,{0.5*sin(\x*180)});
%
\begin{scope} [shift={(0.0,0.0)}]
\draw [blue, thick] plot [rotate  = 0.0, domain = -4.0:4.0, samples = 80] (\x,{-1.65*(\x*\x-16)/16});
\end{scope}
%
\end{tikzpicture}
\caption{\label{Name}Bla bla...}
\end{figure}
%
%
%
\end{document}

I first plot a horizontal straight line then plot a sine function above it (observe here that the pattern function does not work ; what am I doing wrong here ?). Then, I would like to plot say the same sine function but "above" the blue curve, as if the graph was following the blue curve.

Nicolas
  • 311

1 Answers1

2

I guess this has to go in iterations. The pattern does not appear because you added it to the options of the plot, and not the path. But then I have a hard time parsing the remaining instructions. Could you perhaps try to rephrase them, or provide a sketch?

\documentclass{article}  
\usepackage[left=4.0cm,right=4.0cm,top=4.0cm,bottom=4.0cm]{geometry}  
\usepackage{tikz}
\usetikzlibrary{patterns}
% \usepackage{pgfplots}
% \pgfplotsset{compat=1.16}
\usepackage{caption}
\usetikzlibrary{arrows}
%
%
\begin{document}
%
\begin{figure}[!h]
\centering
\captionsetup{justification=centering,margin=2cm}
\begin{tikzpicture}[scale=1.0]
%
\draw[](-4,0)--(4,0);
%
\path[pattern = vertical lines] plot [domain = -4:4, samples = 120] (\x,{0.5*sin(\x*180)})
-- plot [domain = 4:-4, samples = 80] (\x,{-1.65*(\x*\x-16)/16+0.5*sin(\x*180)})
-- cycle;
\draw[red, thick] plot [domain=-4:4,samples=120] (\x,{0.5*sin(\x*180)});
%
\draw [blue, thick] 
plot [domain=-4:4,samples=80] (\x,{-1.65*(\x*\x-16)/16+0.5*sin(\x*180)});
%
\end{tikzpicture}
\caption{\label{Name}Bla bla...}
\end{figure}
%
%
%
\end{document}

enter image description here

  • Thank you for your answer. The remaining problem is to plot the sine function with domain the blue line. In fact, I would like to do the same thing as what you've done so far, that is to plot the graph of the sine function with pattern following the horizontal black line, but now with the blue curve instead of the black straight line. The graph has to "follow" the curve in the sense that it has to be "curved" itself, to be bent along the blue path (as the text is bent in the first answer here : https://tex.stackexchange.com/questions/22314/tikz-bend-text-so-that-it-follows-a-line) – Nicolas Apr 28 '19 at 07:13
  • @Nicolas I added something but am not sure if that's what you want. Please note that one could think of using a decoration here, e.g. decoration={coil,aspect=0} which comes with \usetikzlibrary{decorations.pathmorphing} but this does not look good out of the box. There are also the complete sines with which one may play. –  Apr 28 '19 at 12:50
  • This is almost what I'm looking for. The problem here is that if I add the pattern command with vertical lines, then the lines will touch the horizontal line y=0. Instead, I would like them to be bounded by the distorted sine graph and the original blue curve. Ideally, the lines also follow the blue curve in the sense that the orientation changes as we range over the blue path (it starts north west oriented, then progressively moves to vertically oriented and ends north east oriented). – Nicolas Apr 28 '19 at 13:07
  • @Nicolas I made another update. (This can also be done with the pgfplots library fillbetween but in this case this does not bring real advantages IMHO.) –  Apr 28 '19 at 16:07
  • It is not exactly what I wanted (I wanted the vertical lines to be between the blue curve and the "curved" sine). But the modification is really easy to carry out. Many thanks anyway, you've helped me a lot ! – Nicolas Apr 28 '19 at 16:41