我正在尝试绘制一组圆盘的凸包,如下图所示这文章。
我所能做的就是手动计算点数(大约):
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=0.2]
\draw (-4,2) circle (2cm);
\draw (2,0) circle (7cm);
\draw (0,6) circle (4cm);
\draw (8,2) circle (2cm);
\draw (8,-6) circle (8cm);
\draw (4,-4) circle (6.1cm);
\node (G) at (-5.8, 2.8) {};
\node (H) at (-3.6, 7.6) {};
\node (I) at (2.7, 8.9) {};
\node (J) at (6.8, 5.1) {};
\node (K) at (9.1, 3.7) {};
\node (L) at (13.3, 0) {};
\node (M) at (1.8, -11.1) {};
\node (N) at (-0.7, -8) {};
\node (P) at (-0.9, -7.7) {};
\node (O) at (-3.6, -4.2) {};
\node (R) at (-4.6, -2.3) {};
\node (Q) at (-5.9, 1.3) {};
\draw[thick, red] (G)--(H) ;
\draw[thick, red] (I)--(K) ;
\draw[thick, red] (K)--(L) ;
\draw[thick, red] (M)--(N) ;
\draw[thick, red] (P)--(O) ;
\draw[thick, red] (R)--(Q) ;
\end{tikzpicture}
\end{document}
但它看起来很荒谬:
做到这一点最简单的方法是什么?
答案1
您可以定义一种样式,这样就可以像使用 一样轻松地绘制带有节点的圆圈\draw
。然后tangent cs
可以像 percusses 中所示那样使用关联。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=0.2]
\tikzset{onlycircle/.style={draw,circle,inner sep=0pt,outer sep=0pt,minimum width=2*#1,transform shape}}
\node[onlycircle=2cm] (A) at (-4, 2) {};
\node[onlycircle=7cm] (B) at ( 2, 0) {};
\node[onlycircle=4cm] (C) at ( 0, 6) {};
\node[onlycircle=2cm] (D) at ( 8, 2) {};
\node[onlycircle=8cm] (E) at ( 8,-6) {};
\node[onlycircle=6.1cm] (F) at ( 4,-4) {};
\draw[red] (tangent cs:node=A,point={(C.north west)}) -- (tangent cs:node=C,point={(A.north west)},solution=2);
\draw[red] (tangent cs:node=C,point={(D.north east)}) -- (tangent cs:node=D,point={(C.north east)},solution=2);
\draw[red] (tangent cs:node=D,point={(E.north east)}) -- (tangent cs:node=E,point={(D.north east)},solution=2);
\draw[red] (tangent cs:node=E,point={(F.south west)}) -- (tangent cs:node=F,point={(E.south west)},solution=2);
\draw[red] (tangent cs:node=F,point={(B.south west)}) -- (tangent cs:node=B,point={(F.south west)},solution=2);
\draw[red] (tangent cs:node=B,point={(A.south west)}) -- (tangent cs:node=A,point={(B.south west)},solution=2);
\end{tikzpicture}
\end{document}
答案2
只是为了完整性。由于@percusse 的链接中有两个答案,我很好奇它们之间的比较。底线是@percusse 的解决方案是一个近乎完美的近似。Paul Gaborit 的解决方案似乎就是那个。接下来,我在@Mike 的答案中添加了一个使用 Paul Gaborit 答案的宏。
\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
% #1: options, #2: circle node 1, #3: circle node 2
\newcommand{\DrawGaboritTangent}[4][]{
\path let \p1=($(#2.center)-(#2.west)$), \p2=($(#3.center)-(#3.west)$) in
\pgfextra{\pgfmathsetmacro{\radiusA}{\x1/veclen(\x1,\x2)}
\pgfmathsetmacro{\radiusB}{\x2/veclen(\x1,\x2)}}
\ifdim\radiusA pt>\radiusB pt
coordinate (GaboritC) at (barycentric cs:#2=-\radiusB,#3=\radiusA)
\else
coordinate (GaboritC) at (barycentric cs:#2=\radiusB,#3=-\radiusA);
\fi
;
\draw[#1] (tangent cs:node=#2,point={(GaboritC)},solution=#4) --
(tangent cs:node=#3,point={(GaboritC)},solution=#4);
}
\begin{document}
\begin{tikzpicture}[scale=0.2]
\tikzset{onlycircle/.style={draw,circle,inner sep=0pt,outer sep=0pt,minimum width=2*#1,transform shape}}
\node[onlycircle=2cm] (A) at (-4, 2) {};
\node[onlycircle=7cm] (B) at ( 2, 0) {};
\node[onlycircle=4cm] (C) at ( 0, 6) {};
\node[onlycircle=2cm] (D) at ( 8, 2) {};
\node[onlycircle=8cm] (E) at ( 8,-6) {};
\node[onlycircle=6.1cm] (F) at ( 4,-4) {};
\draw[red] (tangent cs:node=A,point={(C.north west)}) -- (tangent cs:node=C,point={(A.north west)},solution=2);
\DrawGaboritTangent[blue,opacity=0.5]{A}{C}{2}
\draw[red,opacity=0.5] (tangent cs:node=C,point={(D.north east)}) -- (tangent cs:node=D,point={(C.north east)},solution=2);
\DrawGaboritTangent[blue,opacity=0.5]{C}{D}{1}
\draw[red,opacity=0.5] (tangent cs:node=D,point={(E.north east)}) -- (tangent cs:node=E,point={(D.north east)},solution=2);
\DrawGaboritTangent[blue,opacity=0.5]{D}{E}{2}
\draw[red,opacity=0.5] (tangent cs:node=E,point={(F.south west)}) -- (tangent cs:node=F,point={(E.south west)},solution=2);
\DrawGaboritTangent[blue,opacity=0.5]{E}{F}{1}
\draw[red,opacity=0.5] (tangent cs:node=F,point={(B.south west)}) -- (tangent cs:node=B,point={(F.south west)},solution=2);
\DrawGaboritTangent[blue,opacity=0.5]{F}{B}{2}
\draw[red,opacity=0.5] (tangent cs:node=B,point={(A.south west)}) -- (tangent cs:node=A,point={(B.south west)},solution=2);
\DrawGaboritTangent[blue,opacity=0.5]{A}{B}{1}
\end{tikzpicture}
\end{document}
不同的切线很难用肉眼区分。