1

Here is a short Wikipedia Definition of Napoleon's theorem:

"Napoleon's theorem states that if equilateral triangles are constructed on the sides of any triangle, either all outward or all inward, the lines connecting the centres of those equilateral triangles themselves form an equilateral triangle."

I tried to visualize this in tkz-euclide, but it doesn't work for me. MWE:

\documentclass[border=2mm]{standalone}

\usepackage{tkz-euclide}

\begin{document}
\begin{tikzpicture}
\tkzDefPoint(0,0){a}
\tkzDefPoint(5,1){b}
\tkzDefPoint(1,4){c}
\tkzDefPoint(1,-3){d}
\tkzDefPoint(6,4){e}
\tkzDefPoint(-1,3){f}

\tkzDrawPolygon(a,b,c)
\tkzDrawPolygon(a,b,d)
\tkzDrawPolygon(b,c,e)
\tkzDrawPolygon(a,c,f)

\tkzInCenter(a,b,c)\tkzGetPoint{D}

\tkzInCenter(a,b,d)\tkzGetPoint(A)

\tkzInCenter(b,c,e)\tkzGetPoint(B)

\tkzInCenter(a,c,f)\tkzGetPoint(C)

\tkzDrawPoint[red](D)
\tkzDrawPoint[red](A)
\tkzDrawPoint[red](B)
\tkzDrawPoint[red](C)
\tkzDrawPolygon(A,B,C) 
\end{tikzpicture}

\end{document}

I geht the following error messages: No shape named 'A' is known., No shape named 'B' is known., No shape named 'C' is known. which is weird, since it apparently works for D.

Am I doing something wrong or is this a bug?

Small note: The points, as they are defined, do not yet give three equilateral triangles. I chose some points first and wanted to take care of the geometric centroids first.

Thanks in advance!

0

2 Answers 2

2

It's just a typo: use { } instead of ( )

result

\documentclass[border=2mm]{standalone}

%\usepackage{tikz}
\usepackage{tkz-euclide}

\begin{document}
 \begin{tikzpicture}
    \tkzDefPoint(0,0){a}
    \tkzDefPoint(5,1){b}
    \tkzDefPoint(1,4){c}
    \tkzDefPoint(1,-3){d}
    \tkzDefPoint(6,4){e}
    \tkzDefPoint(-1,3){f}
    
    \tkzDrawPolygon(a,b,c)
    \tkzDrawPolygon(a,b,d)
    \tkzDrawPolygon(b,c,e)
    \tkzDrawPolygon(a,c,f)
    
    \tkzInCenter(a,b,c)\tkzGetPoint{D}
    
    \tkzInCenter(a,b,d)\tkzGetPoint{A}% ! { }
    
    \tkzInCenter(b,c,e)\tkzGetPoint{B}%(B)
    
    \tkzInCenter(a,c,f)\tkzGetPoint{C}%(C)
    
    \tkzDrawPoint[red](D)
    \tkzDrawPoint[red](A)
    \tkzDrawPoint[red](B)
    \tkzDrawPoint[red](C)
    \tkzDrawPolygon(A,B,C) 
 \end{tikzpicture}

\end{document}
4
  • 1
    Oh my god, I feel so stupid. I might as well delete this post, but on the other hand, perhaps others could learn from it. Thank you!
    – Jim Ye
    Dec 2, 2023 at 17:34
  • 1
    Lol, everyone's been there. This post is super useful for someone else trying to do something simliar.
    – Miloop
    Dec 2, 2023 at 17:36
  • No problem, we all made this kind of mistake every now and then … And yes, it‘s hard to spot.
    – MS-SPO
    Dec 2, 2023 at 17:36
  • 2
    @JimYe I've used the following rule for the whole package: if the macro concerns points already created, use () if the macro creates points, use {}. Dec 2, 2023 at 19:40
2

Finally, the question is useful, as it has enabled me to improve my package. Like the introduction of the indirect parameter to define an equilateral triangle in the indirect direction. I've also introduced the check_equilateral function.

The following code will only work with version 1.40 of tkz-elements, which arrives this week. The advantage of the code is that it generalizes the answer. You can modify the initial triangle without modifying anything else.

Some explanations.

T.ABC is the initial triangle. It is an object and among its attributes are the lines (or segments) defined by the vertices. We get_points ( ) the lines with T.A = T.ABC.bc which corresponds to the straight line (BC) etc. others lines attributes are ca and ab.

T.BCD = T.ABC.bc : equilateral (indirect) defines an equilateral triangle. The indirect parameter is to obtain the triangle such that (BC,BD)=-60°

A triangle has three vertices represented by the attributes (pa,pb,pc). We obtain the vertices with: z.D = T.BCD.pc.

Then we get_points ( ) the centroid point of each triangle. check_equilateral is a test to determine whether the triangle is equilateral.

% !TEX TS-program = lualatex
\documentclass[border=2mm]{standalone}
\usepackage{tkz-euclide,tkz-elements,ifthen}
\begin{document}
   
 \begin{tkzelements}
   z.A = point :  new ( 0 , 0 )
   z.B = point :  new ( 5 , 1 ) 
   z.C = point :  new ( 1 , 3 ) 
   T.ABC = triangle  :  new (z.A,z.B,z.C)
   T.BCD = T.ABC.bc : equilateral (indirect)
   T.CAE = T.ABC.ca : equilateral (indirect)
   T.ABF = T.ABC.ab : equilateral (indirect)
   z.D = T.BCD.pc
   z.E = T.CAE.pc
   z.F = T.ABF.pc
   z.G = T.BCD.centroid
   z.H = T.CAE.centroid
   z.I = T.ABF.centroid
   T.GHI = triangle : new (z.G,z.H,z.I)
   bool_GHI = T.GHI : check_equilateral ()
   bool_ABC = T.ABC : check_equilateral ()
\end{tkzelements}
   
\begin{tikzpicture} 
\tkzGetNodes
\tkzDrawPolygons[thick](B,C,D A,C,E A,B,F) 
\tkzDrawPoints(A,B,C,D,E,F,G,H,I)
\tkzLabelPoints(A,B,C,D,E,F,G,H,I)

\ifthenelse{\equal{\tkzUseLua{bool_GHI}}{false}}{%
\tikzset{col/.style = {green}}}{\tikzset{col/.style = {red}}}
\tkzDrawPolygons[thick,col](G,H,I)

\ifthenelse{\equal{\tkzUseLua{bool_ABC}}{false}}{%
\tikzset{col/.style = {green}}}{\tikzset{col/.style = {red}}}
\tkzDrawPolygons[thick,col](A,B,C)
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .