画一个网球场

画一个网球场

带小路的网球场

我是 TikZ 的新手,我不知道如何绘制如此复杂的区域。我只知道绘制一个矩形,如下所示:

\tikz \draw[fill=brown] (0,0) rectangle (10,5) (1cm);

答案1

您可能想要pic为此定义一个。我只是从 Wikipedia 复制了尺寸并​​用它们来定义图片tennis court。对于玩家来说,实际上没有太多选择,只有 15 个,在休眠时间之外将是 16 个。这还安装了一个本地坐标系,使放置玩家更容易,(-1,-1)即左下角和(1,1)右上角。编辑:添加了中心服务线,非常感谢 Fortega。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,angles}
\usepackage{tikzlings}
\newsavebox\Koala
\newsavebox\Penguin
\sbox\Koala{\tikz{\koala[cricket=blue,scale=0.5]}}
\sbox\Penguin{\tikz{\penguin[cricket=red,scale=0.5]}}
\tikzset{pics/tennis court/.style={code={
 \def\pv##1{\pgfkeysvalueof{/tikz/tennis court/##1}}
 \path[tennis court/back] (-1.2*\pv{scale}*11.98,-1.4*\pv{scale}*10.97/2) 
    rectangle ++ (1.2*\pv{scale}*2*11.98,1.4*\pv{scale}*10.97);
 \path[tennis court/markers,line width=2mm*\pv{scale},tennis court/surface] 
    (-11.98*\pv{scale},-10.97*\pv{scale}/2) 
        rectangle ++ (2*\pv{scale}*11.98,10.97*\pv{scale});
  \path[tennis court/markers,line width=1.5mm*\pv{scale}] 
   (-11.98*\pv{scale},-8.23*\pv{scale}/2) -- 
   (11.98*\pv{scale},-8.23*\pv{scale}/2)
   (-11.98*\pv{scale},8.23*\pv{scale}/2) -- 
   (11.98*\pv{scale},8.23*\pv{scale}/2)
   (-6.4*\pv{scale},-8.23*\pv{scale}/2) -- (-6.4*\pv{scale},8.23*\pv{scale}/2)
   (-6.4*\pv{scale},0) -- (6.4*\pv{scale},0)
   (6.4*\pv{scale},-8.23*\pv{scale}/2) -- (6.4*\pv{scale},8.23*\pv{scale}/2)
   (-11.98*\pv{scale},0) -- (-11.5*\pv{scale},0)
   (11.98*\pv{scale},0) -- (11.5*\pv{scale},0);
  \path[tennis court/net,line width=1mm*\pv{scale}]
  (0,-1.1*\pv{scale}*10.97/2) circle[radius=1.5mm*\pv{scale}]
   --    (0,1.1*\pv{scale}*10.97/2) circle[radius=1.5mm*\pv{scale}];
  \path (0,0) coordinate(-center)
    (11.98*\pv{scale},0) coordinate(-X)
    (0,10.97*\pv{scale}/2) coordinate(-DY)
    (0,8.23*\pv{scale}/2) coordinate(-SY);
}},
tennis court/.cd,surface/.style={fill=green!80!black},
back/.style={fill=green!60!black},
markers/.style={draw=white},scale/.initial=0.5,
net/.style={draw=orange,fill=orange}}
\begin{document}
\begin{tikzpicture}
 \pic (center court) {tennis court};
 \begin{scope}[shift={(center court-center)},
    x={($(center court-X)-(center court-center)$)},
    y={($(center court-SY)-(center court-center)$)},
    text=white,font=\large\sffamily]
  \path (-1.1,-0.4) node[label=below:B](B){\usebox\Koala};
  \draw[thick,orange!80!red,shorten >=-4cm] (B) -- (0,1) coordinate(t);
  \draw[thick,orange!80!red,shorten >=-4cm] (B) -- (0,-1) coordinate(b);
  \path let \p1=($(t)-(B)$),\p2=($(b)-(B)$),
    \n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)}
    in ($(B)+(\n1/2+\n2/2:2cm)$) coordinate (aux)
    (intersection cs:first line={(B)--(aux)}, second line={(1.1,-1)--(1.1,1)})
    node[label=below:A](A){\usebox\Penguin};
  \draw[ultra thick,red]    (B)--(A);
  \pic[draw,thick,angle radius=2cm] {angle=A--B--t};
  \pic[draw,thick,angle radius=2.2cm] {angle=b--B--A};
 \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

