# Triangular diagram in Tikz

I'm trying to replicate the following diagram in Tikz:

Where the borders encompass a right angled triangle, with dashed lines (not in picture) joining (0,0.5--1,0) and (0,1--0,5,0). Moreover, it has 2 dashed lines around the (1/3,1/3) point. These lines are kind of triangular, but smooth (so without kinks).

I have attempted the following:

\begin{tikzpicture}[scale=0.5]
%Drawing the border
\draw (0,0) -- (0,11) (0,0) -- (11,0);
\draw [->] (0,11);
\draw [->] (11,0);
\draw (10,0) -- (0,10);
% Drawing dashed lines
\draw[dashed] (0,5) -- (10,0);
\draw[dashed] (5,0) -- (0,10);
\end{tikzpicture}


But have no idea how to draw those dashed smooth triangles. Note that this need not to follow any particular equation, just a rough sketch is satisfactory :).

An astute commenter pointed out that the 1/3, 1/3 is on the intersection of the two lines! My drawn diagram forgot about this.

• please can you post a compile-able example rather than just a snippet? – Thruston Apr 19 '18 at 14:42
• OT, but also (1/3, 1/3) will be at the intersection of those two lines... – Thruston Apr 19 '18 at 14:47
• Ah of course! You're right. 1/3, 1/3 is at the intersection! Silly me. – Tamay Apr 19 '18 at 14:50

With smooth cycle you can draw smooth triangles. You can make it rounder by playing with tension.

\documentclass[tikz,border=3.14pt]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.5]
%Drawing the border
\draw (0,0) -- (0,11) (0,0) -- (11,0);
\draw [->] (0,11);
\draw [->] (11,0);
\draw (10,0) -- (0,10);
% Drawing dashed lines
\draw[dashed] (0,5) -- (10,0);
\draw[dashed] (5,0) -- (0,10);
\pgfmathsetmacro{\myx}{2}
\draw[dashed] plot[smooth cycle] coordinates {({10/3-\myx/3},{10/3+\myx})
({10/3+\myx},{10/3-\myx/3}) ({10/3-\myx/3},{10/3-\myx/3}) };
\pgfmathsetmacro{\myx}{1}
\draw[dashed] plot[smooth cycle] coordinates {({10/3-\myx/3},{10/3+\myx})
({10/3+\myx},{10/3-\myx/3}) ({10/3-\myx/3},{10/3-\myx/3}) };
\end{tikzpicture}
\end{document}


• Amazing! If one more person upvotes this question, I'll have enough reputation to upvote your answer :) – Tamay Apr 19 '18 at 15:29

Same idea as @marmot, another code (varying the tension and the scale factor in the same time).

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
\begin{tikzpicture}
%Drawing the border
\draw (0,0) edge[-latex] (0,11) edge[-latex] (11,0) (10,0) -- (0,10);
% Drawing dotted lines
\draw[dotted, very thick] (0,5) -- (10,0) (5,0) -- (0,10);
% The barycenter
\fill[red] (10/3,10/3) coordinate (O) circle(3pt);
% The smooth triangles
\foreach[evaluate={\t=1-~/10}] ~ in {1,...,9}
\draw[blue,scale around={~/10:(O)},smooth cycle,tension=\t,dashed, thick]
plot coordinates {(0,0) (0,10) (10,0)};
\end{tikzpicture}
\end{document}


An option that in my opinion is more practical, is to use the tkz-euclide package that is designed for this type of graphics, in the case of the drawing that you pose, you can use the centroid (or any other point) and look for points towards the vertices to then draw the internal triangles.

You can get this:

or This:

Here is the code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% By J. Leon V.  coded based on the BSD, MIT, Beerware licences.
\documentclass[border=2mm]{standalone}
\usepackage{xcolor}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}
% Set limits.
\tkzInit[xmax=20,xmin=-1,ymax=20, ymin=-1]
%\tkzGrid[sub,color=blue!10!,subxstep=.5,subystep=.5] %HIDE CARTESIAN GRID
%\tkzAxeXY %HIDEN CARTESIAN AXIS
\tkzClip
%Define principal points. (10X)
\tkzDefPoint(0,0){O}
\tkzDefPoint(11,0){X1}
\tkzDefPoint(0,11){X2}
%Calculate points.
\tkzDefBarycentricPoint(O=1,X1=10) \tkzGetPoint{A}
\tkzDefBarycentricPoint(O=1,X2=10) \tkzGetPoint{B}
\tkzDefMidPoint(O,A) \tkzGetPoint{C}
\tkzDefMidPoint(O,B) \tkzGetPoint{D}
\tkzDefBarycentricPoint(O=2,A=1) \tkzGetPoint{c}
\tkzDefBarycentricPoint(O=2,B=1) \tkzGetPoint{d}
\tkzCentroid(A,B,O) \tkzGetPoint{G}

