# Shading triangle

I'd like to use tikz to shade an isosceles triangle with points A B C and length of AB and AC are equal. Shading should go from AB (red) to AC (green) where the color on a line through A always stays the same. I have found such a shading for circles but unfortunately not yet for triangles...

Thanks in advance Jan

• Please include any code you've tried so far. – Null Jul 22 '16 at 1:34
• Welcome! What you ask is impossible. If any line through A must have the same colour at every point, then every line through A must have the same colour because all such lines include the point A which can have only one colour. But all lines in the plane go through A. Hence, all must have the same colour at every point. In particular, AB and AC must have the same colour. Red and green are not the same colour. Hence, the desiderata yield a contradiction. – cfr Jul 22 '16 at 2:48

## 2 Answers

Here's how you do that in Metapost. There's no built-in gradient shading option, but you can draw lots of thin triangles with varying colours. prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

a = 20;

pair A, B, C;
A = origin;
B = 120 right rotated a;
C = 120 right rotated -a;

path t;
t = A--B--C--cycle;

s = 1/4;
for i=s step s until 2a:
filldraw point 0 of t
-- point 1+(i-s)/2a of t
-- point 1+(i)/2a of t
-- cycle withcolor ((3+i)/2a)[green,red];
endfor

dotlabel.lft("A", A);
dotlabel.urt("B", B);
dotlabel.lrt("C", C);

endfig;
end.


Note: the extra 3 in the shading arithmetic slightly favours red so that it looks even. Without this bias, it looked like there was more green than red to me.

I was able to achieve the following with a color wheel. I couldn't rotate the built in color wheel, so I copied one off the internet (image). I should note that the built in color wheel is very slow, so to get the desired shading one might as well bite the bullet and fill the triangle one line width at a time.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shadings}

\begin{document}
\begin{tikzpicture}
\draw (0,0) coordinate (B) -- (2,0) coordinate (C) -- (1,2) coordinate (A) -- cycle;
\begin{scope}
\clip (A) -- (B) -- (C) -- cycle;
\node[rotate=210] at (A) {\includegraphics[width=5.656cm] {images/colorwheel}};
\end{scope}
\end{tikzpicture}
\end{document} 