[Tex/LaTex] How to draw the trefoil knot in 3D co-ordinates in Latex using these parametric equations

3dasymptotedrawtikz-pgf

When I use the parametric equations (according to Wikipedia) to plot a trefoil knot:

x(t)=sint+2sin2t

y(t)=cost−2cos2t

z(t)=−sin3t

I get a plot that looks very different from the nice plot on Wolfram Alpha.

trefoil from WA

This is my code:

\begin{tikzpicture}
\begin{axis}
\addplot3[variable=t,mesh,domain=-2*pi:2*pi] ({sin(deg(t))+2*sin(deg(2*t))},{cos(deg(t))-2*cos(deg(2*t))}, {-1*sin(deg(3*t))});
\end{axis}
\end{tikzpicture}

How can I create a nice plot of a trefoil knot? Thank you!

Best Answer

I think that the key here is to put more samples. This is your code, with 100 samples. I changed the domain too, from 0 to 2pi, because yours draws everything twice. I also added a view more alike to the plot in WA that you linked.

\documentclass[border=2mm]{standalone}
\usepackage {pgfplots}
\pgfplotsset{compat=1.17}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[view={30}{55}]
  \addplot3[red,variable=t,samples=100,domain=0:2*pi]
    ({sin(deg(t))+2*sin(deg(2*t))},{cos(deg(t))-2*cos(deg(2*t))}, {-sin(deg(3*t))});
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Related Question