靠墙的栅栏

靠墙的栅栏

我有以下代码。我想要一堵墙和一个矩形,但这看起来不太好。我希望它更好,即三维的,这样看起来会更好。我的意思是一堵立墙。我该怎么做呢?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\definecolor{brickcolor}{HTML}{F0D8B2}
\begin{document}

\usetikzlibrary {patterns}
\def\wall{ \fill     [fill=brickcolor]  (0,-1) rectangle (8,.5);
           \pattern  [pattern=bricks,pattern color=white] (0,-1) rectangle (8,.5);
          }

\begin{tikzpicture}
\draw[red, very thick, text=black](2,0)--node[above left]{$x$}(2,2)--node[above]{$y$}(6,2)--node[above right]{$x$}(6,0 );
  \wall
\end{tikzpicture}

\end{document}

答案1

你可以使用 TiZ3d库中的canvas is...选项。这些选项可让您在与坐标平面平行的任何平面上进行绘制。然后进行几个剪辑,您就拥有了它。

更新:我没办法。这需要一只鸭子!!!

像这样:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{3d,perspective}
\usetikzlibrary{ducks} % only for the duck, obviously

\definecolor{brickcolor}{HTML}{F0D8B2}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,3d view={210}{20}]
% wall
\begin{scope}[canvas is xz plane at y=0]
  \clip (-3.99,0) rectangle (3.99,2.5);
  \foreach\y in {0,...,9} \foreach\x in {-8,...,8}
    \fill[brickcolor] ({0.5*\x-0.24-0.25*mod(\y,2)},0.25*\y) rectangle ++ (0.48,0.23);
\end{scope}
% duck
\draw[canvas is xz plane at y=1] (1,0) pic[duck/water=blue!50,scale=0.25] {duck};
% fence, x
\foreach\i in {-2,2}
{
  \begin{scope}[canvas is yz plane at x=\i,green!50!black]
    \draw[thick] (0,0) rectangle (2,2);
    \clip (0,0) rectangle (2,2);
    \foreach\x in {-3.8,-3.6,...,1.8}
      \draw (\x,0) --++ (2,2) --++ (2,-2);
  \end{scope}
}
\node[below] at (-2,1) {$x$};
% fence, y
\begin{scope}[canvas is xz plane at y=2,green!50!black]
  \draw[thick] (-2,0) rectangle (2,2);
  \clip (-2,0) rectangle (2,2);
  \foreach\x in {-5.8,-5.6,...,1.8}
    \draw (\x,0) --++ (2,2) --++ (2,-2);
\end{scope}
\node[below] at (0,2) {$y$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容