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

此处的根本问题与当交叉点接近另一条(粗)线时,“结” tikz 库会出现意外行为:发生了什么?有两个交叉点非常接近,并且剪切圆(绘制交叉点时)重叠,这意味着当紫色线绘制在虚线灰色线上时,它也会在该有问题的交叉点处绘制自身。

这里有几个可能的修复方法。首先,我减小了剪切圆的半径。其次,我将虚线灰色线从结中取出,因为它似乎不是结的真正一部分(请注意,如果您确实想将其保留在结中,则应使用only when renderingdashed部分的键 - 有关详细信息,请参阅文档)。在第三个修复中,我稍微简化了您的爱好路径。

结果:

各种修复

代码:

\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}

在此处输入图片描述

相关内容