2

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.

  • 3
    Those points do not form a square. – Torbjørn T. Jun 11 '17 at 13:05
  • 1
    I drew them in a diagram and looked at it. – Torbjørn T. Jun 11 '17 at 13:10
  • 2
    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
  • 1
    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
  • 1
    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
5

One possibility using the calc library and a loop.

enter image description here

\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}
3

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}

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.