我试图在圆上画一条切线,但是我对该选项得到的结果并不满意tangent
。
具体来说,我希望线条能够平滑地结束在圆圈内。问题如下图所示:
以下是这个最小示例的代码
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[thick]
\node[draw,circle,xshift=2.2cm] (big) [minimum size=25mm] {};
\node[draw,circle] (small) [minimum size=2mm] {};
\draw (small.south) -- (tangent cs:node=big,point={(small.south)});
\draw (small.north) -- (tangent cs:node=big,point={(small.north)},solution=2);
\end{tikzpicture}
\end{document}
我将非常感激任何能让我做到这一点的建议!
答案1
您已经有了解决方案:只需将其应用到小圆圈上,然后扔一些outer sep=0
即可获得漂亮的混合。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[thick]
\node[draw,circle,xshift=2.2cm,minimum size=25mm,outer sep=0] (big) {};
\node[draw,circle,minimum size=2mm,outer sep=0] (small) {};
\draw (tangent cs:node=small,point={(big.south)},solution=2) -- (tangent cs:node=big,point={(small.south)});
\draw (tangent cs:node=small,point={(big.north)},solution=1) -- (tangent cs:node=big,point={(small.north)},solution=2);
\end{tikzpicture}
\end{document}
答案2
这是一个精确的解决方案(通过barycentric
坐标系这个答案针对这个问题PSTricks 或其他人是否可以在无需进行额外计算的情况下绘制两个“不相交”圆的 4 条公切线?):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[inner sep=0,outer sep=0]
% radii
\pgfmathsetmacro{\rbig}{20mm}
\pgfmathsetmacro{\rsmall}{1mm}
% the two circles
\node[draw,circle,xshift=\rsmall+\rbig+1mm,minimum size=2*\rbig pt] (big) {};
\node[draw,circle,minimum size=2*\rsmall pt] (small) {};
% the good point !
\coordinate (c) at (barycentric cs:big=-\rsmall,small=\rbig);
\fill[red](c) circle (.2pt);
% the two tangents
\draw (tangent cs:node=small,point={(c)},solution=2) -- (tangent cs:node=big,point={(c)},solution=2);
\draw (tangent cs:node=small,point={(c)},solution=1) -- (tangent cs:node=big,point={(c)},solution=1);
\end{tikzpicture}
\end{document}
编辑:
以下代码计算了 Percusse 的解决方案(一个很好的近似值)与此解决方案(一个“精确的“ 解决方案):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[inner sep=0,outer sep=0]
\pgfmathsetmacro{\rbig}{20mm}
\pgfmathsetmacro{\rsmall}{1mm}
\node[draw,circle,xshift=\rsmall+\rbig+1mm,minimum size=2*\rbig pt] (big) {};
\node[draw,circle,minimum size=2*\rsmall pt] (small) {};
\coordinate (c) at (barycentric cs:big=-\rsmall,small=\rbig);
\coordinate (exact small 1) at (tangent cs:node=small,point={(c)},solution=1);
\coordinate (approx small 1) at (tangent cs:node=small,point={(big.south)},solution=2);
\coordinate (exact big 1) at (tangent cs:node=big,point={(c)},solution=1);
\coordinate (approx big 1) at (tangent cs:node=big,point={(small.south)},solution=1);
% the difference
\path let \p1=($(exact small 1) - (approx small 1)$),
\p2=($(exact big 1) - (approx big 1)$) in
\pgfextra{
\typeout{small circle difference:\x1,\y1}
\typeout{big circle difference:\x2,\y2}
};
\end{tikzpicture}
\end{document}
从日志中可以看到:
小圆差:-0.6035pt,0.73969pt 大圆差:1.43744pt,-2.58029pt