# How to draw grid by given four points in Tikz?

It is easy to draw a grid on a square if the square is not rotated. But for rotated squares it is difficult for me to grid it. I want to grid a square by given four points. for example the following four points:

A(-3,0), B (-2,5), C(-5,3), D(0,2).

Any suggest would be greatly appreciated.

• Those points do not form a square. – Torbjørn T. Jun 11 '17 at 13:05
• I drew them in a diagram and looked at it. – Torbjørn T. Jun 11 '17 at 13:10
• The grid command takes options just as any other, such as [rotation=<angle>]. Figure out the rotation of your rectangle, put that rotation into the grid rotation option, done. Example: \tikz[rotate=30] \draw[step=1mm] (0,0) grid (2,2); – Huang_d Jun 11 '17 at 13:10
• That is a perfectly good way. No fuss involved. What is your usual way? Care to edit an MWE into your question so that we can help you better? – Huang_d Jun 11 '17 at 13:13
• I haven't said that, I've merely pointed out that your example points do not form a square (or even a rectangle or parallellogram for that matter). – Torbjørn T. Jun 11 '17 at 13:15

One possibility using the calc library and a loop.

\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,1);
\coordinate (C) at (2,4);
\coordinate (D) at (-1,3);

\foreach [evaluate=\i as \x using \i/10] \i in {0,...,10}
{
\draw ($(A)!\x!(B)$) -- ($(D)!\x!(C)$);
\draw ($(A)!\x!(D)$) -- ($(B)!\x!(C)$);
}
\end{tikzpicture}
\end{document}


Brute force, without calc

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\foreach \t in {0,1,...,10}
{
\draw({-3+\t*(-5-(-3))/10},{0+\t*(3-0)/10})--({0+\t*(-5-(-3))/10},{2+\t*(3-0)/10});
\draw({-3+\t*(0-(-3))/10},{0+\t*(2-0)/10})--({-5+\t*(3-0)/10},{3+\t*(2-0)/10});
}
\end{tikzpicture}
\end{document}