带有圆弧的松散边界框

带有圆弧的松散边界框

考虑以下 MWE:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[blue] (current bounding box.south west) rectangle 
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[red] (200:1)  arc (200:320:1);
   \draw[blue] (current bounding box.south west) rectangle 
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[green] (320:1)  arc (320:560:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \draw[green] (320:1)  arc (320:560:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[green] (320:1)  arc (320:560:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}

\end{document}

我希望边界框能够紧密贴合圆弧。但是,图片显示了不同的行为。我相信这里有专家可以向我解释为什么会发生这种情况......

在此处输入图片描述

答案1

当 TikZ 计算圆弧的边界框时,它使用起点、终点和控制考虑贝塞尔曲线的点。控制点通常位于圆弧之外。

以下示例通过重置边界框\pgfresetboundingbox并使用\draw无线的命令再次设置它来修复边界框,其中的点定义了边界框。\draw代替\path\useasboundingbox,因为它还考虑了线宽。

\documentclass[border=5pt]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[red] (200:1)  arc (200:320:1);
   \pgfresetboundingbox
   \draw (-1, -1) (1, 1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw (0,0)  circle (1);
   \draw[green] (320:1)  arc (320:560:1);
   \pgfresetboundingbox
   \draw (-1, -1) (1, 1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \draw[green] (320:1)  arc (320:560:1);
   \pgfresetboundingbox
   \draw (-1, -1) (1, 1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[green] (320:1)  arc (320:560:1);
   \pgfresetboundingbox
   \draw (-1, 1) (1, 0) (320:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}\quad
%
\begin{tikzpicture}
   \draw[red] (200:1)  arc (200:320:1);
   \pgfresetboundingbox
   \draw (0, -1) (200:1) (320:1);
   \draw[blue] (current bounding box.south west) rectangle
        (current bounding box.north east);
\end{tikzpicture}

\end{document}

结果

相关内容