% 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.13 c}
\def\filedate{2011/01/19}   


%<--------------------------------------------------------------------------–>
%                        Transformations Géométriques
%<--------------------------------------------------------------------------–>
\def\tkz@numtrsf{0}
\pgfkeys{/tkzDefPointBy/.cd,
translation/.code args={from #1 to #2}{%
                  \global\def\tkzfrom{#1}%
                  \global\def\tkzto{#2}%
                  \global\def\tkz@numtrsf{0}},
 homothety/.code args={center #1 ratio #2}{%
                  \global\def\tkzcenter{#1}%
                  \global\def\tkzratio{#2}%
                  \global\def\tkz@numtrsf{1}},
 reflection/.code args={over #1--#2}{%
                  \global\def\tkzdeb{#1}%
                  \global\def\tkzfin{#2}%
                  \global\def\tkz@numtrsf{2}},
 symmetry/.code args={center #1}{%
                  \global\def\tkzcenter{#1}%
                  \global\def\tkz@numtrsf{3}},
 projection/.code args={onto #1--#2}{%
                  \global\def\tkzdeb{#1}%
                  \global\def\tkzfin{#2}%  
                  \global\def\tkz@numtrsf{4}}, 
 rotation/.code args={center #1 angle #2}{%
                 \global\def\tkzcenter{#1}%
                 \global\def\tkzangle{#2}%
                 \global\def\tkz@numtrsf{5}},
 rotation in rad/.code args={center #1 angle #2}{%
                 \global\def\tkzcenter{#1}%
                 \global\def\tkzangle{#2}%
                 \global\def\tkz@numtrsf{6}},
inversion/.code args={center #1 through #2}{%
                 \global\def\tkzcenter{#1}%
                 \global\def\tkzpoint{#2}%
                 \global\def\tkz@numtrsf{7}} 
} 
%<--------------------------------------------------------------------------–>
\def\tkzDefPointsBy{\pgfutil@ifnextchar[{\tkz@DefPointsBy}{%
           \tkz@DefPointsBy[]}}
\def\tkz@DefPointsBy[#1](#2)#3{% 
\begingroup
\pgfqkeys{/tkzDefPointBy}{#1}  
\ifcase\tkz@numtrsf%
 % first case 0
  \tkzTranslation(\tkzfrom,\tkzto)(#2){#3}  
 \or% 1
  \tkzHomo(\tkzcenter,\tkzratio)(#2){#3}
 \or% 2
  \tkzSymOrth(\tkzdeb,\tkzfin)(#2){#3} 
 \or% 3
  \tkzCSym(\tkzcenter)(#2){#3}
 \or% 4
   \tkzProjection(\tkzdeb,\tkzfin)(#2){#3}
 \or% 5
  \tkzRotateAngle(\tkzcenter,\tkzangle)(#2){#3}
  \or% 6
  \tkzRotateInRad(\tkzcenter,\tkzangle)(#2){#3}
    \or% 7
  \tkzInversePoint(\tkzcenter,\tkzpoint)(#2){#3}    
\fi    
\endgroup
} 
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzDefPointBy{\pgfutil@ifnextchar[{\tkz@DefPointBy}{%
           \tkz@DefPointBy[]}}
\def\tkz@DefPointBy[#1](#2){% 
\begingroup 
\pgfqkeys{/tkzDefPointBy}{#1}    
 \ifcase\tkz@numtrsf%
%  % first case 0   
 \tkzUTranslation(\tkzfrom,\tkzto)(#2) 
 \or% 1
 \tkzUHomo(\tkzcenter,\tkzratio)(#2)
\or% 2
\tkzUSymOrth(\tkzdeb,\tkzfin)(#2) 
\or% 3
\tkzUCSym(\tkzcenter)(#2)
\or% 4
\tkzUProjection(\tkzdeb,\tkzfin)(#2)  
\or% 5  
\tkzURotateAngle(\tkzcenter,\tkzangle)(#2)
 \or% 6 
\tkzURotateInRad(\tkzcenter,\tkzangle)(#2)
 \or% 7
\tkzUInversePoint(\tkzcenter,\tkzpoint)(#2)     
\fi    
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\ExtractPoint#1,#2\@nil{% 
\global\edef\tkz@LastList{#2}
\global\edef\tkz@FirstPoint{#1}  
} 
\def\FirstPointInList#1{% 
\edef\tkz@templist{#1,}
\expandafter\ExtractPoint\tkz@templist\@nil
}
%<--------------------------------------------------------------------------–>
%  Translation par rapport à un point
%<--------------------------------------------------------------------------–>
\def\tkzTranslation(#1,#2)(#3)#4{%
\begingroup 
\global\def\tkz@LastList{#4}
    \foreach\PointTR in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointTR '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
  \tkzVecKCoLinear(#1,#2,\PointTR){\tkz@pointtsf}% 
}  
\endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkzUTranslation(#1,#2)(#3){%
\begingroup 
  \tkzVecKCoLinear(#1,#2,#3){tkzPointResult}% 
\endgroup
}  

%<--------------------------------------------------------------------------–>
%  Symétrie par rapport à un point Homo with (-1) 
% #2 le centre #3 l'antécédent 
%<--------------------------------------------------------------------------–>
\def\tkzCSym(#1)(#2)#3{%
\begingroup
\global\def\tkz@LastList{#3}
    \foreach\PointCS in {#2}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointCS '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
        \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                     {\pgfpointanchor{\PointCS}{center}}%
        \tkz@ax=\pgf@x%
        \tkz@ay=\pgf@y%
       \path(#1)--++(-\tkz@ax,-\tkz@ay)coordinate (\tkz@pointtsf); 
}       
\endgroup 
}
%<--------------------------------------------------------------------------–>
\def\tkzUCSym(#1)(#2){%
\begingroup
    \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                 {\pgfpointanchor{#2}{center}}%
    \tkz@ax=\pgf@x%
    \tkz@ay=\pgf@y%
   \path(#1)--++(-\tkz@ax,-\tkz@ay)coordinate (tkzPointResult); 
\endgroup 
} 
%<--------------------------------------------------------------------------–>
%  Symétrie orthogonale par rapport à une droite
%<--------------------------------------------------------------------------–> 
\def\tkzSymOrth(#1,#2)(#3)#4{%
\begingroup
\global\def\tkz@LastList{#4}
  \foreach\PointSO in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointSO '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
      \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                   {\pgfpointanchor{#2}{center}}%
      \tkz@ax =\pgf@y%
      \tkz@ay =\pgf@x%
      \path[coordinate]%
           (\PointSO)--++(-\tkz@ax,\tkz@ay) coordinate  (tkz@point);
      \tkzInterLL(#1,#2)(\PointSO,tkz@point)\tkzGetPoint{tkzPointofSym}
      \tkz@VecK[2](\PointSO,tkzPointofSym){\tkz@pointtsf}
}
\endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkzUSymOrth(#1,#2)(#3){%
\begingroup
      \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                   {\pgfpointanchor{#2}{center}}%
      \tkz@ax =\pgf@y%
      \tkz@ay =\pgf@x%
      \path[coordinate]%
           (#3)--++(-\tkz@ax,\tkz@ay) coordinate  (tkz@point);
      \tkzInterLL(#1,#2)(#3,tkz@point)\tkzGetPoint{tkzPointofSym}
      \tkz@VecK[2](#3,tkzPointofSym){tkzPointResult}
\endgroup
}

%<--------------------------------------------------------------------------–>
%  Projection orthogonale sur une droite
%<--------------------------------------------------------------------------–>
\def\tkzProjection(#1,#2)(#3)#4{%
\begingroup 
\global\def\tkz@LastList{#4}
    \foreach\PointPJ in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointPJ '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
  \tkzUProjection(#1,#2)(\PointPJ)    
  \tkzGetPoint{\tkz@pointtsf} 
  }    
\endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkzUProjection(#1,#2)(#3){%
\begingroup 
  \pgfpointdiff{\pgfpointanchor{#1}{center}}%
               {\pgfpointanchor{#2}{center}}%
  \tkz@ax =\pgf@y%
  \tkz@ay =\pgf@x%
  \path[coordinate](#3)--++(-\tkz@ax,\tkz@ay) coordinate (tkz@point);
  \tkzInterLL(#1,#2)(#3,tkz@point)% définit tkzPointResult 
\endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkz@Projection(#1,#2)(#3)#4{%
\begingroup 
  \pgfpointdiff{\pgfpointanchor{#1}{center}}%
               {\pgfpointanchor{#2}{center}}%
  \tkz@ax =\pgf@y%
  \tkz@ay =\pgf@x%
  \path[coordinate](#3)--++(-\tkz@ax,\tkz@ay) coordinate (tkz@point);
  \tkz@InterLL(#1,#2)(#3,tkz@point){#4}% définit tkzPointResult 
\endgroup
}
%<--------------------------------------------------------------------------–>
%  Homothétie par rapport à un point
%<--------------------------------------------------------------------------–>
\def\tkzHomo(#1,#2)(#3)#4{%
\begingroup 
\global\def\tkz@LastList{#4}
    \foreach\PointHO in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointHO '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
       \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                    {\pgfpointanchor{\PointHO}{center}}%
       \pgf@xa=\pgf@x%
       \pgf@ya=\pgf@y% 
      \pgfmathparse{#2}\edef\tkz@coeff{\pgfmathresult}%
      \path[coordinate](#1)--++(\tkz@coeff\pgf@xa,\tkz@coeff\pgf@ya)%
            coordinate(\tkz@pointtsf);
  }  
\endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkzUHomo(#1,#2)(#3){%
\begingroup 
       \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                    {\pgfpointanchor{#3}{center}}%
       \pgf@xa=\pgf@x%
       \pgf@ya=\pgf@y% 
      \pgfmathparse{#2}\edef\tkz@coeff{\pgfmathresult}%
      \path[coordinate](#1)--++(\tkz@coeff\pgf@xa,\tkz@coeff\pgf@ya)%
            coordinate(tkzPointResult);
\endgroup
}
%<--------------------------------------------------------------------------–>
%                 rotation  en degré
%<--------------------------------------------------------------------------–>
\def\tkzRotateAngle(#1,#2)(#3)#4{%
\begingroup
\global\def\tkz@LastList{#4}
    \foreach\PointRot in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointRot '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
        \tkz@@extractxy{\PointRot}
        \global\tkz@ax\pgf@x%
        \global\tkz@ay\pgf@y%
        \tkz@@extractxy{#1}
        \global\tkz@bx\pgf@x%
        \global\tkz@by\pgf@y%
        \tkzmathrotatepointaround{\pgfpoint{\tkz@ax}{\tkz@ay}}%
                                 {\pgfpoint{\tkz@bx}{\tkz@by}}%
                                 {#2}
        \global\tkz@bx\pgf@x%
        \global\tkz@by\pgf@y%
        \path[coordinate](\tkz@bx,\tkz@by)coordinate(\tkz@pointtsf);% 
        }   
  \endgroup
}
%<--------------------------------------------------------------------------–>
\def\tkzURotateAngle(#1,#2)(#3){%
\begingroup 
        \tkz@@extractxy{#3}
        \global\tkz@ax\pgf@x%
        \global\tkz@ay\pgf@y%
        \tkz@@extractxy{#1}
        \global\tkz@bx\pgf@x%
        \global\tkz@by\pgf@y%
        \tkzmathrotatepointaround{\pgfpoint{\tkz@ax}{\tkz@ay}}%
                                 {\pgfpoint{\tkz@bx}{\tkz@by}}%
                                 {#2}
        \global\tkz@bx\pgf@x%
        \global\tkz@by\pgf@y%
        \path[coordinate](\tkz@bx,\tkz@by)coordinate(tkzPointResult);%      
  \endgroup
}   
%<--------------------------------------------------------------------------–>
% %                 rotation  en radian
% %<--------------------------------------------------------------------------–>
\def\tkzRotateInRad(#1,#2)(#3)#4{%
\begingroup
\global\def\tkz@LastList{#4}
    \foreach\PointRot in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointRot '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
   \pgfmathparse{#2 r}
   \let\tkz@Angle\pgfmathresult
    \tkz@@extractxy{\PointRot}
    \tkz@ax\pgf@x%
    \tkz@ay\pgf@y%
    \tkz@@extractxy{#1}
    \tkz@bx\pgf@x%
    \tkz@by\pgf@y%
    \tkzmathrotatepointaround{\pgfpoint{\tkz@ax}{\tkz@ay}}%
                             {\pgfpoint{\tkz@bx}{\tkz@by}}%
                             {\tkz@Angle}
    \tkz@bx\pgf@x%
    \tkz@by\pgf@y%
    \path[coordinate](\tkz@bx,\tkz@by)coordinate(\tkz@pointtsf);  
}  
\endgroup 
}
%<--------------------------------------------------------------------------–>
\def\tkzURotateInRad(#1,#2)(#3){%
\begingroup
   \pgfmathparse{#2 r}
   \let\tkz@Angle\pgfmathresult
    \tkz@@extractxy{#3}
    \tkz@ax\pgf@x%
    \tkz@ay\pgf@y%
    \tkz@@extractxy{#1}
    \tkz@bx\pgf@x%
    \tkz@by\pgf@y%
    \tkzmathrotatepointaround{\pgfpoint{\tkz@ax}{\tkz@ay}}%
                             {\pgfpoint{\tkz@bx}{\tkz@by}}%
                             {\tkz@Angle}
    \tkz@bx\pgf@x%
    \tkz@by\pgf@y%
    \path[coordinate](\tkz@bx,\tkz@by)coordinate(tkzPointResult);  
\endgroup 
}
%<--------------------------------------------------------------------------–>
%                   Inverse of a point 
%<--------------------------------------------------------------------------–>
\def\tkzInversePoint(#1,#2)(#3)#4{%
\begingroup 
\global\def\tkz@LastList{#4}
    \foreach\PointIP in {#3}{%
      \FirstPointInList\tkz@LastList
      \ifx\tkz@FirstPoint\tkzutil@empty  
         \global\edef\tkz@pointtsf{\PointIP '}
      \else
         \global\edef\tkz@pointtsf{\tkz@FirstPoint}
      \fi 
   \tkzCalcLength[cm](#1,#2)\tkzGetLength{tkz@lna}% 
   \tkzCalcLength[cm](#1,\PointIP)\tkzGetLength{tkz@lnb}% 
   \FPeval\tkz@lnc{\tkz@lna/\tkz@lnb*\tkz@lna}
   \tkzVecKNorm[\tkz@lnc](#1,\PointIP){tkzPointResult}
   }  
\endgroup
} \def\tkzUInversePoint(#1,#2)(#3){%  
\begingroup  
   \tkzCalcLength[cm](#1,#2)\tkzGetLength{tkz@lna}% 
   \tkzCalcLength[cm](#1,#3)\tkzGetLength{tkz@lnb}% 
   \FPeval\tkz@lnc{\tkz@lna/\tkz@lnb*\tkz@lna}
   \tkzVecKNorm[\tkz@lnc](#1,#3){tkzPointResult}
\endgroup
} 
%<--------------------------------------------------------------------------–>
%                   Fin des transformations
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
%                   The SHOW
%<--------------------------------------------------------------------------–>
\def\tkz@numst{0}
\pgfkeys{/showtsf/.cd,
 reflection/.code args={over #1--#2}{%
                  \def\tkzdeb{#1}
                  \def\tkzfin{#2}
                  \def\tkz@numst{0}},  
 symmetry/.code args={center #1}{%
                  \def\tkzcenter{#1} 
                  \def\tkz@numst{1}},
 projection/.code args={onto #1--#2}{%
                  \def\tkzdeb{#1}
                  \def\tkzfin{#2}  
                  \def\tkz@numst{2}},
translation/.code args={from #1 to #2}{%
                  \def\tkzfrom{#1}%
                  \def\tkzto{#2}%
                  \def\tkz@numst{3}},  
  K/.code                = \def\tkz@koeff{#1}, 
  length/.code           = \def\tkz@show@length{#1},
  ratio/.code            = \def\tkz@show@ratio{#1},
  gap/.code              = \def\tkz@show@gap{#1},
  size/.code             = \def\tkz@show@size{#1},
/showtsf/.unknown/.code   = {\let\searchname=\pgfkeyscurrentname
                              \pgfkeysalso{\searchname/.try=#1,
                                   /compass/\searchname/.retry=#1,
                                   /tikz/\searchname/.retry=#1}}
}  
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzShowTransformation{\pgfutil@ifnextchar[{\tkz@ShowTransformation}{%
                                                 \tkz@ShowTransformation[]}}
\def\tkz@ShowTransformation[#1](#2){% 
\begingroup
 \pgfqkeys{/showtsf}{K=1,gap=2,size=1,ratio=.5,length=1}  
 \pgfqkeys{/showtsf}{#1}  
\ifcase\tkz@numst%
 % first case 0
  \tkzShowSymOrth[#1](\tkzdeb,\tkzfin)(#2)   
  \or% 1
  \tkzShowCSym[#1](\tkzcenter)(#2)
  \or% 2
   \tkzShowProjection[#1](\tkzdeb,\tkzfin)(#2) 
   \or% 3
    \tkzShowTranslation[#1](\tkzfrom,\tkzto)(#2) 
  \fi    
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzShowTranslation{\pgfutil@ifnextchar[{\tkz@ShowTranslation}{%
                                          \tkz@ShowTranslation[]}}  

\def\tkz@ShowTranslation[#1](#2,#3)(#4){%
\begingroup
\tkz@VecKCoLinear[1](#2,#3,#4){tkz@lltmp}
\tkzCompass[#1](#4,tkz@lltmp)
\tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](#3,tkz@lltmp)
\endgroup}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzShowSymOrth{\pgfutil@ifnextchar[{\tkz@ShowSymOrth}{%
                                          \tkz@ShowSymOrth[]}}  
\def\tkz@ShowSymOrth[#1](#2,#3)(#4){%
\begingroup
  \pgfpointdiff{\pgfpointanchor{#2}{center}}%
               {\pgfpointanchor{#3}{center}}%
  \tkz@ax =\pgf@y%
  \tkz@ay =\pgf@x%
  \path[coordinate](#4)--++(-\tkz@ax,\tkz@ay) coordinate (tkz@point);
  \tkzInterLL(#2,#3)(#4,tkz@point)  \tkzGetPoint{tkzPointofSym}
  \tkz@VecK[2](#4,tkzPointofSym){tkz@pointtsf}  
  \tkzCompass[#1](#2,#4)
  \tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](#3,#4)
  \tkzCompass[#1](#2,tkz@pointtsf)
  \tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](#3,tkz@pointtsf)   
\endgroup
} 
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzShowCSym{\pgfutil@ifnextchar[{\tkz@ShowCSym}{\tkz@ShowCSym[]}}
 
\def\tkz@ShowCSym[#1](#2)(#3){%
\begingroup
 \pgfpointdiff{\pgfpointanchor{#2}{center}}%
              {\pgfpointanchor{#3}{center}}%
 \tkz@ax=\pgf@x%
 \tkz@ay=\pgf@y%
\path[coordinate](#2)--++(-\tkz@ax,-\tkz@ay) coordinate (tkz@pointtsf); 
       \tkzCompass[#1](#2,tkz@pointtsf)
       \tkzCompass[#1](#2,#3)
\endgroup
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzShowProjection{\pgfutil@ifnextchar[{\tkz@ShowProjection}{%
                                          \tkz@ShowProjection[]}}  
\def\tkz@ShowProjection[#1](#2,#3)(#4){%
\begingroup 
  \pgfpointdiff{\pgfpointanchor{#2}{center}}%
               {\pgfpointanchor{#3}{center}}%
  \tkz@ax =\pgf@y%
  \tkz@ay =\pgf@x%     
  \path[coordinate](#4)--++(-\tkz@ax,\tkz@ay) coordinate (tkz@point);
  \tkzInterLL(#2,#3)(#4,tkz@point)\tkzGetPoint{tkz@pointtsf}
  \tkz@VecKCoLinear[1](#2,#3,tkz@pointtsf){SO@tmp1}
  \tkz@VecKCoLinear[-1](#2,#3,tkz@pointtsf){SO@tmp2}
  \tkz@VecKNorm[\tkz@show@size](tkz@pointtsf,SO@tmp1){SO@1}
  \tkz@VecKNorm[\tkz@show@size](tkz@pointtsf,SO@tmp2){SO@2}
  \tkz@VecKNorm[-\tkz@show@gap](tkz@pointtsf,#4){SO@3}
  \tkzCompass[#1](#4,SO@1)
  \tkzCompass[#1](#4,SO@2)
  \tkzCompass[#1](SO@1,SO@3)
  \tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](SO@2,SO@3)  
\endgroup
}   
  
\endinput