12

I am trying to make a 3D plot with TikZ, as shown in the picture, but I was not able to do it.

enter image description here

I have an example of my Latex code

\documentclass{article}

\usepackage[a4paper,top=2cm,bottom=2cm,
left=15mm,right=15mm,marginparwidth=1.75cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}

\begin{document}

\begin{tikzpicture}
\begin{axis} [ticklabel style = {font = \scriptsize},grid]
\addplot3 [%
domain=-2:4,
samples=250,
samples y=0, line width=1pt]
{exp(-2*(x-1.25)*(x-1.25))*cos((x-1.25)*1140)};
\end{axis}
\end{tikzpicture}

\end{document}

If anyone has an idea and solutions on how to draw the required diagram, I would be very grateful.

1 Answer 1

19

This could be a starting point. It uses 3d and perspective TikZ libraries, and I'm 'reconstructin your function (hope is the right one).

\documentclass[tikz,border=1.616mm]{standalone}
\usetikzlibrary{3d,perspective}

\begin{document}
\begin{tikzpicture}[3d view={120}{30},domain=-1:3.5,samples=1001]
\draw[canvas is xz plane at y=-1] (-2,-2) rectangle (2,2);
\draw[canvas is yz plane at x=-2] (-1,-2) rectangle (3.5,2);
\draw[canvas is xy plane at z=-2] (-2,-1) rectangle (2,3.5);
\draw[blue] plot ({exp(-2*(\x-1.25)*(\x-1.25))*cos((\x-1.25)*1140)},\x,{exp(-2*(\x-1.25)*(\x-1.25))*sin((\x-1.25)*1140)});
\draw[red]  plot ({exp(-2*(\x-1.25)*(\x-1.25))*cos((\x-1.25)*1140)},\x,-2);
\draw       plot (-2,\x,{exp(-2*(\x-1.25)*(\x-1.25))*sin((\x-1.25)*1140)});
\end{tikzpicture}
\end{document}

enter image description here

Update: another version using a \pic for the function and its projections.

\documentclass[tikz,border=1.616mm]{standalone}
\usetikzlibrary{3d,perspective}

\tikzset
{%
   pics/spiral/.style 2 args={code=%
   {
      \draw[pic actions] plot[domain=#1:#2,samples=1001]
        ({exp(-2*\x*\x)*cos(1140*\x)},\x,
         {exp(-2*\x*\x)*sin(1140*\x)});
   }},
}

\begin{document}
\begin{tikzpicture}[3d view={120}{30},line cap=round,line join=round]
\draw[canvas is xy plane at z=-2] (-2,-3) rectangle (2,3);
\draw[canvas is xz plane at y=-3] (-2,-2) rectangle (2,2);
\draw[canvas is yz plane at x=-2] (-3,-2) rectangle (3,2);
\begin{scope}[shift={(0,-3,0)}]
  \pic[teal,y=0] {spiral={-3}{3}};
\end{scope}
\pic [red           ,canvas is xy plane at z=-2] {spiral={-3}{3}};
\pic [green!50!black,canvas is zy plane at x=-2] {spiral={-3}{3}};
\pic [blue,thick]                                {spiral={-3}{3}};
\end{tikzpicture}
\end{document}

enter image description here

3
  • 1
    Finally, I get to ask you this question: do you know of any projection computing ability in TikZ? I mean, you had to draw red and black via a function (const, x,y) and (z,const, y). is there a package/library that can compute the projection of blue function on the XY plane? I am aware that this is a big stretch and there are many tools that are better fit for the task.
    – anis
    May 30 at 14:18
  • 1
    @anis, not exactly, but your comment gave me an idea using scopes and 3d library. See my edit May 30 at 19:18
  • 1
    that's actually what I thought of. hats off
    – anis
    May 30 at 20:12

You must log in to answer this question.

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