TikZ Knots 包:縮放後交叉發生變化

TikZ Knots 包:縮放後交叉發生變化

我意識到,當我的結圖以不同的比例縮放時,它的交叉點之一會改變。交叉點應該是正確的第二由下面的程式碼產生的圖表。我不知道這是怎麼發生的。我嘗試過使用draft mode=crossings但沒有用。我可以幫忙將第一個圖的交叉點切換到正確的版本嗎?

這是我的程式碼:

\documentclass[a4paper,11pt]{report}
\usepackage{graphicx,amssymb,amstext,amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,hobby,knots,celtic,shapes.geometric,calc}

\begin{document}

\tikzset{
  knot diagram/every strand/.append style={
    line width=1.5pt,violet
  },
}

\tikzset{
  my style/.style={
    dashed
  }
}

\begin{tikzpicture}[scale=0.9, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[my style, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[my style, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

%---------------------------------------------------------------

\begin{tikzpicture}[scale=2, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[my style, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[my style, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

\end{document}

答案1

這裡的根本問題與中指出的相同當交叉點靠近另一條(粗)線時,「knots」tikz 函式庫的意外行為:發生了什麼事?。有兩個交叉點非常靠近,並且剪切圓(繪製交叉點時)重疊,這意味著當在灰色虛線上繪製紫色線時,它也會在該有問題的交叉點處繪製自身。

以下是一些可能的修復方法。首先,我縮小了剪切圓的半徑。在第二個中,我從結中取出了灰色虛線,因為它似乎實際上並不是結的一部分(請注意,如果您確實想將其保留在結中,則應該使用該only when rendering部分的鑰匙dashed-詳細信息請參閱文件)。在第三次修復中,我稍微簡化了你的嗜好路徑。

結果:

各種修復

代碼:

\documentclass[a4paper,11pt]{report}
%\url{https://tex.stackexchange.com/q/478294/86}
\usepackage{shellesc}
\usepackage{graphicx,amssymb,amstext,amsmath}
\usepackage{tikz}
\usetikzlibrary{
  decorations.pathreplacing,
  decorations.markings,
  hobby,
  knots,
  celtic,
  shapes.geometric,
  calc,
  external
}

\tikzexternalize

\begin{document}

\tikzset{
  knot diagram/every strand/.append style={
    line width=1.5pt,violet
  },
}

\tikzset{
  my style/.style={
    dashed
  }
}




Demonstration of the problem: the clipping circles are big enough that the circle associated with the crossing between the violet line and the dashed grey line overlaps the problematic crossing.

\tikzsetnextfilename{problem}
\begin{tikzpicture}[scale=0.9, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  background clip/.append style={
    preaction={
      fill=gray,
      fill opacity=.5,
    }
  },
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[knot diagram/only when rendering/.style={my style}, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[knot diagram/only when rendering/.style={my style}, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

%---------------------------------------------------------------

Fix one: shrink the clipping circles using the \verb+clip radius+ key.

\tikzsetnextfilename{fix-one}
\begin{tikzpicture}[scale=0.9, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  clip radius=3pt,
  background clip/.append style={
    preaction={
      fill=gray,
      fill opacity=.5,
    }
  },
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[knot diagram/only when rendering/.style={my style}, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[knot diagram/only when rendering/.style={my style}, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

Fix two: the dashed grey lines don't appear to actually be anything to do with the knot, so draw them separately.
This means that there aren't two crossings near to each other any more.

\tikzsetnextfilename{fix-two}
\begin{tikzpicture}[scale=0.9, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\draw[
  line width=1.5pt,
  my style,
  lightgray,
  rotate=180
] (-0.7,-1.2) -- (-0.7,2.5);
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
%  flip crossing=6,
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

Fix three: you specify a lot of \emph{nodes} in your Hobby path.
If you aren't wedded to that specific path then reducing the number of nodes can simplify the knot algorithm.

\tikzsetnextfilename{fix-three}
\begin{tikzpicture}[scale=0.9, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.2 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.28 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.8 with {\arrow[line width=1.5pt]{<}}}}]
\draw[
  line width=1.5pt,
  my style,
  lightgray,
  rotate=180
] (-0.7,-2.2) -- (-0.7,3.5);
\begin{knot}[
  consider self intersections=true,
  end tolerance=3pt,
  flip crossing=4,
  rotate=180]
  \strand ([closed].5,2) [add arrow,violet] ..  (-.5,1) .. (.3,-.5) .. (-.3,-.5) .. (.5,1) .. ([tension=3]-1.5,1) .. (.7,-1) .. (-2,1);
\end{knot}
\path (0,-.7);
\end{tikzpicture}


\tikzsetnextfilename{large-scale}
\begin{tikzpicture}[scale=2, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[knot diagram/only when rendering/.style={my style}, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[knot diagram/only when rendering/.style={my style}, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

\end{document}

答案2

我完全按照你的建議做了,draft mode=crossings之後我翻轉了數字 6 並得到

\documentclass[a4paper,11pt]{report}
\usepackage{graphicx,amssymb,amstext,amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,hobby,knots,celtic,shapes.geometric,calc}

\begin{document}

\tikzset{
  knot diagram/every strand/.append style={
    line width=1.5pt,violet
  },
}

\tikzset{
  my style/.style={
    dashed
  }
}

\begin{tikzpicture}[scale=0.9, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[my style, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[my style, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

%---------------------------------------------------------------

\begin{tikzpicture}[scale=2, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[%draft mode=crossings,
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing/.list={3,6},
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[my style, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[my style, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}

\end{document}

在此輸入影像描述

好吧,我無法解決這個問題。這是一個解決方法的建議。

\documentclass[a4paper,11pt]{report}
\usepackage{graphicx,amssymb,amstext,amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings,hobby,knots,celtic,shapes.geometric,calc}

\begin{document}

\tikzset{
  knot diagram/every strand/.append style={
    line width=3.2pt,violet
  },
}

\tikzset{
  my style/.style={
    dashed
  }
}

\scalebox{0.45}{
\begin{tikzpicture}[scale=2, use Hobby shortcut, add arrow/.style={postaction={decorate}, decoration={
  markings,
  mark=at position 0.25 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.653 with {\arrow[line width=1.5pt]{<}},
  mark=at position 0.75 with {\arrow[line width=1.5pt]{<}}}}]
\begin{knot}[%draft mode=crossings,
  consider self intersections=true,
  ignore endpoint intersections=false,
  flip crossing=3,
  rotate=180]
  \strand ([closed]0,0) .. (0.7,-0.7) .. (0,-1) .. (-1.7,0) .. (-1.5,2.2) .. (0,2.5) .. (.5,2) .. (-.5,1) [add arrow,violet] .. (.5,0) .. (0,-.5) .. (-.5,0) .. (.5,1) .. (-.5,2) .. (-1.5,1) .. (0,0);
  \strand[my style, lightgray] (-0.7,-1.2) -- (-0.7,-.9); 
  \strand[my style, lightgray] (-0.7,-.75) -- (-0.7,2.5);
\end{knot}
\path (0,-.7);
\end{tikzpicture}}

\end{document}

在此輸入影像描述

相關內容