%DRAW AND FIND POINTS
\foreach \y [count=\i] in {1,..., 4}{
\tkzDefBarycentricPoint(O=1,G=\y) \tkzGetPoint{GO\i}
\tkzDrawPoint[fill=red,size=10pt,](GO\i) % SHOW HIDEN POINTS GO
\tkzDefBarycentricPoint(A=1,G=\y) \tkzGetPoint{GA\i}
\tkzDrawPoint[fill=red,size=10pt,](GA\i) % SHOW HIDEN POINTS GA
\tkzDefBarycentricPoint(B=1,G=\y) \tkzGetPoint{GB\i}
\tkzDrawPoint[fill=red,size=10pt,](GB\i) % SHOW HIDEN POINTS GB
\draw[dashed] plot[smooth cycle] coordinates{
(GO\i)(GA\i)(GB\i)
};
}

\tkzDrawSegments(B,A)
\tkzDrawSegments[dashed](B,C A,D)
\tkzDrawVectors[thick](O,X1 O,X2)
\tkzMarkRightAngle(X2,O,X1) % For the case of 90 degres
\tkzDrawPoints[size=10pt,shape=cross](c,d,G)

%
%   %Labels:
\tkzLabelPoint[below](A){ $A$}
\tkzLabelPoint[below](C){$A/2$}
\tkzLabelPoint[left](B){ $B$}
\tkzLabelPoint[left](D){$B/2$}
\tkzLabelPoint[left](O){$O$}
\tkzLabelPoint[below](X1){$X_1$}
\tkzLabelPoint[left](X2){$X_2$}
\tkzLabelPoint[below](c){$A/3$}
\tkzLabelPoint[left](d){$B/3$}
\tkzLabelPoint[left](G){\sf Centroid}

\end{tikzpicture}

\end{document}

• @marmot You can ask a question when it doesn't work. He used to be a very active user and still stops by occasionally. tex.stackexchange.com/users/3144/alain-matthes It is a pretty decent tool for me to be honest. – percusse Apr 19 '18 at 16:48
• @Tamay, in my case I use a separated tex code that is compiled and exported to a pdf, and then is included in the main document, the standalone document class crops the canvas, and when you import the pdf in the main document using for example graphics package (that gives you many controls for positioning), there is no lost of quality it still a vertor image, the pdf produced is low of file size (36KB in this example) and has no significant effect in the increment of size of the principal document. – J Leon V. Apr 19 '18 at 18:48
• @Kpym Thank you so much!!!! Yes, that solved it. (But in some way this confirms what I was suspecting, namely that I screwed it simply because I cannot understand the French manual.) Anyway, I am going to remove all my above comments now. – user121799 Apr 19 '18 at 20:00
• @Kpym I am wondering if I should write an official question which you might answer. I am suspecting that I am not the only one having this problem. – user121799 Apr 19 '18 at 20:06
• @marmot I'm serenely not the person to answer this question, because I don't use very much tkz-euclid. If you are interested in a english cheatsheet I have created one for myself (originally it was in french ;)). – Kpym Apr 19 '18 at 20:17

You might also like a Metapost version, that shows how to do nice smooth cycle paths (in red). This is done using luamplib so compile with lualatex - or workout how to convert it for pdflatex with the gmp package (or plain MP).

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\usepackage{luatex85}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric u;
u = 144;
path xx, yy;
xx = origin -- right scaled 1.1u;
yy = xx rotated 90;

z0 = (1, 1) scaled 1/3 u;

draw (0, 1/2u) -- (u, 0) -- (0, u) -- (1/2u, 0)
dashed evenly scaled 1/2
withcolor 1/2 white;

dotlabel.llft("$x$", z0);

% this is how to make a nice "smooth cycle" curve
% default tension is 1 and gives something more like a circle
% tension infinity gives straight lines
def :: = .. tension 3 .. enddef;
for t=1/5, 1/3:
draw t[z0, (0,0)] ::
t[z0, (0,u)] ::
t[z0, (u,0)] :: cycle
dashed withdots scaled 1/4
withcolor 2/3 red;
endfor

drawarrow xx; label.rt ("$x_1$", point 1 of xx);
drawarrow yy; label.top("$x_2$", point 1 of yy);

draw (down--up) scaled 1 shifted (1/3u,0);
draw (down--up) scaled 1 shifted (1/2u,0);
draw (down--up) scaled 1 shifted (   u,0);
label.bot("$\frac13$", (1/3u, 0));
label.bot("$\frac12$", (1/2u, 0));
label.bot("$1$", (u,0));

draw (left--right) scaled 1 shifted (0, 1/3u);
draw (left--right) scaled 1 shifted (0, 1/2u);
draw (left--right) scaled 1 shifted (0,    u);
label.lft("$\frac13$", (0, 1/3u));
label.lft("$\frac12$", (0, 1/2u));
label.lft("$1$", (0, u));

endfig;
\end{mplibcode}
\end{document}