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}
Danu
  • 968
  • 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 08 '16 at 02: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 08 '16 at 03: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 08 '16 at 06:15
  • I can't seem to set options in the argument to the knot environment as I'd expect. For example, every strand/.style={whatever} seems to have no effect. I need to separately do a TikZ set and then knot diagram, every strand ... which isn't what the manual suggests at all, unless I'm completely misreading it. (It isn't very clear, but using knot diagram/every knot diagram, as recommended, doesn't seem to work. At least, I couldn't make it work. Nor can I get the \redraw to do anything much. (I thought I could redo the problematic crossing, but I can't work it out.) Key handling is odd. – cfr Aug 08 '16 at 14:51
  • The key hierarchy is a mix of expl3 and PGF, which doesn't help, I think, as PGF/TikZ and expl3 are not a happy pairing generally. But it is more that I find the mix confusing to read - it doesn't make debugging any easier! – cfr Aug 08 '16 at 14:54
  • @cfr thank you for putting in effort to help solving this question. Unfortunately, I'm not familiar enough with the necessary concepts to be of any use. Perhaps the package creator Loop Space could be of some help, if he/she happens to see this post... – Danu Aug 08 '16 at 15:53
  • I think this knot functionality was written by Andrew Stacey. – Jamie Vicary Aug 09 '16 at 03:14
  • Hi all. I'm away from my computer right now so can't experiment, but will do when I next can. Off the top of my head, you could rotate the circles so that the start/end are away from the crossings. With regard to any specific issues with keys, or poor documentation, the more detail the better for fixing. (I'm totally fine with people pointing out issues in my packages - you won't hurt my feelings!) – Andrew Stacey Aug 10 '16 at 19:02
  • Ignore that about rotating the circles. That's nothing to do with it. I would try redrawing the black/green crossing using the \redraw command. – Andrew Stacey Aug 10 '16 at 19:09
  • 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: https://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
  • @LoopSpace That might be it. I tried using \redraw but it didn't help. The OP should likely try your update, then. – cfr Aug 11 '16 at 16:00
  • 1
    @cfr Just notifying you of an answer. – Andrew Stacey Aug 16 '16 at 12:08

1 Answers1

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}
Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751