将圆圈放在垂直矩形上 - Latex 中的机器人

将圆圈放在垂直矩形上 - Latex 中的机器人

我正在尝试用乳胶绘制这幅图,我从这个论坛收集了一些碎片信息,但是我无法找到将几何元素相互叠加以获得所需形状的方法。

设置

\documentclass[10pt]{beamer}
\input{headerBeamer}
\setbeamertemplate{caption}[numbered]
\graphicspath{{./drawings/}}
\title[short title]{XYZ}
\author{Abc}

\begin{document}
\begin{frame}
\begin{figure}
  \centering
  \includetikz{drawings/checkerboard.tikz}
\end{figure}
\end{frame}

\end{document}

棋盘格.tikz

\begin{tikzpicture}[scale=0.2]
\foreach \x in {0,...,8} \foreach \y in {0,...,5}
{
    \pgfmathparse{mod(\x+\y,2) ? "black" : "white"}
    \edef\colour{\pgfmathresult}
    \path[fill=\colour] (\x,\y) rectangle ++ (1,1);
}
\draw (0,0)--(0,6)--(9,6)--(9,0)--cycle;

\tikz \fill [black] (0.2,0.2) rectangle (1.8,0.8);
\tikz \fill [black,rotate around={-35:(-1,0.5)}] (0.2,0.2) rectangle (0.8,1.8);
\tikz \fill [black]   (0,0)     circle (2.5ex);
\tikz \fill [black]   (0,0)     circle (1.2ex);

\end{tikzpicture}

答案1

(我当然不知道里面有什么headerBeamer.tex,也不\includetikz知道是如何定义的,如果没有它们,你的例子会更好。依赖于我们没有的文件的示例并不理想。)

我觉得你的主要问题是你嵌套了tikzpictures ,而这通常不是一个好主意。\tikz ...是 的缩写形式\begin{tikzpicture} ...\end{tikzpicture}

如果删除所有\tikz宏,则所有坐标都将属于同一坐标系,然后移动物体只需更改坐标中的数字即可。即\tikz \fill (0,0) circle (1.2ex);,使用而不是\fill (x,y) circle (1.2ex);,其中您更改xy

不过,还有其他方法可以做类似的事情,下面展示了一种可能的方法。使用 s 绘制形状\node,并将它们相对于彼此定位。这可能更简单,因为不需要猜测坐标。

在此处输入图片描述

\documentclass[10pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
  blackrec/.style 2 args={fill=black,rectangle,minimum width=#1,minimum height=#2,inner sep=0pt},
  blackcirc/.style={fill=black,circle,inner sep=0pt,minimum size=#1}
}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}
\begin{scope}[scale=0.2]
\foreach \x in {0,...,8} \foreach \y in {0,...,5}
{
    \pgfmathparse{mod(\x+\y,2) ? "black" : "white"}
    \edef\colour{\pgfmathresult}
    \path[fill=\colour] (\x,\y) rectangle ++ (1,1);
}
\draw (0,0)--coordinate (checkerleftside)(0,6)--(9,6)--(9,0)--cycle;
\end{scope}
\node [blackrec={3mm}{4mm},fill=blue,left] (bluerec) at (checkerleftside) {};
\node [blackrec={4mm}{9mm},anchor=north east] (rec1) at (bluerec.north west) {};
\node [blackcirc=5mm,anchor=north] (circ1) at (rec1.south) {};
\node [blackrec={4mm}{9mm},anchor=north,rotate=-75] (rec2) at (circ1.185) {};
\node [blackcirc=5mm,anchor=15] (circ2) at (rec2.south) {};
\node [blackrec={4mm}{8mm},anchor=north] (rec3) at (circ2.south) {};
\node [blackrec={10mm}{5mm},anchor=north] (rec4) at (rec3.south) {};

\end{tikzpicture}
\end{frame}

\end{document}

答案2

装饰时间robot arm

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{robot arm}{draw first}{
\state{draw first}[width=\pgfdecoratedinputsegmentlength, next state=draw,
  persistent precomputation={%
    \def\x{\pgfdecoratedinputsegmentlength}
    \let\s=\pgfdecorationsegmentlength
    \let\a=\pgfdecorationsegmentamplitude}]{
  \fill [black] (0,-\s) rectangle (\s/2, \s);
  \fill [black] (\s/2,-\a/2) rectangle (\x-\s/2, \a/2);
}
\state{draw}[width=\x, switch if less than=\x+1 to final]{
  \fill [black] circle [radius=\s/2];
  \fill [black] (\s/2,-\a/2) rectangle (\x-\s/2, \a/2);
}
\state{final}{
  \fill [black] circle [radius=\s/2];
  \fill [black] (\s/2,-\a/2) rectangle (\x, \a/2);
  \fill [blue] (\x-\s, -\a/2) rectangle (\x, -3 * \a/2);
  \tikzset{shift={(\x-3*\s/2, -3 * \a/2)}, x=\s/2, y=\s/2}
  \foreach \i in {0,...,3}
    \foreach \j [evaluate={\o=mod(\i+\j,2)*100;}] in {0,...,3}{
      \draw [fill=black!\o!white] (\i,-\j) rectangle ++(1, -1);
}}}
\begin{document}
\begin{tikzpicture}
\path [decoration={robot arm, segment length=20pt, amplitude=10pt}, decorate] 
  (0,0) -- (0,3) -- ++(20:2) -- ++(80:1) -- ++(45:2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容