TikZで各エッジを個別に色付けする

TikZで各エッジを個別に色付けする

エッジ AB を濃い青色で、エッジ AC と BC を濃い赤色で塗ります。

の回答を参考にTikZ の複数のカラーエッジ1 つの方法は、 コマンドを使用することです\clip[draw]。ただし、私の形状は三角形であり、三角形もオレンジ色で塗りつぶされているため、私のコンテキストではどのように使用すればよいかわかりません。

期待される結果:

ここに画像の説明を入力してください

現在の結果:

ここに画像の説明を入力してください

三角形はまだオレンジ色で塗りつぶされ、端は上記の色になっているはずです。

注記: この例は PGF マニュアルからのみ引用されています。説明なしにマニュアルにコードを提供することは推奨されません。

\filldrawまたはコマンドを使用する代わりに、図形を塗りつぶす別の方法はありますか\draw[fill]

MWE:

\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

いくつかのオプションは、パスの一部の場合、これは の場合です。しかし、マニュアル3.1.1の149ページに示されているように、これrounded cornersは では常に に適用される では機能しません。colorsパス全体

ページ 149 のスクリーンショット:

スクリーンショット

簡単にするために、次のようになります。

  • まずABCの三角形をコマンドでオレンジ色に着色しまし\fill(何も描画しません);
  • それから私は描いたパス、1 つはblue、もう 1 つは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。特に、交差点を関連するパスに統合することで、空のパスを削除できます。

から までの色付けをするにはAB2 つのポイントの間に線を引くだけです (フレームを描いた後、またはフレームを削除した後)。 についても同様です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} 

関連情報