默认情况下,线条的粗细是从中心(原始路径)向左侧和右侧扩展。看到这个图片,如您所见,假设白线是原始路径,与白线重叠的黑线是厚度。
我的问题:如何改变向下和向上扩展厚度的方向?
我之所以问这个问题是因为当我画一条封闭路径刻在另一条封闭路径上时它变得像这。我希望内部的封闭路径在原始路径的向下方向具有厚度,并且外部在原始路径的向上方向具有厚度,这样我的图像看起来会很漂亮。
梅威瑟:
\documentclass[tikz,border=1mm]{standalone}
\usepackage{bm}
\usetikzlibrary{calc,arrows.meta}
\tikzset{
parallel segment/.style={
segment distance/.store in=\segDistance,
segment pos/.store in=\segPos,
segment length/.store in=\segLength,
to path={
($(\tikztostart)!\segPos!(\tikztotarget)!\segLength/2!(\tikztostart)!\segDistance!90:(\tikztotarget)$) --
($(\tikztostart)!\segPos!(\tikztotarget)!\segLength/2!(\tikztotarget)!\segDistance!-90:(\tikztostart)$) \tikztonodes
},
% Default values
segment pos=.5,
segment length=1cm,
segment distance=-2.5mm,
},
}
\begin{document}
\begin{tikzpicture}[>=Latex]
\coordinate (A) at (0,0);
\coordinate (B) at (7,1);
\coordinate (C) at (3.5,4);
\coordinate (D) at (3.5,.5);
\coordinate (E) at (5.25,2.5);
\coordinate (F) at (1.75,2);
\draw [line width=3pt] (A)--(B)--(C)--cycle
node[] at (1.7,.8){$\bm{C}$};
\draw [line width=3pt] (D)--(E)--(F)--cycle;
\draw[->, line width=1.5pt, red] (A) to[parallel segment] (B);
\draw[->, line width=1.5pt, red] (B) to[parallel segment] (C);
\draw[->, line width=1.5pt, red] (C) to[parallel segment] (A);
\end{tikzpicture}
\end{document}
答案1
最简单的解决方案是裁剪图。如果使用相同的形状进行裁剪和绘制,则每条线只有内半部分可见。
下面只是剪掉多余的角。
\documentclass[tikz,border=1mm]{standalone}
\usepackage{bm}
\usetikzlibrary{calc,arrows.meta}
\tikzset{
parallel segment/.style={
segment distance/.store in=\segDistance,
segment pos/.store in=\segPos,
segment length/.store in=\segLength,
to path={
($(\tikztostart)!\segPos!(\tikztotarget)!\segLength/2!(\tikztostart)!\segDistance!90:(\tikztotarget)$) --
($(\tikztostart)!\segPos!(\tikztotarget)!\segLength/2!(\tikztotarget)!\segDistance!-90:(\tikztostart)$) \tikztonodes
},
% Default values
segment pos=.5,
segment length=1cm,
segment distance=-2.5mm,
},
}
\begin{document}
\begin{tikzpicture}[>=Latex]
\coordinate (A) at (0,0);
\coordinate (B) at (7,1);
\coordinate (C) at (3.5,4);
\coordinate (D) at (3.5,.5);
\coordinate (E) at (5.25,2.5);
\coordinate (F) at (1.75,2);
\draw [line width=3pt] (A)--(B)--(C)--cycle
node[] at (1.7,.8){$\bm{C}$};
\begin{scope}
\clip (A)--(B)--(C)--cycle;
\draw [line width=3pt] (D)--(E)--(F)--cycle;
\end{scope}
\draw[->, line width=1.5pt, red] (A) to[parallel segment] (B);
\draw[->, line width=1.5pt, red] (B) to[parallel segment] (C);
\draw[->, line width=1.5pt, red] (C) to[parallel segment] (A);
\end{tikzpicture}
\end{document}