企鹅根据考拉的位置选择自己的位置。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,angles}
\usepackage{tikzlings}
\newsavebox\Koala
\newsavebox\Penguin
\sbox\Koala{\tikz{\koala[cricket=blue,scale=0.5]}}
\sbox\Penguin{\tikz{\penguin[cricket=red,scale=0.5]}}
\tikzset{pics/tennis court/.style={code={
 \def\pv##1{\pgfkeysvalueof{/tikz/tennis court/##1}}
 \path[tennis court/back] (-1.2*\pv{scale}*11.98,-1.4*\pv{scale}*10.97/2) 
    rectangle ++ (1.2*\pv{scale}*2*11.98,1.4*\pv{scale}*10.97);
 \path[tennis court/markers,line width=2mm*\pv{scale},tennis court/surface] 
    (-11.98*\pv{scale},-10.97*\pv{scale}/2) 
        rectangle ++ (2*\pv{scale}*11.98,10.97*\pv{scale});
  \path[tennis court/markers,line width=1.5mm*\pv{scale}] 
   (-11.98*\pv{scale},-8.23*\pv{scale}/2) -- 
   (11.98*\pv{scale},-8.23*\pv{scale}/2)
   (-11.98*\pv{scale},8.23*\pv{scale}/2) -- 
   (11.98*\pv{scale},8.23*\pv{scale}/2)
   (-6.4*\pv{scale},-8.23*\pv{scale}/2) -- (-6.4*\pv{scale},8.23*\pv{scale}/2)
   (6.4*\pv{scale},-8.23*\pv{scale}/2) -- (6.4*\pv{scale},8.23*\pv{scale}/2)
   (-6.4*\pv{scale},0) -- (6.4*\pv{scale},0)
   (-11.98*\pv{scale},0) -- (-11.5*\pv{scale},0)
   (11.98*\pv{scale},0) -- (11.5*\pv{scale},0);
  \path[tennis court/net,line width=1mm*\pv{scale}]
  (0,-1.1*\pv{scale}*10.97/2) circle[radius=1.5mm*\pv{scale}]
   --    (0,1.1*\pv{scale}*10.97/2) circle[radius=1.5mm*\pv{scale}];
  \path (0,0) coordinate(-center)
    (11.98*\pv{scale},0) coordinate(-X)
    (0,10.97*\pv{scale}/2) coordinate(-DY)
    (0,8.23*\pv{scale}/2) coordinate(-SY);
}},
tennis court/.cd,surface/.style={fill=green!80!black},
back/.style={fill=green!60!black},
markers/.style={draw=white},scale/.initial=0.5,
net/.style={draw=orange,fill=orange}}
\begin{document}
\foreach \X in {0,10,...,350}
{\begin{tikzpicture}
 \pic (center court) {tennis court};
 \begin{scope}[shift={(center court-center)},
    x={($(center court-X)-(center court-center)$)},
    y={($(center court-SY)-(center court-center)$)},
    text=white,font=\large\sffamily]
  \path (-1.1,{0.6*sin(\X)})    node[label=below:B](B){\usebox\Koala};
  \draw[thick,orange!80!red,shorten >=-4cm] (B) -- (0,1) coordinate(t);
  \draw[thick,orange!80!red,shorten >=-4cm] (B) -- (0,-1) coordinate(b);
  \path let \p1=($(t)-(B)$),\p2=($(b)-(B)$),
    \n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)}
    in ($(B.center)+({\n1/2+\n2/2}:2cm)$)coordinate(aux)
    (intersection cs:first line={(B)--(aux)}, second line={(1.1,-1)--(1.1,1)})
    node[label=below:A](A){\usebox\Penguin};
  \draw[ultra thick,red]    (B)--(A);
  \draw[ultra thick,red]    (B)--(aux);
  \pic[draw,thick,angle radius=2cm] {angle=A--B--t};
  \pic[draw,thick,angle radius=2.2cm] {angle=b--B--A};
 \end{scope}
\end{tikzpicture}}
\end{document}

在此处输入图片描述

这表明企鹅很聪明(不仅仅是发明了 Linux ;-))。

相关内容