4

I recently tried to draw some Olympic rings using the tikz library "knots", and ran into some unexpected behavior. As can be seen in the linked answer, the lower crossing of the black and green rings looks a bit strange. Removing the yellow ring corrects this behavior, so it must be due to this ring being close to the crossing. Is this behavior intended? Is it a bug? Or am I making some kind of basic mistake?

The MWE is given in the linked answer, but I will reproduce it below:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{knots}
\begin{document} 
\begin{tikzpicture}
\definecolor{blue1}{RGB}{0,129,188}
\definecolor{yellow1}{RGB}{252,177,49}
\definecolor{black1}{RGB}{35,34,35}
\definecolor{green1}{RGB}{0,157,87}
\definecolor{red1}{RGB}{238,50,78}
\begin{knot}[clip width=1.5pt]
    \strand[line width=0.25cm,red1] (3,0) circle(1.25cm);
    \strand[line width=0.25cm,green1] (1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,black1] (0,0) circle(1.25cm);
    \strand[line width=0.25cm,yellow1] (-1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,blue1] (-3,0) circle(1.25cm);
    \flipcrossings{2,4,6,8}
\end{knot}
\end{tikzpicture}
\end{document}
12
  • If you comment the flipping and the yellow circle, then the red/green crossing looks odd. Comment the black, and it is fine. Is the yellow ring meant to be smaller, by the way? – cfr Aug 8 '16 at 2:23
  • There is something very weird about the package, isn't there? Or is it just me? But the key handling does not seem to work quite as advertised? – cfr Aug 8 '16 at 3:01
  • @cfr woops, that radius change was part of my investigation into the cause of the behavior. Also, you're right that this package has some quirks... Though I'm not sure exactly what you're referring to. – Danu Aug 8 '16 at 6:15
  • 1
    I did a bit of an update of the redraw stuff a short time ago which isn't on ctan yet, you can get the latest version at github: github.com/loopspace/spath3 the code is all in spath3.dtx (in particular, ignore knots.dtx - that's very old) – Andrew Stacey Aug 10 '16 at 19:17
  • 1
    @cfr Just notifying you of an answer. – Andrew Stacey Aug 16 '16 at 12:08
3

Here's two versions that work.

The first uses the slightly advanced \redraw command from the version on github (Warning: that repository needs a clean-up; the only file that matters is spath3.dtx). This was mentioned in the comments. The update evaluates the coordinate passed to \redraw at evaluation time rather than invocation time. This allows for the coordinates defined by the knot drawing routine to be used making it easier to target a specific intersection.

\begin{tikzpicture}
\definecolor{blue1}{RGB}{0,129,188}
\definecolor{yellow1}{RGB}{252,177,49}
\definecolor{black1}{RGB}{35,34,35}
\definecolor{green1}{RGB}{0,157,87}
\definecolor{red1}{RGB}{238,50,78}
\begin{knot}[
  clip width=1.5pt,
  name=olympic,
]
    \strand[line width=0.25cm,red1] (3,0) circle(1.25cm);
    \strand[line width=0.25cm,green1] (1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,black1] (0,0) circle(1.25cm);
    \strand[line width=0.25cm,yellow1] (-1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,blue1] (-3,0) circle(1.25cm);
\flipcrossings{2,4,6,8}
\redraw{2}{(olympic 3)}
\end{knot}
\end{tikzpicture}

Result:

Olympic rings

The second version plays with the clip width and clip radius a little bit to get it right the first time. I'm beginning to think that these are not named very well as even I keep getting them confused! In short, when an intersection is flipped then it is redrawn with the strands in the opposite order so that what was the under-strand is now the over-strand. In order to ensure that this only affects the specified crossing, the redraw is clipped to a circle around that crossing. The radius of this clipping circle is given by the key clip radius and is a dimension. The goal with this is to set it as small as possible to minimise the effect of redrawing while making it big enough for the redraw to be successful.

The clip width is something separate. When each strand is drawn, it is first drawn a little thicker and the colour of the background. This is to achieve the "cutting out" effect whereby the over-strand "cuts out" a part of whatever is under it. The clip width affects the line width of this cutting path. It is a multiplier and the line width of the cutting path is this multiplier times by the line width of the drawn strand. The idea here is to make it easier to vary the line width and keep the diagram in proportion.

So here's a version shrinking the clip radius to ensure that the problem intersection doesn't affect the neighbouring intersection and then adjusting the clip width so that the cut-out is properly drawn within the clipping circle.

This should work with the current version of knots on CTAN.

\begin{tikzpicture}
\definecolor{blue1}{RGB}{0,129,188}
\definecolor{yellow1}{RGB}{252,177,49}
\definecolor{black1}{RGB}{35,34,35}
\definecolor{green1}{RGB}{0,157,87}
\definecolor{red1}{RGB}{238,50,78}
\begin{knot}[
  clip width=1.4,
  clip radius=0.31cm
]
    \strand[line width=0.25cm,red1] (3,0) circle(1.25cm);
    \strand[line width=0.25cm,green1] (1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,black1] (0,0) circle(1.25cm);
    \strand[line width=0.25cm,yellow1] (-1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,blue1] (-3,0) circle(1.25cm);
    \flipcrossings{2,4,6,8}
\end{knot}
\end{tikzpicture}

Result:

Olympic rings v2

Full code:

\documentclass{article}
%\url{http://tex.stackexchange.com/q/323758/86}
\usepackage{tikz}
\usetikzlibrary{knots}
\begin{document} 
\begin{tikzpicture}
\definecolor{blue1}{RGB}{0,129,188}
\definecolor{yellow1}{RGB}{252,177,49}
\definecolor{black1}{RGB}{35,34,35}
\definecolor{green1}{RGB}{0,157,87}
\definecolor{red1}{RGB}{238,50,78}
\begin{knot}[
  clip width=1.4,
  clip radius=0.31cm
]
    \strand[line width=0.25cm,red1] (3,0) circle(1.25cm);
    \strand[line width=0.25cm,green1] (1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,black1] (0,0) circle(1.25cm);
    \strand[line width=0.25cm,yellow1] (-1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,blue1] (-3,0) circle(1.25cm);
    \flipcrossings{2,4,6,8}
\end{knot}
\end{tikzpicture}

\vspace{2cm}

\begin{tikzpicture}
\definecolor{blue1}{RGB}{0,129,188}
\definecolor{yellow1}{RGB}{252,177,49}
\definecolor{black1}{RGB}{35,34,35}
\definecolor{green1}{RGB}{0,157,87}
\definecolor{red1}{RGB}{238,50,78}
\begin{knot}[
  clip width=1.5pt,
  name=olympic,
]
    \strand[line width=0.25cm,red1] (3,0) circle(1.25cm);
    \strand[line width=0.25cm,green1] (1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,black1] (0,0) circle(1.25cm);
    \strand[line width=0.25cm,yellow1] (-1.5,-1.375) circle(1.25cm);
    \strand[line width=0.25cm,blue1] (-3,0) circle(1.25cm);
\flipcrossings{2,4,6,8}
\redraw{2}{(olympic 3)}
\end{knot}
\end{tikzpicture}
\end{document}
2
  • Fantastic! and . – cfr Aug 16 '16 at 20:06
  • Thank you for going above and beyond what I originally asked for; my understanding of the knots library has significantly improved :) – Danu Aug 19 '16 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.