5

I am currently teaching myself Knot Theory and am looking to draw related diagrams using TikZ. Using the knots library and a foreach loop, I have written a pretty solid code for drawing a monocolor trefoil knot:

\begin{tikzpicture}
    \begin{knot}[
        clip width=5,
        consider self intersections
    ]
        \strand[red,thick] (90:1)
            \foreach \x in {1,2,3} {
                to [bend left=117,looseness=1.9] ({90+120*\x}:1)
            }
        ;
        \flipcrossings{1,3}
    \end{knot}
\end{tikzpicture}

This yields the following image.

enter image description here

However, I would like to color each uninterrupted segment (3 total) a different color, as in my textbook (note that I am not looking to do the double lines, just the variation from white to grey to black [or colors of my choice, preferably]):

enter image description here

So far, I have looked into the decorations library, dashed lines, and more recommendations from this site and others, but I have not found the solution anywhere.

In sum, how can I independently color the different segments of my knot in TikZ?

Note that I would like the procedure to be general enough to be applicable to other knots as well.

10
  • Can help you this link at the §7? loopspace.mathforge.org/HowDidIDoThat/TeX/Knots Commented Sep 2, 2019 at 10:42
  • @Sebastiano I have seen this link. I am not sure how that code works, though. If you believe that this could be the solution, can you write up an answer explaining it? I'm still rather new to TikZ, sorry... Commented Sep 2, 2019 at 10:45
  • With lot of sincerity I should to read the manual and I'm not very able to give you an answer. Surely there is my +1. My best regards. Commented Sep 2, 2019 at 10:48
  • (Sorry - only just seen this.) The difficulty here is that colours and decorations have to be applied to paths as a whole, but the knot library is designed for when we are trying to draw strands as entire paths which cross over each other at possibly unknown places. So there's a basic tension between the two. I'm not sure of the best way to solve this one. Commented Mar 27, 2020 at 20:36
  • @AndrewStacey Yeah, I worried that that was the case. Based on my own toying around, it looks like knots obscures parts of a path rather than creating multiple. Do you have any plans to adjust its functioning, possibly as an option? BTW, I did find a rather crude solution in using multiple strands, but I had to manually create a number of the intersections using the double feature of TikZ. Commented Mar 27, 2020 at 22:45

1 Answer 1

1

[Kudos to @AndrewStacey for suggesting this fix in the comments under the question]


A full, simple solution to this problem has not yet been implemented for LaTeX, but the following is a more than adequate approximation.

To begin, consider Section 3.3 of the knots library documentation, especially the idea of using TikZ nodes to aid in knot diagrams. The most important passage is quoted below.

The node knot crossing is not meant to be drawn, it is an empty shape...This can be useful for designing curves that enter and exit the crossing gracefully at particular directions. When using this node shape, the crossing itself is easiest to draw by using the center anchor for the strands that form the over cross.

Following this guidance, I created the following MWE for the 7_4 knot, modeled after the black and white picture below it and generating the colored picture also below it.

\begin{tikzpicture}[
    every path/.style={thick},
    every node/.style={knot crossing,inner sep=1.2pt}
]
    \colorlet{rex}{red}
    \colorlet{orx}{orange}
    \colorlet{ylx}{yellow!70!black}

    \node (l) at (-1,0) {};
    \node (c) at (0,0) {};
    \node (r) at (1,0) {};
    \node (lu) at (-0.6,0.6) {};
    \node (lb) at (-0.6,-0.6) {};
    \node (ru) at (0.6,0.6) {};
    \node (rb) at (0.6,-0.6) {};

    \draw [orx] (lb)
        to [out=-50,in=-130] (rb.center)
        to [out=50,in=-120] (r)
    ;
    \draw [rex] (r)
        to [out=60,in=35,out looseness=2.5] (ru.center)
        to [out=-145,in=50] (c)
    ;
    \draw [rex] (c)
        to [out=-130,in=35] (lb.center)
        to [out=-145,in=-120,looseness=2] (l)
    ;
    \draw [orx] (l)
        to [out=60,in=-130] (lu.center)
        to [out=50,in=130] (ru)
    ;
    \draw [ylx] (ru)
        to [out=-50,in=120] (r.center)
        to [out=-60,in=-35,looseness=2] (rb)
    ;
    \draw [rex] (rb)
        to [out=145,in=-52] (c.center)
        to [out=128,in=-35] (lu)
    ;
    \draw [ylx] (lu)
        to [out=145,in=120,in looseness=2.5] (l.center)
        to [out=-60,in=130] (lb)
    ;
\end{tikzpicture}

enter image description here enter image description here

Let's begin with the styles defined at the beginning of the tikzpicture environment. As a matter of personal preference, I draw my knot diagrams with thick paths, so it made sense to define that style globally. Additionally, the inner sep node option controls the amount of white space at each crossing (the higher the value, the more white space). Lastly, the knot crossing node type is actually not technically necessary (I don't believe), but I figured why not.

Next, I define macros for the three colors that I wish to use. This both makes it easy to change every instance of a particular color should I want to and lets every color (when used later on) be represented by a short, three-letter term. Aesthetic, perhaps, but it does make the code more readable. Note that I chose my color names by taking two letters indicative of the color (e.g., "re" for "red") and concatenating the suffix "-x." I choose "-x" because should I want to have multiple shades of a color, subsequent tones could have "-y" and "-z" suffixes.

For the nodes (which must lie at the crossings of the knot), I initially guessed at appropriate positions and then progressively refined. Note that the names of the nodes are abbreviations of their positions -- from top to bottom in the MWE: left, center, right, left-upper, left-bottom, right-upper, right-bottom. Also note that while it was not necessary here, the scale key could be used to shrink or grow the knot.

Now that the invisible, helper parts have been set up, I used seven draw macros -- one for each of the seven strands of the knot. Note that using seven instead of one draw macro is only necessary because of the multiple colors. Regardless, to create the code, I began at one crossing and worked my way through all of them, following the black and white picture and the instructions from Section 3.3 quoted above and guessing at in and out angles for the to macro. After I had my draft, I progressively refined the angles and added in looseness macros as needed (maintaining symmetry throughout) until I was satisfied. Colors were added in last.

Although imperfect in that this method lacks the ease of the knot environment adjusted with a multicolor feature, this method creates a non-buggy, procedural rendering of a multicolor knot. Although this is generally true for any diagram, note that to ease the code's creation, a decent sketch of the knot must be made first to locate the crossings' positions.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.