I would like to draw cycles (or polygonal paths) using TikZ
. I provide code in which I try to do this using rectangular coordinates and polar coordinates. In the first drawing, I think the cycle is obscured by the help lines. The second drawing is not drawn the way I had intended.
In both drawings, I have the paths on a grid. I wanted to make the grid lines a quarter of the thickness of the line segments in the cycles and a light gray. I think the default thickness of lines drawn by TikZ
is 0.4pt; so, I thought the specification line width=0.1pt
would make the help lines a quarter as thick as the cycles. It did not. I forgot how to make the lines a light gray. (I thought help lines were gray by default.)
\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{intersections,decorations.pathreplacing,positioning}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid [xstep=0.5, ystep=0.5, line width=0.1pt,gray] (6,6);
\draw[line width=0.5pt] (4,1) -- ++(1,0) -- ++(0,3) -- ++(-2,0) -- cycle;
\end{tikzpicture}
\vskip0.25in
\begin{tikzpicture}
\draw (0,0) grid [xstep=0.5, ystep=0.5, line width=0.1pt,gray] (6,6);
\draw[line width=0.5pt] (1,1.5) -- ++(2:135) -- ++(1:135) -- ++(3:90) -- ++ (1:120) -- cycle;
\end{tikzpicture}
\end{document}
Best Answer
The options for drawing need to be passed to the
\draw
command rather thangrid
. (EDIT: as Qrrbrbirlbel said first.)Polar coordinates are specified as
(angle:distance)
. But note that an angle of135
, say, is always in the same direction so the first two segments of your path are going in the same direction:and
are equivalent.
So partially corrected code looks like this:
but this is probably not what you want:
Close up of lines:
EDIT
The
shapes.geometric
library lets you draw things like regular polygons easily:However, if that doesn't suit, you could try this:
EDIT EDIT
Or irregular...