[Tex/LaTex] How to draw a shaded triangle

tikz-pgf

I would like to draw a shaded triangle by defining the 3 vertices and an RGB color at each of those vertices. The interior shaded color would vary linearly from one vertex to the other.

Here is what I have so far but the shading is not what I am needing.

\documentclass[tikz]{standalone}

\usetikzlibrary{calc,intersections}

\begin{document}
\begin{tikzpicture}

% Specify the coordinates
\coordinate (A1) at (0,0);
\coordinate (A2) at (5,2);
\coordinate (A3) at (10,-3);

\definecolor{c1}{RGB}{0,129,188}
\definecolor{c2}{RGB}{252,177,49}
\definecolor{c3}{RGB}{35,34,35}

% Draw the sides of the triangle
\draw (A1) -- (A2) -- (A3) -- cycle;

\shade [left color=c1,right color=c2] (A1) -- (A2) -- (A3) -- cycle;

\end{tikzpicture}
\end{document}

While this question is similar: Tikz triangle with point colours

The answers are limited in the following ways

  • Several of the solutions are artistic approximations and not precise shading between the vertices.
  • The solutions are presented for an equilateral triangle and not a general triangle.
  • The solution method using pgfplots works the best but won't display in ShareLatex and is having difficulty printing so is limited.

Best Answer

Just to answer the unanswered.

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\definecolor{c1}{RGB}{0,129,188}
\definecolor{c2}{RGB}{252,177,49}
\definecolor{c3}{RGB}{35,34,35}

\begin{tikzpicture}
\begin{axis}[hide axis]
    \addplot[
        patch,
        shader=interp,
        mesh/color input=explicit,
        data cs=cart,
    ]
    coordinates {
        (0,0)   [color=c1]
        (5,2)   [color=c2]
        (10,-3) [color=c3]
    };
\end{axis}
\end{tikzpicture}
\end{document}

One of the easiest ways to do this is using pgfplots. Many other solutions can be found out here on tex.sx with different degrees of complexity and accuracy. But this seems simple with acceptable output.

Here I draw within an axis but hide it. This is essentially a plot with interpolated shading and the vertices colors are given explicitly.