我想将边 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
您可以使用或命令的功能来保存一些路径\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}