Triangulation in tikz
Example, which uses both smart stuff (grid
), \foreach
loops and manual elements:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw
(0, 0) grid[step=1cm] (3, 3)
(0, 2) -- (1, 3)
(0, 1) -- (2, 3)
(0, 0) -- (3, 3)
(1, 0) -- (3, 2)
(2, 0) -- (3, 1)
;
\fill[radius=3pt]
\foreach \x in {0, ..., 3} {
\foreach \y in {0, ..., 3} {
(\x, \y) circle[]
}
}
;
\path[above left]
\foreach \y in {0, 3} {
\foreach[count=\x] \v in {a, b, c, a} {
(\x - 1, \y) node {$\v$}
}
}
\foreach \p/\v in {
{0, 2}/e,
{1, 2}/f,
{2, 2}/g,
{3, 2}/e,
{0, 1}/h,
{1, 1}/j,
{2, 1}/k,
{3, 1}/h%
} {
(\p) node {$\v$}
}
;
\end{tikzpicture}
\end{document}
A (hopefully accurate) scalable version for arbitrary size (can't say if it's mathematically useful but was fun to make).
alphalph
used to generate arbitrary number of labels some increased spacing is probably necessary if you're going beyond a 5x5 grid to make more space for the double letter labels. The code basically uses a lot of foreach
with a little bit of maths to make sure each label has the appropriate number associated.
\documentclass{article}
\usepackage{tikz}
\usepackage{alphalph}
\newcommand{\triangulation}[1]{
\pgfmathsetmacro{\triangulationdimension}{#1}
\pgfmathsetmacro{\triangulationdim}{\triangulationdimension-1}
\begin{scope}[yscale=-1]
\node [circle,draw,fill=black,label=above left:{\alphalph{1}}] at (\triangulationdimension,\triangulationdimension) {};
\foreach \i [evaluate=\i as \l using int(\triangulationdimension*(\i-1)+1)] in {1,...,\triangulationdim} {
\node [circle,draw,fill=black,label=above left:{\alphalph{\i}}] at (\i,\triangulationdimension) {};
\node [circle,draw,fill=black,label=above left:{\alphalph{\l}}] at (\triangulationdimension,\i) {};
\foreach \j [evaluate=\j as \k using int(\triangulationdimension*(\j-1)+\i)] in {1,...,\triangulationdim} {
\node [circle,draw,fill=black,label=above left:{\alphalph{\k}}] at (\i,\j) {};
\foreach \x in {0,1} {
\draw (\i+\x,\j) -- (\i+\x,\j+1);
\draw (\j,\i+\x) -- (\j+1,\i+\x);
}
\draw (\j,\i+1) -- (\j+1,\i);
}
}
\end{scope}
}
\begin{document}
\begin{tikzpicture}
\triangulation{3}
\end{tikzpicture}
\begin{tikzpicture}
\triangulation{4}
\end{tikzpicture}
\begin{tikzpicture}
\triangulation{8}
\end{tikzpicture}
\end{document}
A sort of a programmer styled answer, similar to @HeikoOberdiek 's one:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {0,..., 3}{
\foreach \y in {0,..., 3}{
\fill (\x, \y) circle (3pt);
\draw (0,0) rectangle (\x,\y);
}
}
\foreach \x in {0, ..., 2}{
\foreach \y in {2, ..., 0}{
\draw (\x, \y) -- (\x + 1, \y + 1);
}
}
\path[above left]
\foreach \a in {0, 3}{
\foreach[count=\x] \b in {a, b, c, a}{
(\x - 1, \a) node {$\b$}
}
}
\foreach \a/\b in {
{0, 2}/e,
{1, 2}/f,
{2, 2}/g,
{3, 2}/e,
{0, 1}/h,
{1, 1}/j,
{2, 1}/k,
{3, 1}/h
} {
(\a) node {$\b$}
}
;
\end{tikzpicture}
\end{document}