如何在倾斜的正方形上画网格ABCD
?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1,line join=round,font=\small]
\draw[lightgray] (0,0) grid (7,7);
\coordinate[label=below:$A$] (A) at (4,0);
\coordinate[label=right:$B$] (B) at (7,4);
\coordinate[label=above:$C$] (C) at (3,7);
\coordinate[label=left:$D$] (D) at (0,3);
\draw[thick] (A)--(B)--(C)--(D)--cycle;
\end{tikzpicture}
\end{document}
我的意思就是像这样。
答案1
正方形内部的旋转网格可以通过部分修饰符给出的坐标绘制:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=1,line join=round,font=\small]
\coordinate[label=below:$A$] (A) at (4,0);
\coordinate[label=right:$B$] (B) at (7,4);
\coordinate[label=above:$C$] (C) at (3,7);
\coordinate[label=left:$D$] (D) at (0,3);
\draw[lightgray]
(0, 0) grid (7, 7)
\foreach \i in {1, ..., 4} {
($(A)!\i/5!(B)$) -- ($(D)!\i/5!(C)$)
($(B)!\i/5!(C)$) -- ($(A)!\i/5!(D)$)
}
;
\draw[thick] (A)--(B)--(C)--(D)--cycle;
\end{tikzpicture}
\end{document}
答案2
A元帖子替代方案(仅用于比较)。使用 进行编译lualatex
。
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path box[];
box0 = unitsquare shifted -(1/2,1/2);
box1 = box0 scaled 7cm;
box2 = box0 scaled 5cm rotated angle (3,4);
vardef draw_grid(expr Q,N) =
for t=1 upto N-1:
draw point t/N of Q -- point 3-t/N of Q;
draw point 1+t/N of Q -- point 4-t/N of Q;
endfor
enddef;
drawoptions(withcolor 2/3 white);
draw_grid(box1,7);
draw_grid(box2,5);
drawoptions();
draw box1;
draw box2;
label.bot("$A$", point 0 of box2);
label.rt ("$B$", point 1 of box2);
label.top("$C$", point 2 of box2);
label.lft("$D$", point 3 of box2);
endfig;
\end{mplibcode}
\end{document}