如何用 TikZ 绘制比例为 1cm 的等距点纸?

如何用 TikZ 绘制比例为 1cm 的等距点纸?

我想把 1cm 等距点纸放入我班考试的练习中,这样我的学生就可以画了。很抱歉没有 MWE。我不知道从哪里开始。查看图片

在此处输入图片描述

答案1

x通过修改和坐标然后将点放在网格上,可以轻松创建等距点y。但是我们需要剪辑结果,因为我们基本上旋转了坐标系。比例必须根据您的喜好进行调整,因为我问过如何定义,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}

在此处输入图片描述

根据 Jon 的评论进行编辑

我使用 Adob​​e Acrobat 对根据上述代码创建的 PDF 进行了一些测量,结果如下: 在此处输入图片描述

那么,如果以此图像作为参考,哪个测量值需要为 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}

答案2

更新 2:使用 pgfkeys 定义的新坐标系

坐标的格式与 tikz 的原生隐式坐标相同,即用逗号分隔的 3 个数字。它们以iso cs:as 为前缀,例如:(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 的要求)

它的缺点是比较冗长,因为你必须写 3 个坐标而不是 2 个。

使用 keyvals 因为这里的键是用keyval包定义的,所以我们可以定义默认值,例如(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}

tri第一个答案使用用x和键调用的坐标系y

截屏

除了笛卡尔坐标系外,我还定义了一个新的坐标系,使其“更简单”在这个网格上绘制图形。它被称为triangular,它的别名是tri

例如第一个红色箭头是这样画的:

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

第二个箭头定义如下:

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

你会注意到你可以混合使用两个坐标系在里面相同的路径并使用相对坐标。

代码

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

答案3

只是为了好玩,一个纯 PostScript 解决方案,用于制作 1 厘米比例的等距点状纸。可以直接发送到 PostScript 打印机。

如果您需要 PDF,请使用它ps2pdf;但它比 PS [242 B] 大得多 [38 kB]。(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 

以下版本可用于两者,A4,格式。只需将第二行中的替换false为即可。点间距仍为 1 厘米。true

isometricdottedA4orLetter.ps

%! 
/letter false def % replace with `true' for Letter paper 
letter {/width 612 def /height 792 def} {/width 595 def /height 842 def} ifelse 
<</PageSize [width height]>> setpagedevice 
/cm2bp {28.346457 mul} def % conversion 
/dots height width 60 sin 60 cos div div add 1 cm2bp div cvi def % # dots filled rhombus height [cm] 
[30 cos 30 sin 60 sin neg 60 cos width 2 div height dots cm2bp sub 2 div] concat % axes rotated (30°, 60°) & translated 
0 1 dots { cm2bp 
  0 1 dots { cm2bp 1 index exch moveto 
    gsave initmatrix currentpoint 2 0 360 arc fill grestore 
  } for pop 
} for

在此处输入图片描述

答案4

像这样?我明白了这里

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d,perspective}
%https://tex.stackexchange.com/questions/690566/how-to-create-a-mapping-like-the-following-figure/690569#690569
\begin{document}
\begin{tikzpicture}[isometric view ,declare function={a=3;b=3;h=3;
        }]
        \path
        foreach \X in {-1,...,5}
        {foreach \Y in {-1,...,5}
            {foreach \Z in {-1,...,3}
                {(\X,\Y,\Z)node[circle,inner sep=1pt,fill]{}}}}
        (0,0,0) coordinate (A)
        (a,0,0) coordinate (B)
        (a,b,0) coordinate (C)
        (0,b,0) coordinate (D)
        (0,0,h) coordinate (E)
        (a,0,h) coordinate (F)
        (a,b,h) coordinate (G)
        (0,b,h) coordinate (H)
        ;
        \draw  (E)-- (F) -- (G) -- (H) --cycle 
        (E) -- (A) -- (D) -- (H)
        (A) -- (B) -- (F)
        ;
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

相关内容