填充 tikzpicture 中的区域

填充 tikzpicture 中的区域

我使用 geogebra 完成了此操作,然后复制代码并生成绘图。我不知道如何填充某些区域以使其看起来像我添加的图片。 在此处输入图片描述

\documentclass[10pt]{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.35cm,y=0.35cm]
\clip(-2.6084198246281884,-1.775158614705993) rectangle (39.01911524098169,25.132373556978752);
\draw [line width=1pt,color=black] (0,0)-- (0,6);
\draw [line width=1pt,color=black] (0,6)-- (1,6);
\draw [line width=1pt,color=black] (2,6)-- (3,6);
\draw [line width=1pt,color=black] (3,6)-- (3,9);
\draw [line width=1pt,color=black] (4,6)-- (5,6);
\draw [line width=1pt,color=black] (5,0)-- (5,6);
\draw [line width=1pt,color=black] (4,6)-- (4,8);
\draw [line width=1pt,color=black] (7,0)-- (7,6);
\draw [line width=1pt,color=black] (8,6)-- (7,6);
\draw [line width=1pt,color=black] (8,6)-- (8,10);
\draw [line width=1pt,color=black] (9,6)-- (10,6);
\draw [line width=1pt,color=black] (10,6)-- (10,8);
\draw [line width=1pt,color=black] (11,6)-- (11,8);
\draw [line width=1pt,color=black] (11,6)-- (12,6);
\draw [line width=1pt,color=black] (12,6)-- (12,0);
\draw [line width=1pt,color=black] (9,6)-- (9,10);
\draw [line width=1pt,color=black] (1,6)-- (1,11);
\draw [line width=1pt,color=black] (2,6)-- (2,10);
\draw [line width=1pt,color=black] (2,10)-- (8,10);
\draw [line width=1pt,color=black] (1,11)-- (28,11);
\draw [line width=1pt,color=black] (9,10)-- (15,10);
\draw [line width=1pt,color=black] (14,0)-- (14,6);
\draw [line width=1pt,color=black] (15,6)-- (14,6);
\draw [line width=1pt,color=black] (15,6)-- (15,10);
\draw [line width=1pt,color=black] (16,10)-- (16,6);
\draw [line width=1pt,color=black] (16,6)-- (17,6);
\draw [line width=1pt,color=black] (18,6)-- (19,6);
\draw [line width=1pt,color=black] (19,6)-- (19,0);
\draw [line width=1pt,color=black] (21,0)-- (21,6);
\draw [line width=1pt,color=black] (21,6)-- (22,6);
\draw [line width=1pt,color=black] (22,6)-- (22,10);
\draw [line width=1pt,color=black] (23,10)-- (23,6);
\draw [line width=1pt,color=black] (23,6)-- (24,6);
\draw [line width=1pt,color=black] (25,6)-- (26,6);
\draw [line width=1pt,color=black] (26,6)-- (26,0);
\draw [line width=1pt,color=black] (16,10)-- (22,10);
\draw [line width=1pt,color=black] (23,10)-- (29,10);
\draw [line width=1pt,color=black] (3,9)-- (8,9);
\draw [line width=1pt,color=black] (4,8)-- (8,8);
\draw [line width=1pt,color=black] (9,9)-- (15,9);
\draw [line width=1pt,color=black] (16,9)-- (22,9);
\draw [line width=1pt,color=black] (28,11)-- (28,15);
\draw [line width=1pt,color=black] (29,10)-- (29,15);
\draw [line width=1pt,color=black] (23,9)-- (34,9);
\draw [line width=1pt,color=black] (28,15)-- (26,17);
\draw [line width=1pt,color=black] (26,17)-- (26,20);
\draw [line width=1pt,color=black] (26,20)-- (29,23);
\draw [line width=1pt,color=black] (29,23)-- (29,22);
\draw [line width=1pt,color=black] (29,15)-- (29,22);
\draw [line width=1pt,color=black] (29,19)-- (34,19);
\draw [line width=1pt,color=black] (29,18)-- (34,18);
\draw [line width=1pt,color=black] (34,23)-- (34,19);
\draw [line width=1pt,color=black] (34,18)-- (34,15);
\draw [line width=1pt,color=black] (34,23)-- (37,20);
\draw [line width=1pt,color=black] (37,20)-- (37,17);
\draw [line width=1pt,color=black] (37,17)-- (35,15);
\draw [line width=1pt,color=black] (34,15)-- (34,9);
\draw [line width=1pt,color=black] (35,15)-- (35,8);
\draw [line width=1pt,color=black] (0,4)-- (1.6,4);
\draw [line width=1pt,color=black] (1.6,4)-- (1.6,0);
\draw [line width=1pt,color=black] (3.4,0)-- (3.4,4);
\draw [line width=1pt,color=black] (3.4,4)-- (5,4);
\draw [line width=1pt,color=black] (7,2)-- (8.6,2);
\draw [line width=1pt,color=black] (8.6,2)-- (8.597289004768815,-0.00494417061539465);
\draw [line width=1pt,color=black] (12,2)-- (10.4,2);
\draw [line width=1pt,color=black] (10.4,2)-- (10.4,0);
\draw [line width=1pt,color=black] (7,4)-- (12,4);
\draw [line width=1pt,color=black] (14,4)-- (19,4);
\draw [line width=1pt,color=black] (14,2)-- (15.6,2);
\draw [line width=1pt,color=black] (15.6,2)-- (15.6,0);
\draw [line width=1pt,color=black] (19,2)-- (17.4,2);
\draw [line width=1pt,color=black] (17.4,2)-- (17.4,0);
\draw [line width=1pt,color=black] (21,4)-- (22.6,4);
\draw [line width=1pt,color=black] (26,4)-- (24.4,4);
\draw [line width=1pt,color=black] (24.4,4)-- (24.4,0);
\draw [line width=1pt,color=black] (22.6,4)-- (22.6,0);
\draw (27,19) node[anchor=north west] {T};
\draw (35,19) node[anchor=north west] {C};
\draw [line width=1pt,color=black] (9,8.006521194140134)-- (10,8);
\draw [line width=1pt,color=black] (11,8)-- (15,8.006521194140134);
\draw [line width=1pt,color=black] (17,6)-- (17,8);
\draw [line width=1pt,color=black] (16,8)-- (17,8);
\draw [line width=1pt,color=black] (18,6)-- (18,8);
\draw [line width=1pt,color=black] (22,8)-- (18,8);
\draw [line width=1pt,color=black] (24,6)-- (24,8);
\draw [line width=1pt,color=black] (23,8.023862255462648)-- (24,8);
\draw [line width=1pt,color=black] (25,6)-- (25,8);
\draw [line width=1pt,color=black] (25,8)-- (35,8);
\draw [line width=1pt,color=black] (34,18)-- (34,19);
\draw [line width=1pt,color=black] (1,6)-- (2,6);
\draw [line width=1pt,color=black] (3,6)-- (4,6);
\draw [line width=1pt,color=black] (22,6)-- (23,6);
\draw [line width=1pt,color=black] (24,6)-- (25,6);

