4

In redrawing a geometric figure with TikZ, it seems that some wrong calculation in tkz-euclide with incircles (the red color below). The command

\tkzDrawCircle[in,color=red](A2,B2,C2)  

give different circles when I change the order, such as (C2,B2,A2). Morover, a blank before (A2,B2,C2)

\tkzDrawCircle[in,color=red] (A2,B2,C2)  

results an error.

Can you give some explanation/suggestion/improvement ?

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\usepackage{tkz-euclide}
\usetkzobj{all}
\def\a{3} % side of the equilateral triangle
\pgfmathsetmacro{\d}{\a/sqrt(3)}
\begin{document}
\begin{tikzpicture}[line join=round]
\pagecolor{yellow!20}
\path
(210:\d) coordinate (A0)
(330:\d) coordinate (B0)
(90:\d)  coordinate (C0)
($(C0)!.3!(B0)$) coordinate (A1)
($(A0)!.3!(C0)$) coordinate (B1)
($(B0)!.3!(A0)$) coordinate (C1)
(intersection of A0--A1 and B0--B1) coordinate (A2)
(intersection of B0--B1 and C0--C1) coordinate (B2)
(intersection of C0--C1 and A0--A1) coordinate (C2);

\clip (A0)--(B0)--(C0)--cycle;
\draw[cyan]
(A0)--(A1) (B0)--(B1) (C0)--(C1) 
(A0)--(B0)--(C0)--cycle;
\draw (A2)--(B2)--(C2)--cycle;

\tkzDrawCircle[in,color=blue](A0,B0,A2)
\tkzDrawCircle[in,color=blue](B0,C0,B2) 
\tkzDrawCircle[in,color=blue](C0,A0,C2)

\tkzDrawCircle[in,color=red](A2,B2,C2)
%\tkzDrawCircle[in,color=red](C2,B2,A2)
%\tkzDrawCircle[in,color=red](B2,A2,C2)
\end{tikzpicture}
\end{document} 
Black Mild
  • 17,569

2 Answers2

5

