TikZ:合并区域

TikZ:合并区域

我需要创建一个由多个部分组成的区域,但周围有一个边框,如下图所示。我尝试了许多不同的方法,但都不令人满意——在这个例子中,由于覆盖的“填充”,圆的线条被切断了一半。

唯一能正常工作的方法是使用交叉点,但每次处理文档时,这都会花费几秒钟的时间,非常烦人。虽然“奇偶规则”允许删除某些部分,但我想,也许还有一种合并的方法。

此外,牙齿的外缘也应是圆形的。

输出

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\def \rotor {
    (0, 0) circle (1)
    (0, 0) circle (2)
}

\startscope[even odd rule]
  \draw \rotor;
  \foreach \x in {1, ..., 6}
  {
    \draw[rotate=(\x-1)*60, fill=lightgray]
    (1, -0.3)   rectangle (3, 0.3);
  }
  \fill[lightgray] \rotor;
\stopscope

\end{tikzpicture}
\end{document}

答案1

更新:(2014/03/17) :根据 OP 的评论,第一个答案不是我想要的。我感到自己有义务再次尝试解决 OP 的担忧,即(每个牙齿的)外边缘应该是以 (0,0) 为中心的圆弧,就像里面的两个圆一样,第一次尝试只是rounded corner为每个矩形牙齿做一个。

注意:可以通过将第 24 行和第 31 行中\draw的替换为 来删除用于演示的蓝线和红线。\path

在此处输入图片描述

代码:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,intersections,calc}

\begin{document}

\begin{tikzpicture}
\def \rotor {
   [name path=curve] (0, 0) circle (2)
   (0, 0) circle (1)
}

\startscope[even odd rule]
\foreach \x in {1, ..., 6}
  {
    \path[rotate=(\x-1)*60]  (0,0) -- ++ (-10:3)   
                             (0,0) -- ++ (10:3)  
                             (0,0) -- ++(-10:3) arc (-10:10:3);          % generate the arc section of a tooth
  }

\draw[fill=lightgray] \rotor;

\foreach \x in {1,...,6}
  { \draw[red,rotate=(\x-1)*60,name path=line \x]  (0,0) -- ++ (-20:3);  % Adjust this angle -10,-20, ... for all  kind of tooth
    \path[name intersections={of=curve and line \x, by={isect \x}}];
    \draw[rotate=(\x-1)*60,fill=lightgray]
    (isect \x) -- (-10:3) arc (-10:10:3) -- (20:2);                      % Adjust the last coordinate accordingly
  }

\foreach \x in {1,...,6}
  { \draw[blue,rotate=(\x-1)*60,name path=line \x]  (0,0) -- ++ (20:3);  % Adjust this angle 10, 20, ... for all  kind of tooth
    \path[name intersections={of=curve and line \x, by={isect \x}}];
    \draw[rotate=(\x-1)*60,fill=lightgray]
    (isect \x) --  (10:3) arc (10:-10:3) --(-20:2);                       % Adjust the last coordinate accordingly
  }
\stopscope
\end{tikzpicture}

\end{dcument}

研究了两种方法。左侧方法没有使用intersection包装,而右侧方法借助intersection包装找到牙根的插入点

在此处输入图片描述

代码

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,intersections,calc}

\begin{document}

% -- Do not use intersection package

\begin{tikzpicture}
\def \rotor {
    (0, 0) circle (1)
    (0, 0) circle (2)
}
\startscope[even odd rule]
\foreach \x in {1, ..., 6}
  {
    \draw[rotate=(\x-1)*60,rounded corners]
    (1.5, -0.3) rectangle (3, 0.3);
  }
\draw[fill=lightgray] \rotor;

\foreach \x in {1,...,6}
  { %\path[rotate=(\x-1)*60,name path=line \x] (1.5,-0.3) -- (3,-0.3);
    %\path[name intersections={of=curve and line \x, by={isect \x}}];
    \draw[rotate=(\x-1)*60,fill=lightgray,rounded corners]
    (1.97,-0.3) -- (3,-0.3) -- (3, 0.3) -- (1.97,0.3);   % knowing that it is cloe dotse to 2, so manually to determine 1.97, 
    %(isect \x) -- (3,-0.3) -- (3, 0.3) -- ($(isect \x)+(0,0.6)$);
  }
\stopscope
\end{tikzpicture}


% -- Use of insetection package

\begin{tikzpicture}
\def \rotor {
    (0, 0) circle (1)
   [name path=curve] (0, 0) circle (2)
}

\startscope[even odd rule]
\foreach \x in {1, ..., 6}
  {
    \draw[rotate=(\x-1)*60,rounded corners]
    (1.5, -0.3) rectangle (3, 0.3);
  }
\draw[fill=lightgray] \rotor;

\foreach \x in {1,...,6}
  { \path[rotate=(\x-1)*60,name path=line \x] (1.5,-0.3) -- (3,-0.3);
    \path[name intersections={of=curve and line \x, by={isect \x}}];
    \draw[rotate=(\x-1)*60,fill=lightgray,rounded corners]
    (isect \x) -- (3,-0.3) -- (3, 0.3) -- ($(isect \x)+(0,0.6)$);
  }
\stopscope
\end{tikzpicture}

\end{document}

相关内容