0

I was wondering if there is a way of coding regular square and triangular lattices like these ones in the images on latex. I know how to generate regular polygons (square, triangle, hexagon etc), but I would like to know if there is a way to create these lattices as well.

enter image description hereenter image description here

2
3

Maybe like this?

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
 \draw (-0.2,-0.2) grid (4.2,3.2);
\end{tikzpicture}

\begin{tikzpicture}
 \clip (-0.2,-0.2) coordinate (bl) rectangle (4.2,3.2) coordinate (tr);
 \draw[xslant={1/sqrt(2)},yscale={1/sqrt(2)}] (-2,-0.2) grid (6,4.2);
 \draw[xslant=-{1/sqrt(2)},yscale={1/sqrt(2)}] (-2,-0.2) grid (6,4.2);
\end{tikzpicture}

\end{document}

enter image description here

1
  • Thank you! How would I add the points on the intersections of these graphs? – causalityrefilm. Apr 19 at 7:28
1

If you want a regular triangular grid with dots, you may try this (based on a solution by AndréC). triangular grid with dots

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \tikzset{d/.style={minimum width=2pt,inner sep=0pt,circle,fill=black}}
    \begin{tikzpicture}
        
        \def\nx{5}
        \def\ny{3} \pgfmathsetmacro\nyy{(2+2*\ny)*sin(60)}
        
        \draw[cyan] (0,0) rectangle (\nx +1,\nyy);
        \foreach \j in {0,...,\ny} {
            \foreach \i in {0,...,\nx} {
                \draw[cyan](0:\i)++(90:{(1+2*\j)*sin(60)})--++(1,0);
                \draw[cyan](0:\i) ++(60:\j) ++(120:\j) node[d] {} --++(60:2) node[d] {} --++(-1,0) node[d] {} --++(-60:1) node[d] {} --++(-60:1) node[d] {};
            }
        }
    \end{tikzpicture}
\end{document}

And if you want to add dots on your square grid, just nest two \foreach loops, like this:

square grid with dots

    \begin{tikzpicture}
        \def\nx{6} \def\ny{4}
        \draw [cyan] (0,0) grid (\nx,\ny);
        \foreach \i in {0,...,\nx}
            \foreach \j in {0,...,\ny}
                \node[d] at (\i,\j) {};
    \end{tikzpicture}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.