To me it seems that this is almost a duplicate of an earlier question, and the answer is, again, that I think that there are numerical instabilities in tkz-euclide. However, to my own embarrassment I have to admit that this is also true for one of my solutions presented there. In my solution (and I also think for tkz-euclide but my French is not sufficient to say this with certainty) the issue is that the on has to find the right quadrants, which I thought I did but apparently didn't. So I switched gears and used the determination of the center based on Cartesian coordinates, and there seems to be no issue.

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{calc}
\tikzset{incircle/.style n args={3}{%
insert path={
let \p1=($(#2)-(#1)$), \p2=($(#3)-(#1)$),\p3=($(#2)-(#3)$),
    \n1={0.5*(veclen(\x1,\y1)+veclen(\x2,\y2)+veclen(\x3,\y3))},
    \n2={sqrt(((\n1-veclen(\x1,\y1))/\n1))*sqrt((\n1-veclen(\x2,\y2))*(\n1-veclen(\x3,\y3)))},
    \n3={veclen(\x1,\y1)}, % length #1 -- #2
    \n4={veclen(\x2,\y2)}, % length #1 -- #3
    \n5={veclen(\x3,\y3)}, % length #2 -- #3
    \n6={\n3+\n4+\n5}
    in % \pgfextra{\typeout{\n1,\n2,\n3,\n4,\n5,\n6}}
    (${(\n5/\n6)}*(#1)+{(\n4/\n6)}*(#2)+{(\n3/\n6)}*(#3)$) circle (\n2)
}}}
% \usepackage{tkz-euclide}
% \usetkzobj{all}
\begin{document}
\begin{tikzpicture}[line join=round]
\pgfmathsetmacro{\a}{3} % side of the equilateral triangle
\pgfmathsetmacro{\d}{\a/sqrt(3)}
\pagecolor{yellow!20}
\path
(210:\d) coordinate (A0)
(330:\d) coordinate (B0)
(90:\d)  coordinate (C0)
($(C0)!.3!(B0)$) coordinate (A1)
($(A0)!.3!(C0)$) coordinate (B1)
($(B0)!.3!(A0)$) coordinate (C1)
(intersection cs:first line={(A0)--(A1)},second line={(B0)--(B1)}) coordinate (A2)
(intersection cs:first line={(B0)--(B1)},second line={(C0)--(C1)}) coordinate (B2)
(intersection cs:first line={(C0)--(C1)},second line={(A0)--(A1)}) coordinate (C2);

\begin{scope}
\clip (A0)--(B0)--(C0)--cycle;
\draw[cyan]
(A0)--(A1) (B0)--(B1) (C0)--(C1) 
(A0)--(B0)--(C0)--cycle;
\draw (A2)--(B2)--(C2)--cycle;
\end{scope}

\draw[blue,incircle={A0}{B0}{A2}];
\draw[blue,incircle={B0}{C0}{B2}];
\draw[blue,incircle={C0}{A0}{C2}];
% \tkzDrawCircle[in,color=blue](A0,B0,A2)
% \tkzDrawCircle[in,color=blue](B0,C0,B2) 
% \tkzDrawCircle[in,color=blue](C0,A0,C2)

\draw[red,incircle={A2}{B2}{C2}];
%\tkzDrawCircle[in,color=red](A2,B2,C2)
%\tkzDrawCircle[in,color=red](C2,B2,A2)
%\tkzDrawCircle[in,color=red](B2,A2,C2)
\end{tikzpicture}
\end{document} 

enter image description here

  • 1
    thank you for pure TikZ answer! By the way, https://tex.stackexchange.com/questions/460483/tikz-euclid-incircle-and-calculated-coordinates is not my question (that is other Black ^^). I did not notice that when posting question – Black Mild May 02 '19 at 22:54
  • @BlackMild Oh, sorry!! I changed it. Sorry again! –  May 02 '19 at 22:58
  • also I think that "determination of almost geometric figures based on Cartesian coordinates" be nice way of drawing of geometric figures, as geometry/olympiad module in Asymptote. – Black Mild May 02 '19 at 23:09
  • 1
    @BlackMild I agree with that. Probably no one wants to do that because it might be considered stepping on the toes of the author of tkz-euclide. This leaves us with the situation in which you are (almost, i.e. up to the above-mentioned issues) fine if you know French and less so if you don't. In principle one can do everything with calc but this requires one sometimes to punch in formulae and, what is worse, find out by trial and error which solution is most stable. –  May 02 '19 at 23:35
  • Is there a way to write \draw[blue,incircle={A}{B}{C}]; in better form, something like that \draw[blue] incircle{A}{B}{C}; or \draw[blue] incircle(A,B,C); ? – Black Mild Jun 01 '19 at 09:25
  • 1
    @BlackMild One would have to modify the parser of TikZ. This can be done, as demonstrated in this answer and in this answer but I agree with the statement made there: I still strongly recommend the to path solution. Do not subvert the TikZ code unless you know what you are doing. (with "to path" replaced by "insert path"). –  Jun 01 '19 at 14:10
  • Use \def\incenter(#1,#2,#3)(#4){...} command, we may store incenter of the triangle ABC to I with \incenter(A,B,C)(I). How can we store inradius of the triangle ABC to a variable (\r, for example), and then use \draw (I) circle(\r); ??? – Black Mild Jun 19 '19 at 15:54
  • 1
    @BlackMild \tikzset{incircle/.style n args={3}{% insert path={ let \p1=($(#2)-(#1)$), \p2=($(#3)-(#1)$),\p3=($(#2)-(#3)$), \n1={0.5*(veclen(\x1,\y1)+veclen(\x2,\y2)+veclen(\x3,\y3))}, \n2={sqrt(((\n1-veclen(\x1,\y1))/\n1))*sqrt((\n1-veclen(\x2,\y2))*(\n1-veclen(\x3,\y3)))}, \n3={veclen(\x1,\y1)}, % length #1 -- #2 \n4={veclen(\x2,\y2)}, % length #1 -- #3 \n5={veclen(\x3,\y3)}, % length #2 -- #3 \n6={\n3+\n4+\n5} in \pgfextra{\xdef\BlackMildRadius{\n2}} (${(\n5/\n6)}*(#1)+{(\n4/\n6)}*(#2)+{(\n3/\n6)}*(#3)$) coordinate (incenter) circle (\n2) }}} –  Jun 19 '19 at 16:02
  • 1
    Then you can \draw[red,dashed] (incenter) circle[radius=\BlackMildRadius]; after a blue circle. –  Jun 19 '19 at 16:03
  • Thanks! it works for the above code, but my question is a bit different. Let me make a new question! – Black Mild Jun 19 '19 at 16:46
4

Bug in the last version 1.16 of tkz-eucide, with the next (beta actually) you get the result. You need to install tkz-base and tkz-euclide in texmf tree.

v2.40b Euclide

\documentclass{article}
\usepackage{tkz-euclide}

\def\a{3} % side of the equilateral triangle
\pgfmathsetmacro{\d}{\a/sqrt(3)}
\begin{document}
\begin{tikzpicture}[scale=3]
\tkzDefPoint(210:\d){A0}
\tkzDefPoint(330:\d){B0}
\tkzDefPoint(90:\d){C0}

\tkzDefBarycentricPoint(C0=2,B0=1) \tkzGetPoint{A1}
\tkzDefBarycentricPoint(A0=2,C0=1) \tkzGetPoint{B1}
\tkzDefBarycentricPoint(B0=2,A0=1) \tkzGetPoint{C1}
\tkzInterLL(A0,A1)(B0,B1) \tkzGetPoint{A2}
\tkzInterLL(B0,B1)(C0,C1) \tkzGetPoint{B2}
\tkzInterLL(C0,C1)(A0,A1) \tkzGetPoint{C2}

%\clip (A0)--(B0)--(C0)--cycle;
\tkzDrawSegments(A0,A1 B0,B1 C0,C1)

\tkzDrawPolygon(A0,B0,C0)
\tkzDrawPolygon(A2,B2,C2)

\tkzDrawCircle[in,color=blue](A0,B0,A2)
\tkzDrawCircle[in,color=blue](B0,C0,B2)
\tkzDrawCircle[in,color=blue](C0,A0,C2)

\tkzDrawCircle[in,color=red](A2,B2,C2)
\tkzDrawCircle[in,color=red](C2,B2,A2)
\tkzDrawCircle[in,color=red](B2,A2,C2)
\end{tikzpicture}
\end{document} 

enter image description here

Alain Matthes
  • 95,075