# How can I draw a tangent ending smoothly in a circle?

I'm trying to draw a tanget on a circle, but I'm not happy with the result I get from the tangent option.

particularly, I'd like to have the lines ending smoothly in the circle. The problem is shown enlarged here:

Here is the code for this mininmal example

\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}


I'd greatly appreciate any advice allowing me to do this!

-

You already have the solution: Just apply the same to the small circle, and throw some outer sep=0 for a nice blend.

\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}


-
oh great. Until now I was only aware of the inner sep key! thanks for the lightening fast answer! Spot on. – Sebastian Jan 21 '12 at 7:17
This "solution" is just an approximation... – Paul Gaborit Oct 10 '12 at 20:21
@PaulGaborit Current TeX math operations, no matter how complicated, are always approximate. It's an acceptable visual solution. Note that we are producing graphics not assessing the data scientifically. But I'll be more than happy to see the precise solution. – percusse Oct 10 '12 at 20:41

Here is an exact solution (via barycentric coordinate system as in this answer to the question Can PSTricks or others draw the 4 common tangent lines of 2 “disjoint” circles without having to do extra calculations?):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[inner sep=0,outer sep=0]
\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}


Edit:

The following code computes the difference between Percusse's solution (a good approximation) and this solution (an "exact" solution):

\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}


And from the log:

small circle difference:-0.6035pt,0.73969pt
big circle difference:1.43744pt,-2.58029pt

-
Is it intentional that there is pt in the minimum size of the circles? – mvkorpel Aug 13 '14 at 9:36
@mvkorpel pgfmath always uses pt internally. All results are in pt... but without pt at the end. – Paul Gaborit Aug 13 '14 at 11:30
Thanks, makes sense. To me it is a bit confusing or superfluous to have pt there. The code apparently works fine without it, and anyone who doesn't know the internals of pgfmath could be confused by what initially looks like a strange mix of mm and pt. Just my 5 euro cents (we don't really use the two smallest denominations in Finland). Seems to be a matter of taste. – mvkorpel Aug 13 '14 at 12:26