How to draw triangular grid in TikZ?
A funny solution (have you ever used lindenmayersystems
library?):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\begin{tikzpicture}
\pgfdeclarelindenmayersystem{triangular grid}{\rule{F->F-F+++F--F}}
\path[draw=black,
l-system={triangular grid,step=1cm,
angle=-60,axiom=F--F--F,order=4,
}]
lindenmayer system -- cycle;
\end{tikzpicture}
\end{document}
Like Leo said: use \foreach
and some math:
\usetikzlibrary{calc}
\newcommand*\rows{10}
\begin{tikzpicture}
\foreach \row in {0, 1, ...,\rows} {
\draw ($\row*(0.5, {0.5*sqrt(3)})$) -- ($(\rows,0)+\row*(-0.5, {0.5*sqrt(3)})$);
\draw ($\row*(1, 0)$) -- ($(\rows/2,{\rows/2*sqrt(3)})+\row*(0.5,{-0.5*sqrt(3)})$);
\draw ($\row*(1, 0)$) -- ($(0,0)+\row*(0.5,{0.5*sqrt(3)})$);
}
\end{tikzpicture}
A slightly different solution using a matrix transformation and clipping:
\newcommand*{\rows}{10}
\pgfmathsetmacro{\xcoord}{cos(60)}
\pgfmathsetmacro{\ycoord}{sin(60)}
\begin{tikzpicture}
\pgftransformcm{1}{0}{\xcoord}{\ycoord}{\pgfpointorigin}
\path[clip,preaction = {draw=black}] (\rows,0) -- (0,0) -- (0,\rows) -- cycle;
\draw (0,0) grid (\rows,\rows);
\foreach \x in {1,2,...,\rows} {
\draw (0,\x) -- (\x,0);
}
\end{tikzpicture}