Drawing probabilities on a simplex in TikZ

To me this looks like an XY question. What you really may be after (or what you were really asked to do) is to produce a so-called ternary diagram. Luckily there exists a library for this specifically: \usepgfplotslibrary{ternary}. It comes with pgfplots, which is based on TikZ. I added the braces for fun, but also think you'd be better off with just the diagram. Notice that there are already several posts on this site that discuss how you can customize these diagrams, just do a google search for site:tex.stackexchange.com ternary diagram to find them.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.16}
\usepgfplotslibrary{ternary} 
\begin{document}
\begin{tikzpicture}
  \begin{ternaryaxis}
    \addplot3 coordinates {(0.25,0.5,0.25)} ;
    \path (0.25,0.5,0.25) coordinate (M)
     (1,0,0) coordinate (C) (0,1,0) coordinate (A) (0,0,1) coordinate (B);
  \end{ternaryaxis}
  \draw (M) -- ($(B)!(M)!(C)$); 
  \draw (M) -- ($(A)!(M)!(B)$);
  \draw (M) -- ($(C)!(M)!(A)$);
  \begin{scope}[thick,decoration={brace,raise=1pt}]
   \draw[decorate] (M) -- ($(B)!(M)!(C)$) node[midway,above=2pt,sloped]{$0.5$}; 
   \draw[decorate] (M) -- ($(A)!(M)!(B)$) node[midway,right=2pt]{$0.25$}; 
   \draw[decorate] ($(C)!(M)!(A)$) -- (M) node[midway,above=2pt,sloped]{$0.25$}; 
  \end{scope}   
\end{tikzpicture}
\end{document}

enter image description here


Tikz provides:

  • a barycentric coordinate system ("13.2.2 Barycentric Systems", p.136, pgfmanual, v3.1.4b).

    Example: (barycentric cs:A=1/2,B=1/4,C=1/4)

  • a projection modifier via the TikZ library calc ("13.5.5 The Syntax of Projection Modifiers", p.148, pgfmanual, v3.1.4b).

    Example to project P on AB: ($(A)!(P)!(B)$)

Here a solution using these features (and polar coordinates to define vertices):

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[node font=\scriptsize,inner sep=.5em]

  \path (-150:2/3) coordinate (A) node[below left]{A};
  \path ( -30:2/3) coordinate (B) node[below right]{B};
  \path (  90:2/3) coordinate (C) node[above]{C};

  \path[fill=blue!30,draw=blue] (A) -- (B) -- (C) -- cycle;

  \path (barycentric cs:A=1/2,B=1/4,C=1/4) coordinate (P) node[above]{P};
  \fill (P) circle (1pt);

  \draw[red] (P) -- ($(A)!(P)!(B)$);
  \draw[red] (P) -- ($(B)!(P)!(C)$);
  \draw[red] (P) -- ($(C)!(P)!(A)$);
\end{tikzpicture}
\end{document}

enter image description here


The calculations is described in following drawing:

enter image description here

For a triangle whose the height is 1, b=c=0.25 and a=0.5.

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}[scale=2]

\coordinate (A) at (0,0);
\coordinate (B) at ({sqrt(4/3)}, 0) {};
\coordinate (C) at ({(sqrt(4/3)/2},1) {};
\filldraw[opacity=.3, blue] (A)  -- (B) -- (C) -- cycle;
\node at (A) [below left] {1};
\node at (B) [below right]{2};
\node at (C) [above]{3};

%\draw (O)--++(0:1)coordinate(A)--++(120:1)coordinate(B)--cycle;
\draw ($(A)!0.375!(B)$)coordinate(X)--++(90:0.25)coordinate(P)--++(150:0.25)coordinate(Y);
\draw (P)--++(30:0.5)coordinate(Z);

\path[] let \p1 = ($ (X) - (P) $) in (X) -- (P) node[midway,below=-1mm,sloped]{\scalebox{0.25}{  \pgfmathparse{veclen(\x1,\y1)/28.4}\pgfmathresult cm}};
\path[] let \p1 = ($ (Y) - (P) $) in (Y) -- (P) node[above=-0.8mm,midway,sloped]{\scalebox{0.25}{ \pgfmathparse{veclen(\x1,\y1)/28.4}\pgfmathresult cm}};
\path[] let \p1 = ($ (Z) - (P) $) in (Z) -- (P) node[above=-0.8mm,midway,sloped]{\scalebox{0.25}{ \pgfmathparse{veclen(\x1,\y1)/28.4}\pgfmathresult cm}};

\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf