TikZでスケールサイズ1cmのアイソメトリックドットペーパーを描くにはどうすればよいですか?

Aug 22 2020

生徒が絵を描くことができるように、1cmの等角ドットペーパーをクラスの試験の練習に入れたいと思います。MWEがないことをお詫びします。どこから始めればいいのかわからない。画像を見る

回答

8 TobiBS Aug 22 2020 at 17:04

等角ドットはxy座標と座標を変更してからグリッドにドットを配置することで簡単に作成できます。ただし、基本的に座標系を回転させたため、結果をクリップする必要があります。スケールは、どの1cmように定義され、@ AlexGの仮定を使用するかを尋ねたので、好みに合わせて採用する必要があります。

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[x={(0.86cm,0.5cm)},y={(-0.86cm,0.5cm)}]
\clip (0,12.5) rectangle (25,12.5);
\foreach \x in {0,...,25}
    \foreach \y in {0,...,25}
    {
    \fill (\x,\y) circle (2pt);
    }
\end{tikzpicture}
\end{document}

ジョンのコメントの後に編集

上記のコードから作成されたPDFでAdobeAcrobatを使用していくつかの測定を行いましたが、これが結果です。

では、この画像を参考にすると、どの測定値が1cmである必要がありますか?

アイソメトリックA4紙

\documentclass[tikz,border={0.23cm 0.25cm}]{standalone}

\begin{document}
\begin{tikzpicture}[x={(0.86cm,0.5cm)},y={(-0.86cm,0.5cm)}]
\clip (0,25.5) rectangle (37.5,29);
\foreach \x in {0,...,50}
\foreach \y in {0,...,50}
{
    \fill (\x,\y) circle (2pt);
}
\end{tikzpicture}
\end{document}
9 AndréC Aug 22 2020 at 18:53

アップデート2:pgfkeysで定義された新しい座標系

座標は、tikzのネイティブの暗黙的な座標と同じスタイルで指定されます。つまり、コンマで区切られた3つの数値です。iso cs:たとえば、接頭辞として次のようになります。(iso cs:0,1,7)

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows.meta}

