% Copyright 2011 by Alain Matthes
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.


\def\fileversion{1.16 c}
\def\filedate{2011/06/01}   


%<--------------------------------------------------------------------------–>
%                                 Polygon 
%<--------------------------------------------------------------------------–>
\def\tkzDrawPolygon{\pgfutil@ifnextchar[{\tkz@DrawPolygon}{%
                                         \tkz@DrawPolygon[]}}
\def\tkz@DrawPolygon[#1](#2,#3){%
\begingroup
\draw[line style,#1] (#2)
    \foreach \tkz@pt in {#3}{--(\tkz@pt)}--cycle;%
\endgroup
}
%<----------------------------   CLIP       --------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzClipPolygon(#1,#2){\path[clip] (#1)
   \foreach \pt in {#2}{--(\pt)}--cycle;
}
%<----------------------------   FILL       --------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzFillPolygon{\pgfutil@ifnextchar[{\tkz@FillPolygon}{%
                                         \tkz@FillPolygon[]}} 
\def\tkz@FillPolygon[#1](#2,#3){%
 \begingroup
     \fill[#1] (#2)
\foreach \tkz@pt in {#3}{--(\tkz@pt)}--cycle;%  
\endgroup
}

%<--------------------------------------------------------------------------–>
%                       Triangle Equilateral
%<--------------------------------------------------------------------------–>
\def\tkzDefEquilateral(#1,#2){
\begingroup
 \tkzURotateAngle(#1,60)(#2)
\endgroup
}  
%<--------------------------------------------------------------------------–>

\def\tkzDrawEquilateral{\pgfutil@ifnextchar[{\tkz@Equilateral}{%
                                         \tkz@Equilateral[]}} 

\def\tkz@Equilateral[#1](#2,#3){%
\begingroup
    \tkzURotateAngle(#2,60)(#3)
    \tkzDrawPolygon[#1](#2,#3,tkzPointResult)
\endgroup
}
%<--------------------------------------------------------------------------–>
%                       Triangle OneTwo
%<--------------------------------------------------------------------------–>
\def\tkzPhi{1.618034}
\def\tkzInvPhi{0.618034}
\def\tkzSqrtPhi{1.27202}

\def\tkzDefTwoOne(#1,#2){
\begingroup
 \tkzVecKOrth[-.5](#2,#1){tkzPointResult}
\endgroup
}
\def\tkzDefPythagore(#1,#2){
\begingroup
 \tkzVecKOrth[-0.75](#2,#1){tkzPointResult}
\endgroup
}
\def\tkzDefSchoolTriangle(#1,#2){
\begingroup
 \tkzURotateAngle(#1,30)(#2)
 \tkzVecKOrth[-1](#2,#1){tkz@a}
 \tkzInterLL(#1,tkzPointResult)(#2,tkz@a)
\endgroup
}
\def\tkzDefGoldTriangle(#1,#2){
\begingroup
 \tkzURotateAngle(#1,36)(#2)
\endgroup
}
\def\tkzDefEuclideTriangle(#1,#2){
\begingroup
 \tkzURotateAngle(#1,72)(#2)
 \tkzUHomo(#1,\tkzPhi)(tkzPointResult)
\endgroup
}
\def\tkzDefGoldenTriangle(#1,#2){
\begingroup
 \tkzVecKOrth[-\tkzInvPhi](#2,#1){tkzPointResult}
\endgroup
}
\def\tkzDefCheopsTriangle(#1,#2){
\begingroup
\tkzDefMidPoint(#1,#2)
 \tkzVecKOrth[-\tkzSqrtPhi](tkzPointResult,#1){tkzPointResult}
\endgroup
}
\def\tkzDefTwoAnglesTriangle(#1,#2){
\begingroup
 \tkzURotateAngle(#1,\tkz@alpha)(#2) \tkzGetPoint{tkz@pta}
 \tkzURotateAngle(#2,-\tkz@beta)(#1) \tkzGetPoint{tkz@ptb}
 \tkzInterLL(#1,tkz@pta)(#2,tkz@ptb)
\endgroup
}
\def\tkz@numtr{0}
\pgfkeys{/deftriangle/.cd,
equilateral/.code                    = \global\def\tkz@numtr{0},
half/.code                           = \global\def\tkz@numtr{1},
pythagore/.code                      = \global\def\tkz@numtr{2},
school/.code                         = \global\def\tkz@numtr{3},
golden/.code                         = \global\def\tkz@numtr{4},
euclide/.code                        = \global\def\tkz@numtr{5},
gold/.code                           = \global\def\tkz@numtr{6},
cheops/.code                         = \global\def\tkz@numtr{7},
two angles/.code  args={#1 and #2}  {  \global\def\tkz@numtr{8}%
                                       \global\def\tkz@alpha{#1}%
                                       \global\def\tkz@beta{#2}}
} 

\def\tkzDefTriangle{\pgfutil@ifnextchar[{\tkz@DefTriangle}{%
                                         \tkz@DefTriangle[]}}
\def\tkz@DefTriangle[#1](#2,#3){% 
\begingroup
\pgfkeys{/deftriangle/.cd,equilateral}   
\pgfqkeys{/deftriangle}{#1}  
\ifcase\tkz@numtr%
  \tkzDefEquilateral(#2,#3)
  \or% 1 
  \tkzDefTwoOne(#2,#3)  
  \or% 2
  \tkzDefPythagore(#2,#3)
  \or% 3
  \tkzDefSchoolTriangle(#2,#3)
  \or% 4
  \tkzDefGoldenTriangle(#2,#3)
  \or% 5
  \tkzDefEuclideTriangle(#2,#3)
  \or% 6
  \tkzDefGoldTriangle(#2,#3) 
  \or% 7
  \tkzDefCheopsTriangle(#2,#3)  
  \or% 8
  \tkzDefTwoAnglesTriangle(#2,#3)  \fi    
\endgroup
}

\def\tkz@numdtr{0}
\pgfkeys{/drawtriangle/.cd,
equilateral/.code                    = {\global\def\tkz@numdtr{0}},
half/.code                           = {\global\def\tkz@numdtr{1}},
pythagore/.code                      = {\global\def\tkz@numdtr{2}},
school/.code                         = {\global\def\tkz@numdtr{3}},
golden/.code                         = {\global\def\tkz@numdtr{4}},
euclide/.code                        = {\global\def\tkz@numdtr{5}},
gold/.code                           = {\global\def\tkz@numdtr{6}},
cheops/.code                         = {\global\def\tkz@numdtr{7}},
two angles/.code  args={#1 and #2}  {  \global\def\tkz@numdtr{8}%
                                       \global\def\tkz@alpha{#1}%
                                       \global\def\tkz@beta{#2}},
/drawtriangle/.unknown/.code ={\let\searchname=\pgfkeyscurrentname
                             \pgfkeysalso{\searchname/.try=#1,
                             /tikz/\searchname/.retry=#1}}
} 

\def\tkzDrawTriangle{\pgfutil@ifnextchar[{\tkz@DrawTriangle}{%
                                         \tkz@DrawTriangle[]}}
\def\tkz@DrawTriangle[#1](#2,#3){% 
\begingroup
\pgfkeys{/drawtriangle/.cd,equilateral}   
\pgfqkeys{/drawtriangle}{#1}  
\ifcase\tkz@numdtr%
\tkzDefEquilateral(#2,#3)
\or% 1
\tkzDefTwoOne(#2,#3)
\or% 2
\tkzDefPythagore(#2,#3)
\or% 3
\tkzDefSchoolTriangle(#2,#3)
\or% 4
\tkzDefGoldenTriangle(#2,#3)
\or% 5
\tkzDefEuclideTriangle(#2,#3)
\or% 6
\tkzDefGoldTriangle(#2,#3) 
\or% 7
\tkzDefCheopsTriangle(#2,#3)  
\or% 8
\tkzDefTwoAnglesTriangle(#2,#3)  
\fi
 \draw[/drawtriangle/.cd,line style,#1] (#2)--(#3)--(tkzPointResult)--cycle;%    
\endgroup
}

%<--------------------------------------------------------------------------–>
%                       Droites particulières d'un triangle
%<--------------------------------------------------------------------------–>
%                                    median
%<--------------------------------------------------------------------------–>
\def\tkzDrawMedian{\pgfutil@ifnextchar[{\tkz@Median}{\tkz@Median[]}}
\def\tkz@Median[#1](#2,#3)(#4){%
\begingroup
   \tkzDefMidPoint(#3,#2)
   \tkzDrawLine[add= 0 and 0,#1](#4,tkzPointResult)
\endgroup
}

%<--------------------------------------------------------------------------–>
%                                    altitude
%<--------------------------------------------------------------------------–>
\def\tkzDrawAltitude{\pgfutil@ifnextchar[{\tkz@Altitude}{\tkz@Altitude[]}}
\def\tkz@Altitude[#1](#2,#3)(#4){%
\begingroup
    \tkzUProjection(#2,#3)(#4)
    \tkzDrawLine[add= 0 and 0,#1](#4,tkzPointResult)
\endgroup
}
%<--------------------------------------------------------------------------–>
%                          bisector
%<--------------------------------------------------------------------------–>
\def\tkzDrawBisector{\pgfutil@ifnextchar[{\tkz@Bisector}{\tkz@Bisector[]}}
\def\tkz@Bisector[#1](#2,#3,#4){%
\begingroup
    \tkzDefBisectorLine(#2,#3,#4)
    \tkzInterLL(#2,#4)(#3,tkzPointResult)
    \tkzDrawLine[add= 0 and 0,#1](#3,tkzPointResult)
\endgroup
}


%<---------------------------      square  ---------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzDefSquare(#1,#2){
\begingroup
 \tkzURotateAngle(#2,-90)(#1)\tkzGetPoint{tkzFirstPointResult}
 \tkzURotateAngle(#1, 90)(#2)\tkzGetPoint{tkzSecondPointResult}
\endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkzDrawSquare{\pgfutil@ifnextchar[{\tkz@DrawSquare}{%
                                         \tkz@DrawSquare[]}} 

\def\tkz@DrawSquare[#1](#2,#3){%
\begingroup
   \tkzDefSquare(#2,#3)
   \tkzDrawPolygon[#1](#2,#3,tkzFirstPointResult,tkzSecondPointResult)
\endgroup
}
%<--------------------------- gold rectangle -------------------------------–>
%
%<--------------------------------------------------------------------------–>

\def\tkzDefGoldRectangle(#1,#2){
\begingroup
 \tkzVecKOrth[-\tkzInvPhi](#2,#1){tkzFirstPointResult}
  \tkzVecKOrth[\tkzInvPhi](#1,#2){tkzSecondPointResult}
\endgroup
}
\def\tkzDrawGoldRectangle{\pgfutil@ifnextchar[{\tkz@DrawGoldRectangle}{%
                                         \tkz@DrawGoldRectangle[]}} 

\def\tkz@DrawGoldRectangle[#1](#2,#3){
\begingroup
 \tkzDefGoldRectangle(#2,#3)
 \tkzDrawPolygon[#1](#2,#3,tkzFirstPointResult,tkzSecondPointResult)
\endgroup
}

\endinput