我想將邊緣 AB 塗為濃藍色,將邊緣 AC 和 BC 塗為濃紅色。
參考答案中TikZ 中的多種顏色邊緣,一種方法是使用\clip[draw]
命令。但是,我不確定如何在我的上下文中使用,因為我的形狀是一個三角形,三角形也填充了橙色。
預期結果:
目前結果:
三角形仍應填滿橙色,邊緣應填滿上述顏色。
筆記:此範例僅來自 PGF 手冊。在沒有解釋的情況下,不建議/讚賞在手冊中提供代碼。
是否有其他方法來填充形狀而不是使用\filldraw
或\draw[fill]
命令。
微量元素:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{through}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[help lines/.style={thin,draw=black!50}]
\coordinate[label=left:\textcolor{blue!80!black}{$A$}] (A) at (0,0);
\coordinate[label=right:\textcolor{blue!80!black}{$B$}] (B) at (1.25,0.25);
\draw[name path=A--B] (A) -- (B);
% \draw let \p1 = ($(B) - (A)$),
% \n2 = {veclen(\x1,\y1)}
% in
% (A) circle (\n2)
% (B) circle (\n2);
\node (D) [name path=D,draw,circle through=(B),label=left:$D$,help lines,draw] at (A) {};
\node (E) [name path=E,draw,circle through=(A),label=right:$E$,help lines,draw] at (B) {};
\path [name intersections={of=D and E, by={[label=above:$C$]C,[label=below:$C'$]C'}}];
%\coordinate[label=above:$C$] (C) at (intersection-1); using by instead
\draw [name path=C--C',red] (C) -- (C');
\path [name intersections={of=A--B and C--C', by=F}];
\node[fill=red,inner sep=1pt, label=-45:$F$] at (F) {};
\draw[fill=orange!80] (A) -- (B) -- (C) -- cycle;
\foreach \point in {A,B,C}
\fill [black,opacity=0.5] (\point) circle (2pt);
\end{tikzpicture}
\end{document}
答案1
某些選項可以應用於路徑的一部分,情況就是如此rounded corners
。但這不適用於colors
手冊 3.1.1 第 149 頁所示的內容,該內容始終適用於整個路徑。
149頁截圖:
因此,為了使其更容易:
\fill
我首先使用命令將 ABC 三角形塗成橙色(它不畫任何東西);- 然後我畫了二路徑,一個在
blue
,另一個在red
。
評論代碼:
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{through}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[help lines/.style={thin,draw=black!50}]
\coordinate[label=left:\textcolor{blue!80!black}{$A$}] (A) at (0,0);
\coordinate[label=right:\textcolor{blue!80!black}{$B$}] (B) at (1.25,0.25);
\path[name path=A--B] (A) -- (B);% <-- construct the path, but not draw it
% \draw let \p1 = ($(B) - (A)$),
% \n2 = {veclen(\x1,\y1)}
% in
% (A) circle (\n2)
% (B) circle (\n2);
\node (D) [name path=D,draw,circle through=(B),label=left:$D$,help lines,draw] at (A) {};
\node (E) [name path=E,draw,circle through=(A),label=right:$E$,help lines,draw] at (B) {};
\path [name intersections={of=D and E, by={[label=above:$C$]C,[label=below:$C'$]C'}}];
%\coordinate[label=above:$C$] (C) at (intersection-1); using by instead
\path [name path=C--C',red] (C) -- (C');
\path [name intersections={of=A--B and C--C', by=F}];
%\node[fill=red,inner sep=1pt, label=-45:$F$] at (F) {};
\fill[orange!80] (A) -- (B) -- (C) -- cycle;%<-- only fill without draw the edges
\draw[blue,thick](A)--(B);%<-- draw in blue
\draw[red,thick](A)--(C)--(B);%<-- draw in red
\foreach \point in {A,B,C}
\fill [black,opacity=0.5] (\point) circle (2pt);
\end{tikzpicture}
\end{document}
答案2
\path
您可以使用or指令的可能性來儲存一些路徑\draw
。特別是,可以透過將交叉點整合到相關路徑中來移除空路徑。
要著色,只需A
在B
兩點之間畫一條線(繪製框架或簡單地刪除框架後)。同樣適用於A--B--C
.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{through}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[help lines/.style={thin,draw=black!50}]
\path[name path=A--B] (0,0) coordinate[label=left:\textcolor{blue!80!black}{$A$}] (A) --
(1.25,0.25) coordinate[label=right:\textcolor{blue!80!black}{$B$}] (B);
\node (D) [name path=D,draw,circle through=(B),label=left:$D$,help lines,draw] at (A) {};
\node (E) [name path=E,draw,circle through=(A),label=right:$E$,help lines,draw] at (B) {};
\draw[name intersections={of=D and E, by={[label=above:$C$]C,[label=below:$C'$]C'}},
name path=C--C',red] (C) -- (C');
\node[fill=red,inner sep=1pt,name intersections={of=A--B and C--C', by=F},label=-45:$F$] at (F) {};
\draw[draw=none,fill=orange!80] (A) -- (B) -- (C) -- cycle;
\draw[blue,thick] (A) -- (B);
\draw[red,thick] (A) -- (C) -- (B);
\foreach \point in {A,B,C}
\fill [black,opacity=0.5] (\point) circle (2pt);
\end{tikzpicture}
\end{document}