Example: Rose rhodonea curve

Published 2009-11-17 | Author: Manuel Kirsch

An example for creating plots with foreach and pgfpointxy. It solves an equation for the parameters d from 1 to 6 an n from 1 to 9. There is still a bug in the formula which only strikes when \d > 5. Increasing the number \n from 9 to 10 runs MiKTeX out of memory.

Download as: [PDF] [TEX]  •  [Open in writeLaTeX]

Rose rhodonea curve

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

% Rose rhodonea curve
% Author: Manuel Kirsch
\documentclass [12pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes}

\title{Rose-rhodonea-curve}
\author{Manuel Kirsch}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}
    \draw (-1, 1) node{$_n\backslash^d$};
    \foreach \d in {1, 2, ..., 6} {
        \draw (2.5 * \d - 2, 1) node{\d};
    }
    \foreach \n in {1, 2, ..., 9} {
    \draw (-1, -2.5 * \n + 2) node{\n};
        \foreach \d in {1, 2, ..., 6} { 
            \fill[black!10!white] (2.5 * \d - 2, -2.5 * \n + 2) circle (1cm);
    \ifnum\n=\d
        \draw (2.5 * \d - 2, -2.5 * \n + 2) circle (0.5cm);
    \else
        \pgfplothandlerlineto
        \pgfplotfunction{\x}{0, \d, ..., 180\d}{
            \pgfpointxy     
            {2.5 * \d + cos(\x) * sin(\n / \d * \x) - 2}
            {-2.5 * \n + sin(\x) * sin(\n / \d * \x) + 2}
        }
    \pgfusepath{stroke}
    \fi
        }
    }
    \draw (7,-25.5) node [rounded rectangle, draw]
        {$r = \sin\left(\frac{\Theta \cdot n}{d}\right)$};
\end{tikzpicture}
\end{document}

Comments

  • #1 azetina, March 4, 2012 at 9:57 p.m.

    Is this related in any way to spirograph-like curves? And if so, how can one recreate them in TikZ?

  • #2 Georges DupĂ©ron, September 4, 2012 at 1:47 p.m.

    @azetina, see this TeX.SX question : http://tex.stackexchange.com/q/36352/5699

Adding comments is currently not enabled.