Chapter 12 – Drawing Smooth Curves

[xyz-ips snippet=”intro”]

[xyz-ips snippet=”img1″]12/01[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.1 – A sample curve without coordinates or parameters[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[axis lines=none]
    \addplot [domain=-3:3, smooth, thick] { x^3 - 5*x };
  \end{axis}
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/02[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.2 – A curve with a grid[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \draw[domain=-3:3,samples=50,color=gray!50,thick] plot (\x, \x^3/5 - \x);
  \draw[very thin,gray,step=.2] (-3,-3) grid (3,3);
  \draw[step=1] (-3,-3) grid (3,3);
  \draw[->] (-3,0) -- (3,0) node[right] {x};
  \draw[->] (0,-3) -- (0,3) node[above] {y};
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/03[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.3 – Manually selected points on a curve[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \draw[domain=-3:3,samples=50,color=gray!50,thick] plot (\x, \x^3/5 - \x);
  \draw[very thin,gray,step=.2] (-3,-3) grid (3,3);
  \draw[step=1] (-3,-3) grid (3,3);
  \draw[->] (-3,0) -- (3,0) node[right] {x};
  \draw[->] (0,-3) -- (0,3) node[above] {y};
  \foreach \x/\y in {-3/-2.4, -2/0.4, -0.4/0.4, 0.4/-0.4, 2/-0.4, 3/2.4}
    \fill (\x,\y) circle (0.6mm);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/04[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.4 – A smooth path through points[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \draw[domain=-3:3,samples=50,color=gray!50,thick] plot (\x, \x^3/5 - \x);
  \foreach \x/\y in { -3/-2.4, -2/0.4, -0.4/0.4,
    0.4/-0.4, 2/-0.4, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw (-3,-2.4) to[out=77,in=240] (-2,0.4)
    to[out=60,in=135, looseness=1.2] (-0.4,0.4) to[out=-45,in=135] (0.4,-0.4)
    to[out=-45,in=-120,looseness=1.2] (2,-0.4) to[out=60,in=257] (3,2.4);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/05[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.5 – A plot through given coordinates[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \draw[domain=-3:3,samples=50,color=gray!50,thick] plot (\x, \x^3/5 - \x);
  \foreach \x/\y in { -3/-2.4, -2/0.4, -0.4/0.4,
    0.4/-0.4, 2/-0.4, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw plot coordinates {
    (-3,-2.4) (-2,0.4) (-1.3,0.86) (-0.4,0.4)
    (0.4,-0.4) (1.3,-0.86) (2,-0.4) (3,2.4) };
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/06[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.6 – A smoothened plot through the given coordinates[xyz-ips snippet=”fig2″]

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \draw[domain=-3:3,samples=50,color=gray!50,thick] plot (\x, \x^3/5 - \x);
  \foreach \x/\y in { -3/-2.4, -2/0.4, -0.4/0.4,
    0.4/-0.4, 2/-0.4, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw plot[smooth] coordinates {
    (-3,-2.4) (-2,0.4) (-1.3,0.86) (-0.4,0.4)
    (0.4,-0.4) (1.3,-0.86) (2,-0.4) (3,2.4) };
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/07[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.7 – A Bézier curve with control points[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
  \foreach \x/\y in { -3/-2.4, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw[thick] (-3,-2.4) .. controls +(77:9) and +(257:9) .. (3,2.4);
  \draw[help lines] (-3,-2.4) -- (-1,6.4) node[right] {P};
  \draw[help lines] (3,2.4) -- (1,-6.4) node[right] {Q};
  \draw[help lines] (-1,6.4) -- (1,-6.4);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/08[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.8 – A curve with Bézier splines[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{spline}
\begin{document}
\begin{tikzpicture}
%  \draw[thin,dotted] (-3,-3) grid (3,3);
%  \draw[->] (-3,0) -- (3,0);
%  \draw[->] (0,-3) -- (0,3);
  %\draw[domain=-3:3,samples=50,color=gray!50,thick] plot (\x, \x^3/5 - \x);
  \foreach \x/\y in { -3/-2.4, -1.3/0.86,
    1.3/-0.86, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
%  \coordinate (A) at (-3,-2.4);
%  \coordinate (B) at (-1.3,0.86);
%  \coordinate (C) at (1.3,-0.86);
%  \coordinate (D) at (3,2.4);
  \draw[thick] (-3,-2.4) to[spline coordinates=S, spline through={(-1.3,0.86)(1.3,-0.86)}] (3,2.4);
  \foreach \i [evaluate=\i as \j using \i+1] in {1,2,...,\tikzsplinesegments} {
    \draw[thin]  (S K-\i) -- (S P-\i)
                      (S K-\j) -- (S Q-\i);
    \fill[gray!50,semithick] (S P-\i) circle (0.6mm);
    \fill[gray!50,semithick] (S Q-\i) circle (0.6mm);
  }
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/09[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.9 – A Hobby curve[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
  \foreach \x/\y in { -3/-2.4, -1.3/0.86,
    1.3/-0.86, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw plot[hobby,thick] coordinates { (-3,-2.4) (-1.3,0.86) (1.3,-0.86) (3,2.4)};
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/10[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.10 – A closed smooth curve[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
  \foreach \x/\y in { -3/-2.4, -1.3/0.86,
    1.3/-0.86, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw (-3,-2.4) to[closed, curve through = {(-1.3,0.86) (1.3,-0.86)}] (3,2.4);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/11[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.11 – A curve with a specific start and end angle[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
  \foreach \x/\y in { -3/-2.4, -1.3/0.86,
    1.3/-0.86, 3/2.4 }
      \fill (\x,\y) circle (0.6mm);
  \draw (-3,-2.4) to[out angle=80, in angle=260,
    curve through = {(-1.3,0.86) (1.3,-0.86)}] (3,2.4);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/12[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.12 – Points on the plane[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
  \draw[step=1,thin,dotted] (-3,-3) grid (3,3);
  \draw[->] (-3,0) -- (3,0) node[right] {x};
  \draw[->] (0,-3) -- (0,3) node[above] {y};
  \foreach \c in {(0,0),(-1,-2),(-2,-1),(-1,0),
    (-1,2),(0,1),(2,1)} \fill \c circle (0.5mm);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”img1″]12/13[xyz-ips snippet=”img2″]

[xyz-ips snippet=”fig1″]Figure 12.13 – A very smooth curve through points on the plane[xyz-ips snippet=”fig2″]

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}
  \draw[step=1,thin,dotted] (-3,-3) grid (3,3);
  \draw[->] (-3,0) -- (3,0) node[right] {x};
  \draw[->] (0,-3) -- (0,3) node[above] {y};
  \foreach \c in {(0,0),(-1,-2),(-2,-1),(-1,0),
    (-1,2),(0,1),(2,1)} \fill \c circle (0.5mm);
  \draw[thick, fill=gray] (0,0) to[closed, curve through =
    { (-1,-2) (-2,-1) (-1,0) (-1,2) (0,1) }] (2,1);
\end{tikzpicture}
\end{document}

[xyz-ips snippet=”chapter1″]13[xyz-ips snippet=”chapter2″]