This answer comes with two styles intersection 1 of line
and intersection 2 of line
, which can be used e.g. like this:
\coordinate[intersection 1 of line={from A to B with circle around A with
radius 2cm}] (aux1);
As the syntax suggests, this will find one intersection of the line that runs through A
and B
with the circle of radius 2cm
around A
. Of course, the circle does not have to be around a point that the line runs through, as the following illustrates. This updated version uses xfp
to avoid `dimension too large errors. (I wish I had tried this earlier. ;-)
\documentclass{standalone}
\usepackage{xfp}
\usepackage{tikz}
% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
\stepcounter{smuggle}%
\expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
\aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
\smuggleone{#2}%
\ifnum#1>1
\aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
\fi
}
\usetikzlibrary{intersections,calc}
\begin{document}
\tikzset{intersection warning/.code={\pgfmathtruncatemacro{\mysign}{sign(#1)+1}
\ifcase\mysign
\typeout{The\space line\space and\space circle\space do\space not\space
intersect.\space The\space intersections\space returned\space are\space fake.}
\or
\typeout{The\space line\space and\space circle\space intersect\space
only\space once.}
\or
\fi},
fpeval/.code n args={2}{\edef#1{\fpeval{#2}}%\typeout{#1}%
\smuggle[2]{#1}},
intersection 1 of line/.style args={from #1 to #2 with circle around #3 with radius #4}{%
insert path={let \p1=(#1),\p2=(#2),\p3=(#3)
in [fpeval={\mydisc}{{-((\y1/10)*(\x2/10) - (\x1/10)*(\y2/10) - (\y1/10)*(\x3/10) + (\y2/10)*(\x3/10) + (\x1/10)*(\y3/10) - (\x2/10)*(\y3/10))^2 +
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)*(#4/10)^2}},
fpeval={\myfactor}{((\x1/10)^2 + (\y1/10)^2 + (\x2/10)*(\x3/10) - (\x1/10)*((\x2/10) + (\x3/10)) + (\y2/10)*(\y3/10) -
(\y1/10)*((\y2/10) + (\y3/10)) -
sqrt(abs(\mydisc)))/
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)},
intersection warning=\mydisc]($(#1)+\myfactor*($(#2)-(#1)$)$)} },
intersection 2 of line/.style args={from #1 to #2 with circle around #3 with radius #4}{%
insert path={let \p1=(#1),\p2=(#2),\p3=(#3)
in [fpeval={\mydisc}{-((\y1/10)*(\x2/10) - (\x1/10)*(\y2/10) - (\y1/10)*(\x3/10) + (\y2/10)*(\x3/10) + (\x1/10)*(\y3/10) - (\x2/10)*(\y3/10))^2 +
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)*(#4/10)^2},
fpeval={\myfactor}{((\x1/10)^2 + (\y1/10)^2 + (\x2/10)*(\x3/10) - (\x1/10)*((\x2/10) + (\x3/10)) + (\y2/10)*(\y3/10) -
(\y1/10)*((\y2/10) + (\y3/10)) + sqrt(abs(\mydisc)))/
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)}]
[intersection warning=\mydisc] ($(#1)+\myfactor*($(#2)-(#1)$)$)} }
}
\begin{tikzpicture}[
plotmark/.style = {%
solid, fill = red, circle, inner sep = 0pt, minimum size = 6pt
}
]
\coordinate (A) at (0,0);
\coordinate (B) at (1,1);
\coordinate (C) at (3,1);
\coordinate (D) at (4,0);
\coordinate (E) at (1,0);
\coordinate (F) at (2,-1);
\coordinate (G) at (2,1);
\coordinate (H) at (3,1);
\draw[->] (A)--(B);
\draw[->] (D)--(C);
\draw[dashed] (A) circle [radius=2];
\coordinate (I) at (intersection cs:first line={(A)--(B)}, second line={(C)--(D)});
\node[plotmark, label={below:$A$}] at (A) {};
\node[plotmark, label={below:$D$}] at (D) {};
\node[plotmark, label={below:$E$}] at (E) {};
\node[plotmark, label={above:$I$}] at (I) {};
\coordinate[intersection 1 of line={from A to B with circle around A with
radius 2cm}] (aux1);
\typeout{aux2}
\coordinate[intersection 2 of line={from A to B with circle around A with
radius 2cm}] (aux2);
\node[plotmark, label={below:$I_1$}] at (aux1) {};
\node[plotmark, label={below:$I_2$}] at (aux2) {};
\coordinate[intersection 1 of line={from E to B with circle around A with
radius 2cm}] (aux3);
\coordinate[intersection 2 of line={from E to B with circle around A with
radius 2cm}] (aux4);
\node[plotmark, label={below:$I_1'$}] at (aux3) {};
\node[plotmark, label={below:$I_2'$}] at (aux4) {};
\coordinate[intersection 1 of line={from F to G with circle around A with
radius 2cm}] (aux5);
\coordinate[intersection 1 of line={from F to H with circle around A with
radius 2cm}] (aux6);
\end{tikzpicture}
\end{document}
Warnings are issued if there is no intersection and the user gets told if the line and the circle only intersect once. The advantage of the analytic computation is that the determination of the intersections does not alter the bounding box.
ADDENDUM: Not tested very well because I feel you should write a new question.
\documentclass{article}
\usepackage{xfp}
% smuggling from https://tex.stackexchange.com/a/470979/121799
\newcounter{smuggle}
\DeclareRobustCommand\smuggleone[1]{%
\stepcounter{smuggle}%
\expandafter\global\expandafter\let\csname smuggle@\arabic{smuggle}\endcsname#1%
\aftergroup\let\aftergroup#1\expandafter\aftergroup\csname smuggle@\arabic{smuggle}\endcsname
}
\DeclareRobustCommand\smuggle[2][1]{%
\smuggleone{#2}%
\ifnum#1>1
\aftergroup\smuggle\aftergroup[\expandafter\aftergroup\the\numexpr#1-1\aftergroup]\aftergroup#2%
\fi
}
\usepackage{tikz}
\usetikzlibrary{intersections,calc,through}
\tikzset{intersection warning/.code={\pgfmathtruncatemacro{\mysign}{sign(#1)+1}
\ifcase\mysign
\typeout{The\space line\space and\space circle\space do\space not\space
intersect.\space The\space intersections\space returned\space are\space fake.}
\or
\typeout{The\space line\space and\space circle\space intersect\space
only\space once.}
\or
\fi},
fpeval/.code n args={2}{\edef#1{\fpeval{#2}}%\typeout{#1}%
\smuggle[2]{#1}},
intersection 1 of line/.style args={from #1 to #2 with circle around #3 with radius #4}{%
insert path={let \p1=(#1),\p2=(#2),\p3=(#3)
in [fpeval={\mydisc}{-((\y1/10)*(\x2/10) - (\x1/10)*(\y2/10) - (\y1/10)*(\x3/10) + (\y2/10)*(\x3/10) + (\x1/10)*(\y3/10) - (\x2/10)*(\y3/10))^2 +
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)*(#4/10)^2},
fpeval={\myfactor}{((\x1/10)^2 + (\y1/10)^2 + (\x2/10)*(\x3/10) - (\x1/10)*((\x2/10) + (\x3/10)) + (\y2/10)*(\y3/10) -
(\y1/10)*((\y2/10) + (\y3/10)) -
sqrt(abs(\mydisc)))/
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)}]
[intersection warning=\mydisc] ($(#1)+\myfactor*($(#2)-(#1)$)$)} },
intersection 2 of line/.style args={from #1 to #2 with circle around #3 with radius #4}{%
insert path={let \p1=(#1),\p2=(#2),\p3=(#3)
in [fpeval={\mydisc}{-((\y1/10)*(\x2/10) - (\x1/10)*(\y2/10) - (\y1/10)*(\x3/10) + (\y2/10)*(\x3/10) + (\x1/10)*(\y3/10) - (\x2/10)*(\y3/10))^2 +
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)*(#4/10)^2},
fpeval={\myfactor}{((\x1/10)^2 + (\y1/10)^2 + (\x2/10)*(\x3/10) - (\x1/10)*((\x2/10) + (\x3/10)) + (\y2/10)*(\y3/10) -
(\y1/10)*((\y2/10) + (\y3/10)) +
sqrt(abs(\mydisc)))/
(((\x1/10) - (\x2/10))^2 + ((\y1/10) - (\y2/10))^2)}]
[intersection warning=\mydisc] ($(#1)+\myfactor*($(#2)-(#1)$)$)} },
circle through 3 points/.style n args={3}{%
insert path={let \p1=($(#1)!0.5!(#2)$),
\p2=($(#1)!0.5!(#3)$),
\p3=($(#1)!0.5!(#2)!1!-90:(#2)$),
\p4=($(#1)!0.5!(#3)!1!90:(#3)$),
\p5=(intersection of \p1--\p3 and \p2--\p4)
in },
at={(\p5)},
circle through= {(#1)}
},
circle radius/.style args={#1 of circle at #2 through #3}{
insert path={let \p1=($(#2)-(#3)$),\n1={veclen(\x1,\y1)}
in \pgfextra{\xdef#1{\n1}}}}
}
\begin{document}
\section*{Intersection of circle with line}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (1,1);
\coordinate (C) at (3,1);
\coordinate (D) at (4,0);
\coordinate (E) at (1,0);
\coordinate (F) at (2,-1);
\coordinate (G) at (2,1);
\draw (A) circle[radius=2cm];
\foreach \X in {A,B,...,G}
{\fill[blue] (\X) circle (2pt) node[above]{\X};}
%
\coordinate[intersection 1 of line={from A to B with circle around A with
radius 2cm}] (aux1);
\coordinate[intersection 2 of line={from A to B with circle around A with
radius 2cm}] (aux2);
\coordinate[intersection 1 of line={from E to B with circle around A with
radius 2cm}] (aux3);
\coordinate[intersection 2 of line={from E to B with circle around A with
radius 2cm}] (aux4);
\coordinate[intersection 1 of line={from F to G with circle around A with
radius 2cm}] (aux5);
\foreach \X in {1,...,5}
{\fill[red] (aux\X) circle (2pt) node[below]{\X};}
\end{tikzpicture}
\section*{Define the circle by center and point on it}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (1,1);
\coordinate (C) at (3,1);
\coordinate (D) at (4,0);
\coordinate (E) at (1,0);
\coordinate (F) at (2,-1);
\coordinate (G) at (2,1);
\path[circle radius={\myradius} of circle at A through G];
\draw (A) circle[radius=\myradius];
\foreach \X in {A,B,...,G}
{\fill[blue] (\X) circle (2pt) node[above]{\X};}
%
\coordinate[intersection 1 of line={from A to B with circle around A with
radius \myradius}] (aux1);
\coordinate[intersection 2 of line={from A to B with circle around A with
radius \myradius}] (aux2);
\coordinate[intersection 1 of line={from E to B with circle around A with
radius \myradius}] (aux3);
\coordinate[intersection 2 of line={from E to B with circle around A with
radius \myradius}] (aux4);
\coordinate[intersection 1 of line={from F to G with circle around A with
radius \myradius}] (aux5);
\foreach \X in {1,...,5}
{\fill[red] (aux\X) circle (2pt) node[below]{\X};}
\end{tikzpicture}
\section*{Define the circle by 3 points}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (1,1);
\coordinate (C) at (3,1);
\coordinate (D) at (4,0);
\coordinate (E) at (1,0);
\coordinate (F) at (2,-1);
\coordinate (G) at (2,1);
\node[circle through 3 points={A}{F}{D},draw] (CN){};
\path[circle radius={\myradius} of circle at CN.center through D];
\draw[red,dashed] (CN.center) circle[radius=\myradius];
\foreach \X in {A,B,...,G}
{\fill[blue] (\X) circle (2pt) node[above]{\X};}
%
\coordinate[intersection 1 of line={from E to C with circle around CN.center with
radius \myradius}] (aux1);
\foreach \X in {1}
{\fill[red] (aux\X) circle (2pt) node[below]{\X};}
\end{tikzpicture}
\end{document}
ADDENDUM II: What can one do when dimension too large
errors occur? The infamous dimension too large
errors can occur with any coordinate computations, so they can occur here. One way to partly avoid them is to work with the fpu
library. (Note, however, that you may have to switch off fpu
(locally) if you work with the math
library, say.) This alone does not (necessarily) fix the issue, but after rewriting the computations in such a way that a characteristic scale auxmax
gets identified and all dimensions divided by it seems to work.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\usetikzlibrary{fpu}
\begin{document}
\tikzset{declare
function={auxmax(\x,\y,\u,\v,\r,\s,\z)=sqrt(\x^2+\y^2+\u^2+\v^2+\r^2+\s^2+\z^2);
auxone(\x,\y,\u,\v,\r,\s,\z)=
-((\y/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\u/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\x/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\v/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\y/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\r/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\v/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\r/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\x/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\s/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\u/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\s/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2 +
(((\x/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\u/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2 + ((\y/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\v/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2)*(\z/auxmax(\x,\y,\u,\v,\r,\s,\z))^2;
auxtwo(\x,\y,\u,\v,\r,\s,\z)=
((\x/auxmax(\x,\y,\u,\v,\r,\s,\z))^2 + (\y/auxmax(\x,\y,\u,\v,\r,\s,\z))^2 + (\u/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\r/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\x/auxmax(\x,\y,\u,\v,\r,\s,\z))*((\u/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\r/auxmax(\x,\y,\u,\v,\r,\s,\z))) + (\v/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\s/auxmax(\x,\y,\u,\v,\r,\s,\z)) -
(\y/auxmax(\x,\y,\u,\v,\r,\s,\z))*((\v/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\s/auxmax(\x,\y,\u,\v,\r,\s,\z))) -
sqrt(abs(\n1)))/
(((\x/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\u/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2 + ((\y/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\v/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2);
auxthree(\x,\y,\u,\v,\r,\s,\z)=-((\y/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\u/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\x/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\v/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\y/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\r/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\v/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\r/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\x/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\s/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\u/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\s/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2 +
(((\x/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\u/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2 + ((\y/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\v/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2)*(\z/auxmax(\x,\y,\u,\v,\r,\s,\z))^2;
auxfour(\x,\y,\u,\v,\r,\s,\z)=((\x/auxmax(\x,\y,\u,\v,\r,\s,\z))^2 + (\y/auxmax(\x,\y,\u,\v,\r,\s,\z))^2 + (\u/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\r/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\x/auxmax(\x,\y,\u,\v,\r,\s,\z))*((\u/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\r/auxmax(\x,\y,\u,\v,\r,\s,\z))) + (\v/auxmax(\x,\y,\u,\v,\r,\s,\z))*(\s/auxmax(\x,\y,\u,\v,\r,\s,\z)) -
(\y/auxmax(\x,\y,\u,\v,\r,\s,\z))*((\v/auxmax(\x,\y,\u,\v,\r,\s,\z)) + (\s/auxmax(\x,\y,\u,\v,\r,\s,\z))) +
sqrt(abs(\n1))/
(((\x/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\u/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2 + ((\y/auxmax(\x,\y,\u,\v,\r,\s,\z)) - (\v/auxmax(\x,\y,\u,\v,\r,\s,\z)))^2);
}}
\tikzset{intersection warning/.code={\pgfmathtruncatemacro{\mysign}{sign(#1)+1}
\ifcase\mysign
\typeout{The\space line\space and\space circle\space do\space not\space
intersect.\space The\space intersections\space returned\space are\space fake.}
\or
\typeout{The\space line\space and\space circle\space intersect\space
only\space once.}
\or
\fi},
intersection 1 of line/.style args={from #1 to #2 with circle around #3 with radius #4}{%
insert path={let \p1=(#1),\p2=(#2),\p3=(#3),
\n1={auxone(\x1,\y1,\x2,\y2,\x3,\y3,#4)},
\n2={auxtwo(\x1,\y1,\x2,\y2,\x3,\y3,#4)}
in [intersection warning=\n1]($(#1)+\n2*($(#2)-(#1)$)$)} },
intersection 2 of line/.style args={from #1 to #2 with circle around #3 with radius #4}{%
insert path={let \p1=(#1),\p2=(#2),\p3=(#3),
\n1={auxthree(\x1,\y1,\x2,\y2,\x3,\y3,#4)},
\n2={auxfour(\x1,\y1,\x2,\y2,\x3,\y3,#4)}
in [intersection warning=\n1] ($(#1)+\n2*($(#2)-(#1)$)$)} }
}
\begin{tikzpicture}[/pgf/fpu=true,/pgf/fpu/output format=fixed]
\pgfmathsetmacro{\myConstant}{5*sqrt(2)}
\coordinate (A) at (0,0);
\coordinate (B) at (0, \myConstant);
\coordinate (C) at (10, \myConstant);
\coordinate (D) at (10,0);
\coordinate (midBC) at (5, \myConstant);
\coordinate (midAD) at (5, 0);
\coordinate[intersection 1 of line={from midBC to A with circle around midAD with radius 5cm}] (aux1);
\foreach \X in {A,B,C,D,midBC,midAD,aux1}
{\fill (\X) circle(1pt) node[above]{\X};}
\end{tikzpicture}
\end{document}