
預設情況下,線條的粗細從中心(原始路徑)向左側和右側擴展。看這張圖片,正如您所看到的,考慮白線是原始路徑,與白線重疊的黑線是厚度。
我的問題:如何改變向下和向上擴散厚度的方向?
我問這個問題的原因是因為當我繪製一條內切於另一條閉合路徑的閉合路徑時,它變得像這。我希望內部閉合路徑在原始路徑的向下方向具有厚度,外部在原始路徑的向上方向具有厚度,所以我的圖像看起來不錯。
微量元素:
\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}