我想构造一个旋转方向为 120° 的三角格子。类似于这里的格子:。
这是我对于它的外观的想法(除了图片中的格子不是等边的,但我希望它是等边的):
我找到了这个代码 示例:绘制格点和矢量,但我没有得到等边三角形。
这是改变后的代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-3,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-2);
\coordinate (YAxisMax) at (0,5);
\draw [thin, gray,-latex] (XAxisMin) -- (XAxisMax) node[right] {$x$};% Draw x axis
\draw [thin, gray,-latex] (YAxisMin) -- (YAxisMax) node[above] {$z$} ;% Draw y axis
\clip (-4,-3) rectangle (5cm,5cm); % Clips the picture...
\pgftransformcm{0.866}{0}{1/2}{1}{\pgfpoint{0cm}{0cm}}
% This is actually the transformation matrix entries that
% gives the slanted unit vectors. You might check it on
% MATLAB etc. . I got it by guessing.
\coordinate (Bone) at (0,2);
\coordinate (Btwo) at (2,-2);
\draw[style=help lines,dashed] (-6,-6) grid[step=2cm] (6,6);
% Draws a grid in the new coordinates.
%\filldraw[fill=gray, fill opacity=0.3, draw=black] (0,0) rectangle (2,2);
% Puts the shaded rectangle
\foreach \x in {-4,-3,...,4}{% Two indices running over each
\foreach \y in {-4,-3,...,4}{% node on the grid we have drawn
\node[draw,circle,inner sep=2pt,fill] at (2*\x,2*\y) {};
% Places a dot at those points
}
}
\draw [ultra thick,-latex,red] (Origin)
-- (Bone) node [above right] {$a(1/2,0,\sqrt{3}/2)$};
\draw [ultra thick,-latex,red] (Origin)
-- (Btwo) node [below right] {$a(1/2,0,-\sqrt{3}/2)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($(Bone)+(Btwo)$) node [below right] {$a(1,0,0)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($-1*(Bone)-1*(Btwo)$) node [below left] {$a(-1,0,0)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($-1*(Btwo)$) node [above left] {$a(-1/2,0,\sqrt{3}/2)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($-1*(Bone)$) node [below left] {$a(-1/2,0,-\sqrt{3}/2)$};\end{tikzpicture}
\end{figure}
\end{document}
总结一下:
- 我怎样才能获得晶格点上的旋转?
- 如何获得等边三角格子?
- 我如何构造如上图所示的新虚线?
答案1
\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{calc,backgrounds}
% 3 couches de dessin
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\def\MyColorList{{"black","blue","red"}}
\begin{document}
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-3,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-2);
\coordinate (YAxisMax) at (0,5);
\draw [thin,-latex] (XAxisMin) -- (XAxisMax) node[below] {$x$};% Draw x axis
\draw [thin,-latex] (YAxisMin) -- (YAxisMax) node[above] {$z$} ;% Draw y axis
\clip (-5.5,-5) rectangle (5.5,5); % Clips the picture...
\begin{scope}[y=(60:1)]
\coordinate (Bone) at (0,2);
\coordinate (Btwo) at (2,-2);
\foreach \x [count=\j from 2] in {-8,-6,...,8}{% Two indices running over each
\draw[help lines,dashed]
(\x,-8) -- (\x,8)
(-8,\x) -- (8,\x)
[rotate=60] (\x,-8) -- (\x,8) ;
\begin{pgfonlayer}{foreground}
\foreach \y [count=\i from 2] in
{-8,-6,...,8}{% node on the grid we have drawn
\node[draw,circle,inner sep=2pt,fill] at (\x,\y) {};
\pgfmathtruncatemacro{\Angle}{mod(\j+2*\i,3)*120+90}
\pgfmathparse{\MyColorList[mod(\j+2*\i,3)]}
\draw[\pgfmathresult,-stealth,ultra thick,shift={(\x,\y)},rotate=\Angle]
(-.5,0)--(.5,0) ;
}
\end{pgfonlayer}
}
\end{scope}
% \foreach \pos/\lbl [count=\i from 0] in {
% below right/{$a(1,0)$},
% above right/{$a(1/2,\sqrt{3}/2)$},
% above left/{$a(-1/2,\sqrt{3}/2)$},
% below left/{$a(-1,0)$},
% below left/{$a(-1/2,-\sqrt{3}/2)$},
% below right/{$a(1/2,-\sqrt{3}/2)$}
% } {
% \draw [ultra thick,-latex,red] (Origin)
% -- (60*\i:2) coordinate (B\i) node [\pos] {\lbl};
% }
% \foreach \pos [count=\i from 0] in {Origin,B1,B2} {%
% \draw[line width=1mm,gray,-latex,shift=(\pos),rotate=120*\i]
% (0,-1)-- (0,1);
% }
\end{tikzpicture}
\end{document}[![enter image description here][1]][1]
答案2
欢迎使用 TeX.SE。使用起来\pgftransformcm
既方便又容易混淆。方便是因为您可以轻松绘制倾斜的格子,而混淆是因为您现在必须忍受这些格子。我将您的代码放在一个范围内以逃离格子,然后添加箭头。从您的绘图来看,方向对我来说并不明显。我还添加了缺失的虚线。
\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-3,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-2);
\coordinate (YAxisMax) at (0,5);
\draw [thin, gray,-latex] (XAxisMin) -- (XAxisMax) node[right] {$x$};% Draw x axis
\draw [thin, gray,-latex] (YAxisMin) -- (YAxisMax) node[above] {$z$} ;% Draw y axis
\clip (-4,-3) rectangle (5cm,5cm); % Clips the picture...
\begin{scope} %<- added
\pgftransformcm{1}{0}{1/2}{sqrt(3)/2}{\pgfpoint{0cm}{0cm}}
\coordinate (Bone) at (0,2);
\coordinate (Btwo) at (2,-2);
\draw[style=help lines,dashed] (-6,-6) grid[step=2cm] (6,6);
\foreach \x in {-4,-3,...,4}{% Two indices running over each
\foreach \y in {-4,-3,...,4}{% node on the grid we have drawn
\coordinate (Dot\x\y) at (2*\x,2*\y);
\node[draw,circle,inner sep=2pt,fill] at (Dot\x\y) {};
}
}
\draw [ultra thick,-latex,red] (Origin)
-- (Bone) node [above right] {$a(1/2,0,\sqrt{3}/2)$};
\draw [ultra thick,-latex,red] (Origin)
-- (Btwo) node [below right] {$a(1/2,0,-\sqrt{3}/2)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($(Bone)+(Btwo)$) node [below right] {$a(1,0,0)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($-1*(Bone)-1*(Btwo)$) node [below left] {$a(-1,0,0)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($-1*(Btwo)$) coordinate (B3) node [above left] {$a(-1/2,0,\sqrt{3}/2)$};
\draw [ultra thick,-latex,red] (Origin)
-- ($-1*(Bone)$) node [below left] {$a(-1/2,0,-\sqrt{3}/2)$};
% all the following is added
\end{scope}
\begin{scope}
\pgftransformcm{1}{0}{-1/2}{sqrt(3)/2}{\pgfpoint{0cm}{0cm}}
\draw[style=help lines,dashed] (-6,-6) grid[step=2cm] (6,6);
\end{scope}
\begin{scope}
\foreach \x in {-4,-3,...,4}{% Two indices running over each
\foreach \y in {-4,-3,...,4}{% node on the grid we have drawn
\pgfmathtruncatemacro{\X}{mod(50+\x-\y,3))}
\ifcase\X
\draw[ultra thick,-latex,blue,shift=(Dot\x\y.center),
rotate around={210:(Dot\x\y.center)}] (-0.5,0) -- (0.5,0);
\or
\draw[ultra thick,-latex,red,shift=(Dot\x\y.center),
rotate around={-30:(Dot\x\y.center)}]
(-0.5,0) -- (0.5,0);
\or
\draw[ultra thick,-latex,black,shift=(Dot\x\y.center),
rotate around={90:(Dot\x\y.center)}]
(-0.5,0) -- (0.5,0);
\fi
}
}
\draw[line width=1mm,gray,-latex] ($(Origin)-(0,1cm)$)-- ($(Origin)+(0,1cm)$);
\draw[line width=1mm,gray,-latex,rotate around={120:(Bone)}]
($(Bone)-(0,1cm)$)-- ($(Bone)+(0,1cm)$);
\draw[line width=1mm,gray,-latex,rotate around={-120:(B3)}]
($(B3)-(0,1cm)$)-- ($(B3)+(0,1cm)$);
\end{scope}
\end{tikzpicture}
\end{document}
更新:使附加网格线与图片一致,谢谢@Tarass。我误读了问题,我以为原帖者不想要等边三角形格子。并添加了箭头。