2

I'm trying to draw a sine in xy plan, fill it with some color, and draw some arrows (dirac) to show it can be considered as a vector. I tried this but the reference of the arrows is 0 and not the x axis and the triangle marker does not rotation depending the sign of y. The fill option is not working either.

\documentclass[crop]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}  
\usepackage[french]{babel}

\begin{document}
\begin{tikzpicture}
[x={(0.866cm,-0.5cm)}, y={(0.866cm,0.5cm)}, z={(0cm,1cm)},
 >=stealth, 
 inner sep=0pt, outer sep=2pt,
 axis/.style={thick,->},
 wave/.style={thick,color=#1,smooth}
]

\coordinate (O) at (0,0,0);
\draw[axis] (O) -- +(12,0,0) node [right] {x};
\draw[axis] (O) -- +(0,2,0) node [right] {y};
\draw[axis] (O) -- +(0,0,2) node [above] {z};

\draw[wave=blue, variable=\x,samples at={0,0.25,...,10}]
plot (\x,{sin(2*\x r)},0)node[anchor=north]{$\vec{E}$};

\draw[ycomb,mark=triangle,variable=\x,samples at={0,0.25,...,10}] plot (\x,        {sin(2*\x r)},0);

\end{tikzpicture}
\end{document}

Here is the result : Dirac problem Fill problem

So several problems but I believe you will help me out.

Thanks !

PS : I've also tried in scope env. but that's not better...

2
  • Not sure about what you want to fix. Do you want the arrow tips to follow the line? What else?
    – Alenanno
    Dec 2, 2015 at 16:04
  • Draw the Diracs in the good plan with x axis reference, with a good orientation of the triangle markers and fix the fill problem. Both problems are connected I guess.
    – rhum187
    Dec 2, 2015 at 16:12

1 Answer 1

1

You can draw the vectors with the following code:

\foreach \x in {0,0.25,...,10}
   \draw[->] (\x,0,0) -- (\x,{sin(2*\x r)},0);

If you want, you can change the arrow tips and use any of those defined by tikz (see the chapter "Arrow Tip Library" of the manual).

The full code and the output:

\documentclass[crop]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}  
%\usepackage[french]{babel}

\begin{document}
\begin{tikzpicture}
[x={(0.866cm,-0.5cm)}, y={(0.866cm,0.5cm)}, z={(0cm,1cm)},
 >=stealth, 
 inner sep=0pt, outer sep=2pt,
 axis/.style={thick,->},
 wave/.style={thick,color=#1,smooth}
]

\coordinate (O) at (0,0,0);
\draw[axis] (O) -- +(12,0,0) node [right] {x};
\draw[axis] (O) -- +(0,2,0) node [right] {y};
\draw[axis] (O) -- +(0,0,2) node [above] {z};

\draw[wave=blue, variable=\x,samples at={0,0.25,...,10}]
plot (\x,{sin(2*\x r)},0)node[anchor=north]{$\vec{E}$};

\foreach \x in {0,0.25,...,10}
  \draw[->] (\x,0,0) -- (\x,{sin(2*\x r)},0);

\end{tikzpicture}
\end{document}

output

3
  • Wow !!! Awesome !!! That's elegant and quite obvious... now... Any idea for the fill problem ?
    – rhum187
    Dec 2, 2015 at 16:17
  • 1
    I don't know a proper solution. Looking at you output it seems that the area filled is between the curve and the segment that connects the initial ad final points. You could get a "correct" filling if both points fall on the x axis, by choosing the final x value as multiple of half the wavelength.
    – LucaD
    Dec 2, 2015 at 16:27
  • Thanks LucaD ! It woks well anyway by setting a multiple of pi and by decreasing the sampling !
    – rhum187
    Dec 2, 2015 at 16:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .