56

One of my last questions talked about certificates and I got great answers. Now my questions is, can one recreate a guilloche in TikZ like the one shown below:enter image description here

or may be a border like

enter image description here

azetina
  • 28,884
  • 1
    Maybe this will help? http://tex.stackexchange.com/questions/41159/does-anybody-know-a-good-source-of-free-ornaments-decorations-frames-backgr – mbork Mar 02 '12 at 15:19
  • 1
    And/or http://tex.stackexchange.com/questions/36352/spirograph-continuous-rotations-in-tikz-or-pstricks ? – Ben Lerner Mar 02 '12 at 15:50
  • I know this is an old question, but for reference I thought I'd add this, since I stumbled across it. It might be possible to design a desirable guilloche with this http://www.subblue.com/projects/guilloche and then utilising their provided source code (extract the equations), plug parameters from your drawing to re-create the image with TikZ – EricR Jun 04 '12 at 19:02

3 Answers3

46

Guilloché (Guilloche) is a decorative engraving technique in which a very precise intricate repetitive pattern or design is mechanically engraved into an underlying material with fine detail. Specifically, it involves a technique of engine turning, called guilloché in French after the French engineer “Guillot”, who invented a machine “that could scratch fine patterns and designs on metallic surfaces

The problem is to draw a curve with a fixed point inside a circle

A method : I used tkz-fct because it's my package and I know it but it's easy to create the same thing with only tikz. (here you need gnuplot)

enter image description here

\documentclass[11pt]{scrartcl}
\usepackage[dvipsnames]{xcolor}     
\usepackage{tkz-fct}


\begin{document} 

\def\spirographlike#1{%
\def\repeatno{#1}
 \foreach \i in {1,...,\repeatno}
   {%
    \begin{scope}[rotate=360/\repeatno*\i]
      \mycloedcurve
    \end{scope}}%
    } 

\def\mycloedcurve{\tkzFctPolar[color=MidnightBlue,thick,domain=0:2*pi,samples=400]{ 1+cos(3*t)+(sin(3*t))**2}}  

\noindent\begin{tikzpicture}
 \mycloedcurve 
\end{tikzpicture}    
\begin{tikzpicture}[scale=2]
 \tkzInit [xmin=-5,xmax=5,ymin=-5,ymax=5] 
  \spirographlike{40}    
\end{tikzpicture} 

\end{document}

update

enter image description here This is better but you need some time to compile

\documentclass[11pt]{scrartcl}
\usepackage[dvipsnames]{xcolor}     
\usepackage{tkz-fct}


\begin{document} 

\def\spirographlike#1{%
\def\repeatno{#1}
 \foreach \i in {1,...,\repeatno}
   {%
    \begin{scope}[rotate around={360/\repeatno*\i:(.5,0)}]
      \mycloedcurve
    \end{scope}}%
    } 

\def\mycloedcurve{\tkzFctPolar[color=MidnightBlue,thick,domain=0:2*pi,samples=400]{ 1+cos(3*t)+(sin(3*t))**2}}    

\begin{tikzpicture}
 \mycloedcurve 
\end{tikzpicture}    
\begin{tikzpicture}[scale=2]
 \tkzInit [xmin=-5,xmax=5,ymin=-5,ymax=5] 
  \spirographlike{20}    
\end{tikzpicture} 

\end{document} 
Alain Matthes
  • 95,075
  • 2
    Sweet sweet sweet.....love TikZ.....love it <3. – azetina Mar 02 '12 at 16:53
  • Adding \noindent before \begin{tikzpicture} eliminates the overfull \hbox warning. – Peter Grill Mar 02 '12 at 17:12
  • Thanks Peter I forget always these kind of problem, because I'm obsessed with the main question. Possible \usepackage{fullpage} – Alain Matthes Mar 02 '12 at 17:31
  • Very nice. This is getting closer and closer to the Spirograph question. – percusse Mar 02 '12 at 17:43
  • @percusse Can you provide any insights in generating the border like guilloche? Or may be with your knowledge on your post quoted above can the image sample I provided be recreated? – azetina Mar 02 '12 at 17:49
  • @percusse yes you are right. I only change one thing it's the point of rotation for the second picture ( and the curve ! ) – Alain Matthes Mar 02 '12 at 17:58
  • @azetina I think what is above is fantastic anyway. What you are asking requires a closed form formula for the end product. If you can provide those formulas or the initial shapes you can plug them into the code of Altermundus above. – percusse Mar 02 '12 at 18:05
  • Exactly percusse is right, you need to find the good formula or a find a shape to rotate. I made some tries but this takes a lot of time. – Alain Matthes Mar 02 '12 at 18:22
  • @percusse I agree with what you are saying. This applies to the rotation examples but how about the horizontal like shape borders. My guess would involve sin and cosbut then to decide where to cut it off and it being dependent on a length would be the trick. – azetina Mar 02 '12 at 19:10
  • FYI,
    I have posted instructions on how to install gnuplot, and make it talk to latex, on Mac OS X here: http://tex.stackexchange.com/questions/71160/how-to-use-gnu-plot-to-plot-diagrams-in-texshop?lq=1
    – PatrickT Feb 20 '14 at 14:54
18

So here's an approach to draw the 'straight' parts. (Might be a bit crude to more seasoned people...)

The compile time is certain to put the most patient of us to test, but that's to be expected with TikZ doing such things... :)

I only plotted one such sample from the ones I found at Mathworld. So there are some samples ready to be downloaded. They are (as you can see below) a sum of lots of sines and the essential trick to get them to mesh together beautifully is to control the 'frequency' and the 'initial phase'.

So here's the code:

\documentclass[12pt,a4paper]{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[very thin]

\foreach \n in {0,...,19}
    {
        \foreach \x [remember=\x as \lastx (initially 0)] in {0.01,0.02,...,6.28}
            {
                \draw [red] (\lastx*2,{(4+sin(5*(180*\lastx/pi)))+((7+sin(7*(180*\lastx/pi)))-(4+sin(5*(180*\lastx/pi))))*(1+sin(5*(180*\lastx/pi)+\n*20))/2}) -- (\x*2,{(4+sin(5*(180*\x/pi)))+((7+sin(7*(180*\x/pi)))-(4+sin(5*(180*\x/pi))))*(1+sin(5*(180*\x/pi)+\n*20))/2});
            }
    }

\end{tikzpicture}

\end{document}

As you can see, I had to rescale a bit the coordinates, primarily because the source formulas used radians and TikZ likes degrees... Also I stretched a bit the thing along the x axis for looks.

And this is what you get after - well - a while:

enter image description here

Faster Code:

The idea is to reuse the previous coordinate instead of recomputing it with the use of \lastx. Further this means that there will only be {0,...,19} draw commands instead of 20\times6.29/0.01=12580.
This feature is used by doing an inline for-loop.

So instead you would do:

\begin{tikzpicture}[very thin]

  \foreach \n in {0,...,19} {
      \draw [red] (0,{(4+sin(5*(0)))+((7+sin(7*(0)))-(4+sin(5*(0))))*(1+sin(5*(0)+\n*20))/2}) 
      \foreach \x in {0.01,0.02,...,6.28} { 
          -- (\x*2,{(4+sin(5*(180*\x/pi)))+((7+sin(7*(180*\x/pi)))-(4+sin(5*(180*\x/pi))))*(1+sin(5*(180*\x/pi)+\n*20))/2}) 
      }; % <- Here the \draw ends
  }
\end{tikzpicture}

For further speed the computation of the angles could be made more explicit, and shorter expression could be made:

\begin{tikzpicture}[very thin]
  \foreach \n in {0,...,19} {
      \draw [red] (0,{4+(7-4)*(1+sin(\n*20))/2}) 
      \foreach \x in {0.5,1,...,360} { 
          -- ({6.28318*\x/180},{4+sin(5*\x)+(7+sin(7*\x)-(4+sin(5*\x)))*(1+sin(5*\x+\n*20))/2})
      };
  }
\end{tikzpicture}

As a last optimization all variables that can be reduced should be, this will not give as much, as it is simple multiplication and division:

\begin{tikzpicture}[very thin]
  \foreach \n [evaluate={\n*20} as \ntwenty] in {0,...,19} {
      \draw [red] (0,{5.5+1.5*sin(\ntwenty))}) 
      \foreach \x [evaluate={sin(5*\x)} as \sfx] in {0.5,1,...,360} { 
          -- ({0.034906585039886591*\x},{4+\sfx+(3+sin(7*\x)-\sfx)*(1+sin(5*\x+\ntwenty))/2})
      };
  }
\end{tikzpicture}

And actually it does compiler twice as fast, and faster for the last, when changing from evaluate to \pgfextra\pgfmathparse{sin(5*\x)}\edef\sfx{\pgfmathresult}\endpgfextra there is no gain, so is not showed:

  1. 1m59.699s
  2. 0m59.100s
  3. 0m43.627s
  4. 0m38.714s
nickpapior
  • 17,275
Count Zero
  • 17,424
  • Excellent results. I suppose one can make it into border like with the above. Though the compilation may take long one can export it as a pdf and then import it as a background. – azetina Mar 03 '12 at 01:02
  • 1
    Very nice, the compilation time will be speed up a lot by not calculating every point twice, so instead do: \draw [red] (\lastx*2,{(4+sin(5*(180*\lastx/pi)))+((7+sin(7*(180*\lastx/pi)))-(4+sin(5*(180*\lastx/pi))))*(1+sin(5*(180*\lastx/pi)+\n*20))/2}) \foreach \x in {0.01,0.02,...,6.28} { -- (\x*2,{(4+sin(5*(180*\x/pi)))+((7+sin(7*(180*\x/pi)))-(4+sin(5*(180*\x/pi))))*(1+sin(5*(180*\x/pi)+\n*20))/2}) }; also the 180*\x/pi could be automated in the for loop instead! – nickpapior Mar 05 '12 at 08:33
  • @zeroth: I'm sorry, I don't really get it... Where do I insert that line of code? What should I do with \lastx? I'd rather you edited my answer (if it's too much for a comment). – Count Zero Mar 05 '12 at 22:52
  • 1
    @CountZero I have edited your answer with two speedups! :) – nickpapior Mar 06 '12 at 07:14
  • @CountZero and one more, which only is to illustrate that the fewest repetitive computations is the best! :) – nickpapior Mar 06 '12 at 11:53
  • @zeroth: THX! :) – Count Zero Mar 06 '12 at 15:54
5

An alternative to creating guillochés with TikZ is to use a third-party tool to produce them as graphics files, and then import them into your document using the usual \includegraphics{…}.

I'm aware of the following guilloché tools:

GuardSoft Cerberus

A sophisticated, proprietary guilloché tool for Microsoft Windows that can export to PostScript. Prices are not listed on the website, though I gather that it's very expensive (thousands of dollars).

Screenshot of GuardSoft Cerberus

Excentro

Another proprietary Guilloché generator, available for $500 for Mac OS. There is also a "Lite" version available for $25. Bitmap and PDF outputs are supported.

Screenshot of Excentro

Guilloché Pattern Generator

A free-as-in-beer Adobe Flash application that you can use from a web browser. You simply select the desired foreground and background colours and adjust a series of sliders to control the size and shape of the pattern. The patterns can be saved as JPEG images by pressing S. If your system has a printer driver that outputs PDF files, then you can supposedly print vectorized PDFs by right-clicking and selecting "Print Guilloche". (I haven't tested this myself.)

Screenshot of subblue's Guilloché Pattern Generator

Vectorizer

A reimplementation of subblue's Guilloché Pattern Generator in HTML and JavaScript. It can output the image as a PNG or SVG graphic. (You can then use your favourite graphics converter, such as Inkscape or rsvg, to convert the SVG to PDF or EPS for use with LaTeX.)

Screenshot of Vectorizer

Psychonaut
  • 3,142