Tikz 3D - Twisted Cubic

Tags: Algebraic Geometry , Curves , LaTeX , Tikz

(Español: Tikz 3D - La "curva cúbica torcida" (twisted cubic))

As Joe Harris mentions in his book “Algebraic Geometry: A First Course”, the Twisted Cubic is “everybody’s first example of a concrete variety that is not a hypersurface, linear space, or finite set of points.”

In affine space, it is given by the image of $$t\mapsto(t,t^2,t^3).$$

As I was working through all the exercises in the book (I still am!) I decided that I wanted to make a Tikz picture for it (to learn to do 3D figures in Tikz).

A couple of days later I ended up with the following code, which I am really proud of! I am becoming a huge Tikz fan.

What I really enjoy about the code is how easy it is to read: each block serves a specific purpose, and even if one does not know the details of $\LaTeX$, or the TikZ package, it is easy to guess what is happening.

\documentclass[border=0pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\begin{axis}%
[ scale=0.8
, view={235}{15} % {rotation angle}{elevation angle}
, xlabel=$x$
, ylabel=$y$
, zlabel=$z$
, zmin=-8
, zmax=8
]

% Parabola and cubic shadow curves
\addplot3%
[ samples=40
, samples y=0
, thick 
, cyan 
, domain=-2:2
, variable=\t
] ({t},{t^2},{-8});

\addplot3%
[ samples=40
, samples y=0
, thick
, red 
, domain=-2:2
, variable=\t
] ({t},{-1},{t^3});

%  Lines
%  (pgfplots cannot handle a \foreach commands inside the {axis} environment, so the draw commands need to have the foreach inside of them. See also pgfplotsinvokeforeach._

\draw [cyan] foreach \a in {-2,-1.9,...,2} {
({\a}, {(\a)^2}, {(\a)^3}) --  ({\a}, {(\a)^2}, -8)
};

\draw [red] foreach \a in {-2,-1.9,...,2} {
({\a}, {(\a)^2}, {(\a)^3}) -- ({\a}, -1, {(\a)^3})
};

% Twisted cubic
\addplot3%
[ samples=51
, samples y=0
, thick
, black 
, domain=-2:2
, variable=\t
] ({t},{t^2},{t^3});

\end{axis}
\end{tikzpicture}
\end{document}

And of course, I also enjoy the very pretty figure the code creates!

Twisted Cubic

Note that if one calls the 3D coordinates $(x,y,z)$, then the shadow in the $(x,y)$ plane of the twisted cubic is the parabola $y=x^2$: $$t\mapsto(x,y)=(t,t^2).$$ This parabola is clearly visible in the figure (on purpose!).

The same happens with the shadow on the $(x,z)$ plane which is the cubic curve $z=x^3$.

Back to the code, this is a piece I really like, it is almost like plain English!

\draw [cyan] foreach \a in {-2,-1.9,...,2} {
({\a}, {(\a)^2}, {(\a)^3}) --  ({\a}, {(\a)^2}, -8)
};

It says “Draw, in cyan color, for each a between -2 and 2 in steps of 0.1, the line (…) — (…) between the points.” Those are the vertical blue lines in the figure!

Subscribe

Want to get an email when a new post is added? If so, subscribe here.