編輯

編輯

我想使用 繪製循環(或多邊形路徑)TikZ。我提供了嘗試使用直角坐標和極坐標來執行此操作的程式碼。在第一張圖中,我認為循環被幫助線遮住了。第二張圖沒有按照我想要的方式繪製。

在這兩張圖中,我在網格上都有路徑。我想讓網格線的厚度為循環中線段的四分之一,並且是淺灰色。我認為預設繪製的線條粗細TikZ是0.4pt;因此,我認為該規格line width=0.1pt將使幫助線的厚度為週期的四分之一。它沒。我忘記瞭如何使線條變成淺灰色。 (我認為幫助線預設是灰色的。)

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

答案1

繪圖選項需要傳遞給\draw命令而不是grid. (編輯:作為Qrrbrbirbel 首先說.)

極座標指定為(angle:distance)。但請注意,例如 的角度135始終處於同一方向,因此路徑的前兩段將朝著同一方向行進:

(1,1.5) -- ++(135:2) -- ++(135:1) 

(1,1.5) -- ++(135:3)

是等價的。

因此部分更正的程式碼如下所示:

\documentclass{amsart}
\usepackage{tikz}

\begin{document}

  \begin{tikzpicture}
    \draw [gray, line width=0.1pt] (0,0) grid [xstep=0.5, ystep=0.5] (6,6);
    \draw [line width=0.5pt] (4,1) -- ++(1,0) -- ++(0,3) -- ++(-2,0) -- cycle;
  \end{tikzpicture}
  \vskip0.25in

  \begin{tikzpicture}
    \draw [gray, line width=0.1pt] (0,0) grid [xstep=0.5, ystep=0.5] (6,6);
    \draw [line width=0.5pt] (1,1.5) -- ++(135:2) -- ++(135:1) -- ++(90:3) -- ++ (120:1) -- cycle;
  \end{tikzpicture}
\end{document}

但這可能不是您想要的:

不是真正的多邊形

線條特寫:

特寫

編輯

shapes.geometric庫可讓您輕鬆繪製正多邊形等內容:

\documentclass[tikz,border=5pt]{standalone}

\usetikzlibrary{shapes.geometric}

\begin{document}

  \begin{tikzpicture}
    \draw [gray, line width=.1pt] (0,0) grid [xstep=0.5, ystep=0.5] (6,6);
    \node [shape=regular polygon, regular polygon sides=5, draw, minimum width=15mm] at (3,3) {};
  \end{tikzpicture}
\end{document}

正多邊形節點

但是,如果這不適合,您可以嘗試以下方法:

  \begin{tikzpicture}
    \draw [gray, line width=.1pt] (0,0) grid [xstep=0.5, ystep=0.5] (6,6);
    \begin{scope}[shift={(1,1.5)}]
      \draw [line width=0.5pt] ++(0:1) -- ++(72:1) -- ++(144:1) -- ++(216:1) -- ++ (288:1) -- cycle;
    \end{scope}
  \end{tikzpicture}

網格上的正多邊形

編輯 編輯

或不規則...

  \begin{tikzpicture}
    \draw [gray, line width=.1pt] (0,0) grid [xstep=0.5, ystep=0.5] (6,6);
    \begin{scope}[shift={(3,1.5)}]
      \draw [line width=0.5pt] ++(0:2) -- ++(72:1) -- ++(144:3) -- ++(216:2.5) -- ++ (288:.5) -- cycle;
    \end{scope}
  \end{tikzpicture}

不規則凸多邊形

相關內容