\pgfkeys{/isometrique/.cd,
      coordonnee/.code args={#1,#2,#3}
        {
            \def\myx{#1}
            \def\myy{#2}
            \def\myz{#3}
        }
}

\tikzdeclarecoordinatesystem{isometric}
{
    \pgfkeys{/isometrique/.cd,
              coordonnee={#1}}
    \pgfpointadd{\pgfpointxyz{0}{\myz}{0}}{\pgfpointadd{\pgfpointpolarxy{-30}{\myx}}{\pgfpointpolarxy{30}{\myy}}}
}
\tikzaliascoordinatesystem{iso}{isometric}

\begin{document}
\begin{tikzpicture}[>={Triangle[angle=45:4pt 3]}]

\newcommand{\nbx}{11}%<--number of point on one row
\newcommand{\nby}{9}%<-- number of point on one column

\foreach \j in {0,...,\the\numexpr\nby-1} {
  \foreach \i in {0,...,\the\numexpr\nbx-1} 
  {\fill[black](90:\j)++(0:{2*\i*cos(30)})circle[radius=1pt]+(30:1)circle[radius=1pt];
}}

\draw[very thick,red,->](0,0)--node[sloped,below]{$y=6$}(iso cs:0,4,0);
\draw[very thick,blue,->](iso cs:0,4,0)-- node[sloped,above]{$x=2$}++(iso cs:2,0,0);
\draw[very thick,red,->](iso cs:2,4,0)-- node[sloped,below]{$z=3$}++(iso cs:0,0,3);

% Arrows showing the newest coordinate system "iso"
\draw [blue,thick,->](0,4)--node[below]{x}++(iso cs:1,0,0);
\draw [red,thick,->](0,4)--node[left]{y}++(iso cs:0,1,0);
\draw [violet,thick,->](0,4)--node[left]{z}++(iso cs:0,0,1);
\node[below,align=center,draw,fill=white] at (iso cs:0,1,2.7){New \textbf{iso} \\ coordinate system};

\begin{scope}[shift={(iso cs:2,4,3)}]
\draw[blue,thick] (iso cs:0,0,0)--++ (iso cs:3,0,0)
--++ (iso cs:0,3,0)
--++ (iso cs:0,0,3)
--++ (iso cs:-3,0,0)
--++ (iso cs:0,-3,0)
--++(iso cs:0,0,-3)
(0,3)--++(iso cs:3,0,0)--+(0,-3)
(iso cs:0,3,0)--+(iso cs:0,3,0);
\end{scope}
\end{tikzpicture}
\end{document}

垂直キーを使用した別の座標系の追加の更新z(Tobiの要求による)

その欠点は、2つではなく3つの座標を記述する必要があるため、より冗長になることです。

ここではキーがkeyvalパッケージで定義されているため、keyvalsを使用すると、デフォルト値を定義して、たとえばの(trio cs:x,y=2,z)代わりに書き込むことができます(trio cs:x=0,y=2,z=0)。ここで、キーにはデフォルト値があります。つまり、値が指定されていない場合、キーはデフォルト値の価値があります。

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

%\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\makeatletter
\define@key{triangularokeys}{x}[0]{\def\myx{#1}}
\define@key{triangularokeys}{y}[0]{\def\myy{#1}}
\define@key{triangularokeys}{z}[0]{\def\myz{#1}}
\tikzdeclarecoordinatesystem{triangularo}%
{%
\setkeys{triangularokeys}{#1}%
\pgfpointadd{\pgfpointxyz{0}{\myz}{0}}{\pgfpointadd{\pgfpointpolarxy{-30}{\myx}}{\pgfpointpolarxy{30}{\myy}}
}
}
\makeatother
\tikzaliascoordinatesystem{trio}{triangularo}
\begin{document}

\begin{tikzpicture}[>={Stealth[]}]

\newcommand{\nbx}{11}%<--number of point on one row
\newcommand{\nby}{9}%<-- number of point on one column


\foreach \j in {0,...,\the\numexpr\nby-1} {
  \foreach \i in {0,...,\the\numexpr\nbx-1} 
  {\fill[black](90:\j)++(0:{2*\i*cos(30)})circle[radius=1pt]+(30:1)circle[radius=1pt];
}}

\draw[very thick,red,->](0,0)--node[sloped,below]{$y=6$}(trio cs:x=0,y=4,z=0);
\draw[very thick,red,->](trio cs:x,y=4,z)-- node[sloped,above]{$x=2$}++(trio cs:x=2,y,z);
\draw[very thick,red,->](trio cs:x=2,y=4,z)-- node[sloped,below]{$z=3$}++(trio cs:x,y,z=3);


% Arrows showing the newest coordinate system "trio"
\draw [blue,thick,->](0,4)--node[below]{x}++(trio cs:x=1,y,z);
\draw [red,thick,->](0,4)--node[left]{y}++(trio cs:x,y=1,z);
\draw [violet,thick,->](0,4)--node[left]{z}++(trio cs:x,y,z=1);
\node[below,align=center] at (trio cs:x,y=1,z=3){New trio \\ coordinate system};

\begin{scope}[shift={(trio cs:x=2,y=4,z=3)}]
\draw[blue,thick] (trio cs:x,y,z)--++ (trio cs:x=3,y,z)
--++ (trio cs:x,y=3,z)
--++ (trio cs:x,y,z=3)
--++ (trio cs:x=-3,y,z)
--++ (trio cs:x,y=-3,z)
--++(trio cs:x,y,z=-3)
(0,3)--++(trio cs:x=3,y,z)--+(0,-3)
(trio cs:x,y=3,z)--+(trio cs:x,y=3,z);
\end{scope}
\end{tikzpicture}

\end{document}

呼ばれる座標系との最初の答えtrixし、yキー。

デカルト座標に加えて、このグリッドに図形を描画するのを「簡単」にする新しい座標系を定義しました。と呼ばれtriangular、そのエイリアスはtriです。

たとえば、最初の赤い矢印は次のように描画されます。

\draw[very thick,red,->](0,0)--(tri cs:x=0,y=7);

2番目の矢印は次のように定義されています。

\draw[very thick,red,->](tri cs:x=0,y=7)--++(tri cs:x=2,y=0);

同じパス2つの座標系を混合し、相対座標を使用できることに気付くでしょう。

コード

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

%\usepackage{tikz}
\usetikzlibrary{arrows.meta}

% new coordinate system called triangular 
\makeatletter
\define@key{triangularkeys}{x}{\def\myx{#1}}
\define@key{triangularkeys}{y}{\def\myy{#1}}
\tikzdeclarecoordinatesystem{triangular}%
{%
\setkeys{triangularkeys}{#1}%
\pgfpointadd{\pgfpointpolarxy{-30}{\myx}}{\pgfpointpolarxy{30}{\myy}}
}
\makeatother
% end of new coordinate system 

\tikzaliascoordinatesystem{tri}{triangular}%<-- define the alias tri for triangular
   

\begin{document}

\begin{tikzpicture}[>={Stealth[]}]

\newcommand{\nbx}{11}%<--number of dots in a single row
\newcommand{\nby}{9}%<-- number of dots in a single column

% Drawing of the isometric grid
\foreach \j in {0,...,\the\numexpr\nby-1} {
  \foreach \i in {0,...,\the\numexpr\nbx-1} 
  {\fill[black](90:\j)++(0:{2*\i*cos(30)})circle[radius=1pt]+(30:1)circle[radius=1pt];
}}

% The following code below shows how to draw on this grid

% Arrows showing the new coordinate system
\draw [blue,thick,->](0,4)--node[below]{x}++(tri cs:x=1,y=0);
\draw [red,thick,->](0,4)--node[left]{y}++(tri cs:x=0,y=1);

% Big red arrow going from the bottom left to the perspective cube
\draw[very thick,red,->](0,0)--node[sloped,below]{$y=7$}(tri cs:x=0,y=7);
\draw[very thick,red,->](tri cs:x=0,y=7)-- node[sloped,above]{$x=2$}++(tri cs:x=2,y=0);

% Cube perspective drawing
\begin{scope}[shift={(tri cs:x=2,y=7)}]
\draw (tri cs:x=0,y=0)circle(3pt)--++ (tri cs:x=3,y=0)
--++ (tri cs:x=0,y=3)
--++ (0,3)
--++ (tri cs:x=-3,y=0)
--++ (tri cs:x=0,y=-3)
--++(0,-3)
(0,3)--++(tri cs:x=3,y=0)--+(0,-3)
(tri cs:x=0,y=3)--+(tri cs:x=0,y=3);
\end{scope}


\end{tikzpicture}

\end{document}
8 AlexG Aug 22 2020 at 20:55

楽しみのために、A4(595 bp * 842 bp)で1cmスケールのアイソメトリックドットペーパーを作成するための純粋なPostScriptソリューション。PostScriptプリンターに直接送信できます。

ps2pdfPDFが必要な場合に使用します。しかし、PS [242B]よりもはるかに大きい[38kB]。(PSコードは、読みやすさを犠牲にしないためにあまり積極的ではありませんが、サイズについていくらか最適化されています。)

isometricdottedA4.ps

%! 
<</PageSize [595 842]>> setpagedevice 
/cm {28.346457 mul} def 
[.866 .5 -.866 .5 595 2 div 842 41 cm sub 2 div] concat 
0 1 41 { cm 
 0 1 41 { cm 1 index exch moveto 
  gsave initmatrix currentpoint 2 0 360 arc fill grestore 
 } for pop 
} for 

1 ArtificialStupidity Aug 23 2020 at 12:32

PSTricksソリューションは、楽しみまたは比較の目的でのみ使用できます。

\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(10,10)
    \multips(0,0)(0,1){11}{%
        \multips(0,0)(1,0){11}{%
            \qdisk(0,0){2pt}\qdisk(.5,.5){2pt}}}
\end{pspicture}
\end{document}