
\tikzstyle{circum} = []
\tikzstyle{bari} = []
\tikzstyle{ortho} = []
\tikzstyle{incenter} = []

\tikzstyle{mediatriz} = [circum,dotted,color=orange]
\tikzstyle{median} = [bari,dotted,color=red]
\tikzstyle{height} = [ortho,dotted,color=blue]
\tikzstyle{bisectriz} = [incenter,dotted,color=green]

% \DrawPoint{P}{Pname}{pos}
\newcommand{\DrawPoint}[3]
{
   \filldraw #1 circle(1pt) node[#3] {$#2$};
}

% \GetVector{P1}{P2}.
% Store in (V)
\newcommand{\GetVector}[2]
{
   \coordinate (V) at ($#2-#1$);
}

% \DotProduct{vv}{ww}
% Store in \DOT
\newcommand{\DotProduct}[2]
{
   \gettikzxy{#1}{\xtmp}{\ytmp};
   \gettikzxy{#2}{\xxtmp}{\yytmp};
   
   \pgfmathparse{sqrt(\xtmp*\xxtmp+\ytmp*\yytmp)} \let\DOT\pgfmathresult;
}

% \SqLength{vv}{ww}
% Store in \DOT
\newcommand{\SqLength}[2]
{
   \DotProduct{#1}{#1};
}

% \Determinant{vv}{ww}
% Store in \DET
\newcommand{\Determinant}[2]
{
   \gettikzxy{#1}{\xtmp}{\ytmp};
   \gettikzxy{#2}{\xxtmp}{\yytmp};
   
   \pgfmathparse{\xtmp*\yytmp-\xxtmp*\ytmp} \let\DET\pgfmathresult;
}

% \Length{vv{ww}
% Store in \LEN
\newcommand{\Length}[1]
{
   \DotProduct{#1}{#1};
   \pgfmathparse{sqrt(\DOT)} \let\LEN\pgfmathresult;   
}

% \GetPerpendicular{P}{v}
% Store in (N)
\newcommand{\GetPerpendicular}[1]
{
   %Get V coords (in pt)
   \gettikzxy{#1}{\xtmp}{\ytmp};
   \coordinate (N) at (-\ytmp,\xtmp);
}

% \GetNormal{P}{v}
% Store in (N)
\newcommand{\GetNormal}[1]
{
   \Length{#1};
   \pgfmathparse{sqrt(\DOT)} \let\LEN\pgfmathresult;
   
   
   %Get V coords (in pt)
   \gettikzxy{#1}{\xtmp}{\ytmp};
   
   %Calculaty len
   \pgfmathparse{sqrt(\xtmp*\xtmp+\ytmp*\ytmp)} \let\LEN\pgfmathresult;
   
   %Normalize
   \pgfmathparse{1/\LEN*\xtmp} \let\xtmp\pgfmathresult;
   \pgfmathparse{1/\LEN*\ytmp} \let\ytmp\pgfmathresult;
   
  
   \coordinate (N) at (-\ytmp,\xtmp);
}

% \DrawConvex{P}{Q}{t}
\newcommand{\DrawConvex}[4]
{
   \draw[#4] ($#1!#3!#2$) -- ($#2!#3!#1$);
}

% \DrawTriangleHeight{A}{B}{C}
\newcommand{\DrawTriangleHeightOld}[3]
{   
   %Projection on point #1 on #2 and #3
   \coordinate (P) at ($#2!#1!#3$);
   \DrawPoint{(P)}{P}{below};
   
   %Orthogonal Complement of point #1
   \coordinate (N) at ($(P)-#1$);
   \draw[-latex] (P) -- +(N);
}

% \DrawTriangle{A}{B}{C}
\newcommand{\DrawTriangle}[3]
{
   \draw
      #1 circle(1pt)
      --
      #2 circle(1pt)
      --
      #3 circle(1pt)
      --
      #1;
}
% \DrawMidPoint{A}{B}{title}{sty}
\newcommand{\DrawMidPoint}[4]
{  
   \filldraw
      ($0.5*#1+0.5*#2$)
      circle(1pt)
      node[#4]
      {\scriptsize{#3}};
}
% \DrawTriangleMidPoints{A}{B}{C}{title}{sty}
\newcommand{\DrawTriangleMidPoints}[3]
{  
   \DrawMidPoint{#2}{#3}
   {$\underline{m}_1$}
   {above};
   \DrawMidPoint{#3}{#1}
   {$\underline{m}_2$}
   {left};
   \DrawMidPoint{#1}{#2}
   {$\underline{m}_3$}
   {below};
}

% \DrawTriangleMedian{A}{B}{C}{linesty}
\newcommand{\DrawTriangleMedian}[3]
{  
   \draw[median]
      ($1/3*#1+1/3*#2+1/3*#3$)
      --
      +($0.5*#1 + 0.5*#2 -1*#3$);
      
   \draw[median]
      ($1/3*#1+1/3*#2+1/3*#3$)
      --
      +($-0.5*#1 - 0.5*#2 + #3$);
}


% \DrawTriangleMedians{A}{B}{C}{sty}
\newcommand{\DrawTriangleMedians}[3]
{   
   \DrawTriangleMedian{#1}{#2}{#3}{1};
   \DrawTriangleMedian{#2}{#3}{#1}{2};
   \DrawTriangleMedian{#3}{#1}{#2}{3};
}

% \DrawTriangleBaricenter{A}{B}{C}{sty}
\newcommand{\DrawTriangleBaricenter}[3]
{
   \filldraw[bari]
      ($1/3*#1+1/3*#2+1/3*#3$)
      circle(1pt) node[left] {B};
}

% \DrawMediatriz{A}{B}{C}{sty}
\newcommand{\DrawTriangleMediatriz}[4]
{
   \coordinate (M) at ($#1!0.5!#2$);
   \coordinate (v) at ($#2 - #1$);
   
   \GetPerpendicular{(v)};
   
   \draw[mediatriz] 
      ($(M)+(N)$)
      --
      (M)
      --
      ($(M)-0.3*(N)$)
      node {$#4$};
}

% \DrawMediatrizes{A}{B}{C}{sty}
\newcommand{\DrawTriangleMediatrizes}[3]
{
   \DrawTriangleMediatriz{#1}{#2}{#3}{1};
   \DrawTriangleMediatriz{#2}{#3}{#1}{2};
   \DrawTriangleMediatriz{#3}{#1}{#2}{3};   
}

% \DrawCircumCenter{A}{B}{C}{sty}
\newcommand{\DrawTriangleCircumCenter}[3]
{   
   %Translate so first point in (0,0)
   \coordinate (V) at ($#2 - #1$);
   \coordinate (W) at ($#3 - #1$);
   
   \gettikzxy{(V)}{\vx}{\vy};
   \gettikzxy{(W)}{\wx}{\wy};
   
   %Lengths
   \pgfmathparse{\vx*\vx+\vy*\vy} \let\rv\pgfmathresult;
   \pgfmathparse{\wx*\wx+\wy*\wy} \let\rw\pgfmathresult;
 
   %Determinant
   \pgfmathparse{\vx*\wy-\vy*\wx} \let\deter\pgfmathresult;
   
   %Circum center
   \pgfmathparse{\wy*\rv-\vy*\rw} \let\x\pgfmathresult;
   \pgfmathparse{\vx*\rw-\wx*\rv} \let\y\pgfmathresult;
   
   \pgfmathparse{0.5*\x/\deter} \let\x\pgfmathresult;
   \pgfmathparse{0.5*\y/\deter} \let\y\pgfmathresult;
   
   \coordinate (Circum) at (\x,\y);
   \coordinate (Circum) at ($(Circum)+#1$);
   \filldraw[circum] (Circum) circle(1pt) node[right] {$C$};
   
   \pgfmathparse{\x*\x+\y*\y} \let\r\pgfmathresult;
   \pgfmathparse{sqrt(\r)} \let\r\pgfmathresult;
   \draw[circum,very thin,dotted] (Circum) circle(\r);
}


% \DrawHeight{A}{B}{C}{sty}{txt}
\newcommand{\DrawTriangleHeight}[4]
{
   \coordinate (v) at ($#3 - #2$);
   \GetPerpendicular{(v)};
   
   \coordinate (M) at ($#2!#1!#3$);
   \draw[height,name path=height#4] 
      ($(M)+(N)$)
      --
      (M)
      --
      ($(M)-(N)$)
      node {$#4$};
}

% \DrawTriangleHeights{A}{B}{C}{sty}
\newcommand{\DrawTriangleHeights}[4]
{
   \DrawTriangleHeight{#1}{#2}{#3}{1};
   \DrawTriangleHeight{#2}{#3}{#1}{2};
   \DrawTriangleHeight{#3}{#1}{#2}{3};
   
   \path [name intersections={of=height1 and height2,by=C}];
   \filldraw[ortho] (C) circle(1pt) node[above] {O};
}

% \DrawTriangleBisectriz{A}{B}{C}{sty}{txt}
\newcommand{\DrawTriangleBisectriz}[4]
{
   \coordinate (v) at ($#2 - #1$);
   \coordinate (M) at ($#3 + (v)$);
   \filldraw (M) circle(1pt);
   
   \draw[bisectriz,name path=bisectriz#4] 
      #1
      --
      (M)
      node {$#4$};
}
% \DrawTriangleBisectrizes{A}{B}{C}{sty}
\newcommand{\DrawTriangleBisectrizes}[3]
{
   \DrawTriangleBisectriz{#1}{#2}{#3}{1};
   \DrawTriangleBisectriz{#2}{#3}{#1}{2};
   \DrawTriangleBisectriz{#3}{#1}{#2}{3};
   
   \path [name intersections={of=bisectriz1 and bisectriz2,by=C}];
   \filldraw[incenter] (C) circle(1pt) node[below] {I};
}