\end{tikzpicture}
\end{document}

答案1

如果 geogebra 没有填充颜色的选项,那么您必须绘制连续的封闭路径以填充所需的颜色/图案。您可以绘制网格线以找到精确的坐标并绘制这些路径。以下是示例:

在此处输入图片描述

我使用了两组网格线 - 一组间距为 1(黑色),另一组间距为 5(红色)。使用以下命令。

\draw[step=1.0,thin,gray] (-2,-1) grid (40,26);
\draw[step=5.0,red] (-2,-1) grid (40,26);

使用这些网格,我找到了坐标并填充了一小部分。我希望您借助此代码完成剩余部分。您可以在最终版本中删除网格线。完整代码如下。

\documentclass[10pt]{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.35cm,y=0.35cm]
\draw[step=1.0,thin,gray] (-2,-1) grid (40,26);
\draw[step=5.0,red] (-2,-1) grid (40,26);
\clip(-2.6084198246281884,-1.775158614705993) rectangle (39.01911524098169,25.132373556978752);
\draw [line width=1pt,color=black] (0,0)-- (0,6);
\draw [line width=1pt,color=black] (0,6)-- (1,6);
\draw [line width=1pt,color=black] (2,6)-- (3,6);
\draw [line width=1pt,color=black] (3,6)-- (3,9);
\draw [line width=1pt,color=black] (4,6)-- (5,6);
\draw [line width=1pt,color=black] (5,0)-- (5,6);
\draw [line width=1pt,color=black] (4,6)-- (4,8);
\draw [line width=1pt,color=black] (7,0)-- (7,6);
\draw [line width=1pt,color=black] (8,6)-- (7,6);
\draw [line width=1pt,color=black] (8,6)-- (8,10);
\draw [line width=1pt,color=black] (9,6)-- (10,6);
\draw [line width=1pt,color=black] (10,6)-- (10,8);
\draw [line width=1pt,color=black] (11,6)-- (11,8);
\draw [line width=1pt,color=black] (11,6)-- (12,6);
\draw [line width=1pt,color=black] (12,6)-- (12,0);
\draw [line width=1pt,color=black] (9,6)-- (9,10);
\draw [line width=1pt,color=black] (1,6)-- (1,11);
\draw [line width=1pt,color=black] (2,6)-- (2,10);
\draw [line width=1pt,color=black] (2,10)-- (8,10);
\draw [line width=1pt,color=black] (1,11)-- (28,11);
\draw [line width=1pt,color=black] (9,10)-- (15,10);
\draw [line width=1pt,color=black] (14,0)-- (14,6);
\draw [line width=1pt,color=black] (15,6)-- (14,6);
\draw [line width=1pt,color=black] (15,6)-- (15,10);
\draw [line width=1pt,color=black] (16,10)-- (16,6);
\draw [line width=1pt,color=black] (16,6)-- (17,6);
\draw [line width=1pt,color=black] (18,6)-- (19,6);
\draw [line width=1pt,color=black] (19,6)-- (19,0);
\draw [line width=1pt,color=black] (21,0)-- (21,6);
\draw [line width=1pt,color=black] (21,6)-- (22,6);
\draw [line width=1pt,color=black] (22,6)-- (22,10);
\draw [line width=1pt,color=black] (23,10)-- (23,6);
\draw [line width=1pt,color=black] (23,6)-- (24,6);
\draw [line width=1pt,color=black] (25,6)-- (26,6);
\draw [line width=1pt,color=black] (26,6)-- (26,0);
\draw [line width=1pt,color=black] (16,10)-- (22,10);
\draw [line width=1pt,color=black] (23,10)-- (29,10);
\draw [line width=1pt,color=black] (3,9)-- (8,9);
\draw [line width=1pt,color=black] (4,8)-- (8,8);
\draw [line width=1pt,color=black] (9,9)-- (15,9);
\draw [line width=1pt,color=black] (16,9)-- (22,9);
\draw [line width=1pt,color=black] (28,11)-- (28,15);
\draw [line width=1pt,color=black] (29,10)-- (29,15);
\draw [line width=1pt,color=black] (23,9)-- (34,9);
\draw [line width=1pt,color=black] (28,15)-- (26,17);
\draw [line width=1pt,color=black] (26,17)-- (26,20);
\draw [line width=1pt,color=black] (26,20)-- (29,23);
\draw [line width=1pt,color=black] (29,23)-- (29,22);
\draw [line width=1pt,color=black] (29,15)-- (29,22);
\draw [line width=1pt,color=black] (29,19)-- (34,19);
\draw [line width=1pt,color=black] (29,18)-- (34,18);
\draw [line width=1pt,color=black] (34,23)-- (34,19);
\draw [line width=1pt,color=black] (34,18)-- (34,15);
\draw [line width=1pt,color=black] (34,23)-- (37,20);
\draw [line width=1pt,color=black] (37,20)-- (37,17);
\draw [line width=1pt,color=black] (37,17)-- (35,15);
\draw [line width=1pt,color=black] (34,15)-- (34,9);
\draw [line width=1pt,color=black] (35,15)-- (35,8);
\draw [line width=1pt,color=black] (0,4)-- (1.6,4);
\draw [line width=1pt,color=black] (1.6,4)-- (1.6,0);
\draw [line width=1pt,color=black] (3.4,0)-- (3.4,4);
\draw [line width=1pt,color=black] (3.4,4)-- (5,4);
\draw [line width=1pt,color=black] (7,2)-- (8.6,2);
\draw [line width=1pt,color=black] (8.6,2)-- (8.597289004768815,-0.00494417061539465);
\draw [line width=1pt,color=black] (12,2)-- (10.4,2);
\draw [line width=1pt,color=black] (10.4,2)-- (10.4,0);
\draw [line width=1pt,color=black] (7,4)-- (12,4);
\draw [line width=1pt,color=black] (14,4)-- (19,4);
\draw [line width=1pt,color=black] (14,2)-- (15.6,2);
\draw [line width=1pt,color=black] (15.6,2)-- (15.6,0);
\draw [line width=1pt,color=black] (19,2)-- (17.4,2);
\draw [line width=1pt,color=black] (17.4,2)-- (17.4,0);
\draw [line width=1pt,color=black] (21,4)-- (22.6,4);
\draw [line width=1pt,color=black] (26,4)-- (24.4,4);
\draw [line width=1pt,color=black] (24.4,4)-- (24.4,0);
\draw [line width=1pt,color=black] (22.6,4)-- (22.6,0);
\draw (27,19) node[anchor=north west] {T};
\draw (35,19) node[anchor=north west] {C};
\draw [line width=1pt,color=black] (9,8.006521194140134)-- (10,8);
\draw [line width=1pt,color=black] (11,8)-- (15,8.006521194140134);
\draw [line width=1pt,color=black] (17,6)-- (17,8);
\draw [line width=1pt,color=black] (16,8)-- (17,8);
\draw [line width=1pt,color=black] (18,6)-- (18,8);
\draw [line width=1pt,color=black] (22,8)-- (18,8);
\draw [line width=1pt,color=black] (24,6)-- (24,8);
\draw [line width=1pt,color=black] (23,8.023862255462648)-- (24,8);
\draw [line width=1pt,color=black] (25,6)-- (25,8);
\draw [line width=1pt,color=black] (25,8)-- (35,8);
\draw [line width=1pt,color=black] (34,18)-- (34,19);
\draw [line width=1pt,color=black] (1,6)-- (2,6);
\draw [line width=1pt,color=black] (3,6)-- (4,6);
\draw [line width=1pt,color=black] (22,6)-- (23,6);
\draw [line width=1pt,color=black] (24,6)-- (25,6);

\fill[red,opacity=0.5] (29,23) -- (26,20) -- (26,17) -- (28,15) --(28,11) -| (1,6) -- (2,6) -- (2,10) -| (29,23) ;
\end{tikzpicture}
\end{document}

相关内容