3

I am trying to draw a plane with the front edge having a sine wave.

Using the code from this example I can draw it by something like

\documentclass{standalone}

\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}

\tdplotsetmaincoords{70}{70}
\begin{tikzpicture}[scale=3,tdplot_main_coords]
    \filldraw[draw=red,fill=red!20
    ]          (0,0,-0.5)
            -- (0,1,-0.5)
            -- (0,1,1)
            -- (0,0,1)
            -- (0,{0.1*sin(deg(4*pi*0.975)},0.975)
            -- ...lots more points....
            -- (0,{0.1*sin(deg(4*pi*-0.475)},-0.475)
            -- cycle;
    \draw[thick,->] (0,-0.2,0) -- (0,1.2,0) node[anchor=north west]{$x$};
    \draw[thick,->] (0,0,-0.5) -- (0,0,1.2) node[anchor=south]{$z$};
    \draw[thick,->] (-0.5,0,0) -- (1.2,0,0) node[anchor=north east]{$y$};
\end{tikzpicture}

\end{document}

where I specify all the points on the sine curve manually. There must be a better way of doing this, for example something like

--[domain=1:-0.5] (0,{0.1*sin(deg(4*pi*x)},x)

I've attached my results so far doing it manually. I want to be able to vary the sine wave which is why I want a better way of doing it.

enter image description here

2

You almost got it. See the code:

\documentclass[tikz, border=5mm]{standalone}

\usepackage{tikz-3dplot}

\tdplotsetmaincoords{70}{70}

\begin{document}
  \begin{tikzpicture}[tdplot_main_coords]
    \draw [red, fill=red!20, domain=-.5:1, samples=100] plot (0,{.1*sin(deg(4*pi*\x))},\x) -- (0,1,1) -- (0,1,-.5) -- cycle;

    \begin{scope}[->, shorten >= 2mm]
        \draw (-.5,0,0) -- (2,0,0) node {$y$};
        \draw (0,-.5,0) -- (0,2,0) node {$x$};
        \draw (0,0,-.5) -- (0,0,2) node {$z$};
    \end{scope}
  \end{tikzpicture}
\end{document}

rendered image

2

It's easier if you use an actual function instead of drawing it manually step by step.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}

\tdplotsetmaincoords{70}{70}
\begin{tikzpicture}[scale=3,tdplot_main_coords]

\fill[draw=red, fill=red!20, variable=\z,domain=-.5:1,samples=200] 
    (0,0,-.5) plot (0,{sin(\z*pi r*4)/10},\z)
    -- (0,1,1)
    -- (0,1,-0.5)
    -- cycle;

\draw[thick,->] (0,-0.2,0) -- (0,1.2,0) node[anchor=north west]{$x$};
\draw[thick,->] (0,0,-0.5) -- (0,0,1.2) node[anchor=south]{$z$};
\draw[thick,->] (-0.5,0,0) -- (1.2,0,0) node[anchor=north east]{$y$};
\end{tikzpicture}
\end{document}
  • Thank you very much, that works just as well as the other answer. I marked the other one as correct because the code was slightly clearer. – OmniJames Jan 21 '16 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.