%%%
% Trigonom\'etrie
%%%
\def\filedateTrigo{2025/12/24}%
\def\fileversionTrigo{0.1a}%
\message{-- \filedateTrigo\space v\fileversionTrigo}%
%
\def\MPFigTrigo#1#2#3#4#5#6#7#8{%
  \mplibforcehmode%
  \begin{mplibcode}
    defaultcolormodel := \useKV[ClesTrigo]{ModeleCouleur};
    u:=\useKV[ClesTrigo]{Echelle};
    pair A,B,C,O,I,D,E,F;%
    % On place les points A,B,C sur le cercle de mani\`ere \`a faciliter la rotation de la figure
    A=u*(1,1);
    B-A=u*(3,0);
    C=(A--2[A,B rotatedabout(A,50)]) intersectionpoint (B--2[B,A rotatedabout(B,-90)]);
    % On d\'efinit le centre du cercle circonscrit
    O - .5[A,B] = whatever * (B-A) rotated 90;
    O - .5[B,C] = whatever * (C-B) rotated 90;
    % On tourne pour \'eventuellement moins de lassitude :)
    A:=A rotatedabout(O,#8);
    B:=B rotatedabout(O,#8);
    C:=C rotatedabout(O,#8);
    % On d\'efinit le centre du cercle inscrit
    (I-C) rotated ((angle(A-C)-angle(B-C))/2) shifted C=whatever[A,C];
    (I-B) rotated ((angle(C-B)-angle(A-B))/2) shifted B=whatever[B,C];
    % on dessine \`a main lev\'ee :)
    path triangle;
    triangle=A{dir(angle(B-A)+5)}..B{dir(angle(B-A)+5)}--B{dir(angle(C-B)+5)}..C{dir(angle(C-B)+5)}--C{dir(angle(A-C)+5)}..A{dir(angle(A-C)+5)}--cycle;
    % on d\'efinit l'angle droit
    D-B=7*unitvector(C-B);
    F-B=7*unitvector(A-B);
    E-D=F-B;
    draw D{dir(angle(E-D)+5)}..E{dir(angle(E-D)+5)}--E{dir(angle(F-E)+5)}..F{dir(angle(F-E)+5)};
    % L'angle :)
    path cc;
    cc=fullcircle scaled 1u;
    % on marque les angles
    picture MAngle;
    MAngle=image(
    draw (cc shifted A);
    );
    draw MAngle;
    clip currentpicture to triangle;
    draw A{dir(angle(B-A)+5)}..B{dir(angle(B-A)+5)};
    draw B{dir(angle(C-B)+5)}..C{dir(angle(C-B)+5)};
    draw C{dir(angle(A-C)+5)}..A{dir(angle(A-C)+5)};
    % on labelise
    picture z;
    label(btex $#1$ etex,1.15[O,A]);
    label(btex $#2$ etex,1.15[O,B]);
    label(btex $#3$ etex,1.15[O,C]);
    label(btex \ang{#7} etex,A+0.95u*unitvector(I-A));
    decalage:=3mm;
    if #6<0:
    else:
    if angle(1/2[A,C]-B)>0:
      if #6=0:
        label(btex ? etex,1.1[B,1/2[A,C]]);
      else:
        label(btex \num{#6} etex,1.2[B,1/2[A,C]]);
      fi;
    else:
      if #6=0:
        label(btex ? etex,1.1[B,1/2[A,C]]);
      else:
        label(btex \num{#6} etex,1.2[B,1/2[A,C]]);
      fi;
    fi;
  fi;   
  if #4<0:
  else:
    if angle(1/2[B,C]-A)>0:
      if #4=0:
        label(btex ? etex,1/2[B,C]-decalage*(unitvector(A-B)));
      else:
        label(btex \num{#4} etex,1/2[B,C]-decalage*(unitvector(A-B)));
      fi;
    else:
      if #4=0:
        label(btex ? etex,1/2[B,C]-decalage*(unitvector(A-B)));
      else:
        label(btex \num{#4} etex,1/2[B,C]-decalage*(unitvector(A-B)));
      fi;
    fi;
  fi;
  if #5<0:
  else:
    if angle(1/2[A,B]-C)>0:
      if #5=0:
        label(btex ? etex,1/2[A,B]-decalage*(unitvector(C-B)));
      else:
        label(btex \num{#5} etex,1/2[A,B]-decalage*(unitvector(C-B)));
      fi;
    else:
      if #5=0:
        label(btex ? etex,1/2[A,B]-decalage*(unitvector(C-B)));
      else:
        label(btex \num{#5} etex,1/2[A,B]-decalage*(unitvector(C-B)));
      fi;
    fi;
    fi;
  \end{mplibcode}%
}%

\def\MPFigTrigoAngle#1#2#3#4#5#6#7{%
  % #1 A
  % #2 B
  % #3 C
  % #4 opp
  % #5 adj
  % #6 hyp
  % #7 angle de rotation
  \mplibforcehmode%
  \begin{mplibcode}
    defaultcolormodel := \useKV[ClesTrigo]{ModeleCouleur};
    u:=\useKV[ClesTrigo]{Echelle};
    pair A,B,C,O,I,D,E,F;%
    A=u*(1,1);
    B-A=u*(3,0);
    C=(A--2[A,B rotatedabout(A,50)]) intersectionpoint (B--2[B,A rotatedabout(B,-90)]);
    % On d\'efinit le centre du cercle circonscrit
    O - .5[A,B] = whatever * (B-A) rotated 90;
    O - .5[B,C] = whatever * (C-B) rotated 90;
    % On tourne pour \'eventuellement moins de lassitude :)
    A:=A rotatedabout(O,#7);
    B:=B rotatedabout(O,#7);
    C:=C rotatedabout(O,#7);
    % On d\'efinit le centre du cercle inscrit
    (I-C) rotated ((angle(A-C)-angle(B-C))/2) shifted C=whatever[A,C];
    (I-B) rotated ((angle(C-B)-angle(A-B))/2) shifted B=whatever[B,C];
    % on dessine \`a main lev\'ee :)
    path triangle;
    triangle=A{dir(angle(B-A)+5)}..B{dir(angle(B-A)+5)}--B{dir(angle(C-B)+5)}..C{dir(angle(C-B)+5)}--C{dir(angle(A-C)+5)}..A{dir(angle(A-C)+5)}--cycle;
    % on d\'efinit l'angle droit
    D-B=7*unitvector(C-B);
    F-B=7*unitvector(A-B);
    E-D=F-B;
    draw D{dir(angle(E-D)+5)}..E{dir(angle(E-D)+5)}--E{dir(angle(F-E)+5)}..F{dir(angle(F-E)+5)};
    % L'angle :)
    path cc;
    cc=fullcircle scaled 1u;
    % on marque les angles
    picture MAngle;
    MAngle=image(
    draw (cc shifted A);
    );
    draw MAngle;
    clip currentpicture to triangle;
    draw A{dir(angle(B-A)+5)}..B{dir(angle(B-A)+5)};
    draw B{dir(angle(C-B)+5)}..C{dir(angle(C-B)+5)};
    draw C{dir(angle(A-C)+5)}..A{dir(angle(A-C)+5)};
    % on labelise
    label(btex $#1$ etex,1.15[O,A]);
    label(btex $#2$ etex,1.15[O,B]);
    label(btex $#3$ etex,1.15[O,C]);
    label(btex ? etex,A+0.95u*unitvector(I-A));
    decalage:=3mm;
    if #6>0:
    if angle(1/2[A,C]-B)>0:
      label(btex \num{#6} etex,1.2[B,1/2[A,C]]);
    else:
      label(btex \num{#6} etex,1.2[B,1/2[A,C]]);
    fi;
  fi;
  if #4>0:
    if angle(1/2[B,C]-A)>0:
      label(btex \num{#4} etex,1/2[B,C]-decalage*(unitvector(A-B)));
    else:
      label(btex \num{#4} etex,1/2[B,C]-decalage*(unitvector(A-B)));
    fi;
  fi;
  if #5>0:
    if angle(1/2[A,B]-C)>0:
      label(btex \num{#5} etex,1/2[A,B]-decalage*(unitvector(C-B)));
    else:
      label(btex \num{#5} etex,1/2[A,B]-decalage*(unitvector(C-B)));
    fi;
  fi;
\end{mplibcode}
}%

\setKVdefault[ClesTrigo]{Angle=0,Propor=false,Figure=false,FigureSeule=false,ValeurExacte=false,Precision=2,Unite=cm,Sinus=false,Cosinus=false,Tangente=false,Perso=false,Echelle=1cm,ModeleCouleur=5}%

\newcommand\RedactionTrigo{}%

\newcommand\TrigoCalculs[5][]{%
  \setKV[ClesTrigo]{#1}%
  % #1 Cl\'es
  % #2 Nom du triangle ABC, rectangle en B, angle connu ou pas : BAC
  % #3 Longueur #4 Longueur #5 angle
  % On d\'efinit les points
  \DeclareSIUnit{\PfCTrigoUnit}{\useKV[ClesTrigo]{Unite}}%
  \StrMid{#2}{1}{1}[\NomA]%
  \StrMid{#2}{2}{2}[\NomB]%
  \StrMid{#2}{3}{3}[\NomC]%
  \xdef\NomTriangle{\NomA\NomB\NomC}%
  \xdef\NomAngleDroit{\NomB}%
  \xdef\NomSommetA{\NomA}%
  \xdef\NomSommetB{\NomB}%
  \xdef\NomSommetC{\NomC}%
  \ifboolKV[ClesTrigo]{Perso}{%
    \RedactionTrigo%
  }{%
    Dans le triangle $\NomA\NomB\NomC$, rectangle en $\NomB$, on a :%
  }%
  \ifboolKV[ClesTrigo]{Cosinus}{%
    \ifx\bla#3\bla%on calcule le c\^ot\'e adjacent
    \xdef\ResultatTrigo{\fpeval{round(#4*cosd(#5),\useKV[ClesTrigo]{Precision})}}%
   \ifboolKV[ClesTrigo]{Propor}{%
     \begin{align*}
       \NomA\NomC\times\cos(\widehat{\NomB\NomA\NomC})&=\NomA\NomB\\
       \num{#4}\times\cos(\ang{#5})&=\NomA\NomB%\\
       \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\
       \SI{\fpeval{round(#4*cosd(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}&\IfInteger{\fpeval{round(#4*cosd(#5),9)}}{=}{\approx}\NomA\NomB}
      \end{align*}%
    }{%
      \begin{align*}
        \cos(\widehat{\NomB\NomA\NomC})&=\frac{\NomA\NomB}{\NomA\NomC}\\
        \cos(\ang{#5})&=\frac{\NomA\NomB}{\num{#4}}\\
        \num{#4}\times\cos(\ang{#5})&=\NomA\NomB%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \SI{\fpeval{round(#4*cosd(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}&\IfInteger{\fpeval{round(#4*cosd(#5),9)}}{=}{\approx}\NomA\NomB}%
      \end{align*}
    }%
    \else%
    \ifx\bla#4\bla%on calcule l'hypoth\'enuse
    \xdef\ResultatTrigo{\fpeval{round(#3/cosd(#5),\useKV[ClesTrigo]{Precision})}}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomC\times\cos(\widehat{\NomB\NomA\NomC})&=\NomA\NomB\\
        \NomA\NomC\times\cos(\ang{#5})&=\num{#3}\\
        \NomA\NomC&=\frac{\num{#3}}{\cos(\ang{#5})}%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \NomA\NomC&\IfInteger{\fpeval{round(#3/cosd(#5),9)}}{=}{\approx}\SI{\fpeval{round(#3/cosd(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}}%
      \end{align*}
    }{%
      \begin{align*}
        \cos(\widehat{\NomB\NomA\NomC})&=\frac{\NomA\NomB}{\NomA\NomC}\\
        \cos(\ang{#5})&=\frac{\num{#3}}{\NomA\NomC}\\
        \NomA\NomC&=\frac{\num{#3}}{\cos(\ang{#5})}%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \NomA\NomC&\IfInteger{\fpeval{round(#3/cosd(#5),9)}}{=}{\approx}\SI{\fpeval{round(#3/cosd(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}}%
      \end{align*}%
    }%
    \else%on calcule l'angle
    \xdef\ResultatTrigo{\fpeval{round(acosd(#3/#4),\useKV[ClesTrigo]{Precision})}}%
    \setKV[ClesTrigo]{Precision=0}%
    \setKV[ClesTrigo]{#1}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomC\times\cos(\widehat{\NomB\NomA\NomC})&=\NomA\NomB\\
        \num{#4}\times\cos(\widehat{\NomB\NomA\NomC})&=\num{#3}\\
        \cos(\widehat{\NomB\NomA\NomC})&=\frac{\num{#3}}{\num{#4}}\\
        \widehat{\NomB\NomA\NomC}&\IfInteger{\fpeval{round(acosd(#3/#4),9)}}{=}{\approx}\ang{\fpeval{round(acosd(#3/#4),\useKV[ClesTrigo]{Precision})}}%
      \end{align*}%
    }{%
      \begin{align*}
        \cos(\widehat{\NomB\NomA\NomC})&=\frac{\NomA\NomB}{\NomA\NomC}\\
        \cos(\widehat{\NomB\NomA\NomC})&=\frac{\num{#3}}{\num{#4}}\\
        \widehat{\NomB\NomA\NomC}&\IfInteger{\fpeval{round(acosd(#3/#4),9)}}{=}{\approx}\ang{\fpeval{round(acosd(#3/#4),\useKV[ClesTrigo]{Precision})}}%
      \end{align*}%
    }%
    \fi%
    \fi%
  }{}%
  \ifboolKV[ClesTrigo]{Sinus}{%
    \ifx\bla#3\bla%on calcule le c\^ot\'e oppos\'e
    \xdef\ResultatTrigo{\fpeval{round(#4*sind(#5),\useKV[ClesTrigo]{Precision})}}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomC\times\sin(\widehat{\NomB\NomA\NomC})&=\NomB\NomC\\
        \num{#4}\times\sin(\ang{#5})&=\NomB\NomC%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \SI{\fpeval{round(#4*sind(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}&\IfInteger{\fpeval{round(#4*sind(#5),9)}}{=}{\approx}\NomB\NomC}%
      \end{align*}%
    }{%
      \begin{align*}
        \sin(\widehat{\NomB\NomA\NomC})&=\frac{\NomB\NomC}{\NomA\NomC}\\
        \sin(\ang{#5})&=\frac{\NomB\NomC}{\num{#4}}\\
        \num{#4}\times\sin(\ang{#5})&=\NomB\NomC%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \SI{\fpeval{round(#4*sind(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}&\IfInteger{\fpeval{round(#4*sind(#5),9)}}{=}{\approx}\NomB\NomC}%
      \end{align*}%
    }%
    \else
    \ifx\bla#4\bla%on calcule l'hypoth\'enuse
    \xdef\ResultatTrigo{\fpeval{round(#3/sind(#5),\useKV[ClesTrigo]{Precision})}}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomC\times\sin(\widehat{\NomB\NomA\NomC})&=\NomB\NomC\\
        \NomA\NomC\times\sin(\ang{#5})&=\num{#3}\\
        \NomA\NomC&=\frac{\num{#3}}{\sin(\ang{#5})}%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \NomA\NomC&\IfInteger{\fpeval{round(#3/sind(#5),9)}}{=}{\approx}\SI{\fpeval{round(#3/sind(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}}%
      \end{align*}%
    }{%
      \begin{align*}
        \sin(\widehat{\NomB\NomA\NomC})&=\frac{\NomB\NomC}{\NomA\NomC}\\
        \sin(\ang{#5})&=\frac{\num{#3}}{\NomA\NomC}\\
        \NomA\NomC&=\frac{\num{#3}}{\sin(\ang{#5})}%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \NomA\NomC&\IfInteger{\fpeval{round(#3/sind(#5),9)}}{=}{\approx}\SI{\fpeval{round(#3/sind(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}}%
      \end{align*}%
    }%
    \else%on calcule l'angle
    \xdef\ResultatTrigo{\fpeval{round(asind(#3/#4),\useKV[ClesTrigo]{Precision})}}%
    \setKV[ClesTrigo]{Precision=0}%
    \setKV[ClesTrigo]{#1}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomC\times\sin(\widehat{\NomB\NomA\NomC})&=\NomB\NomC\\
        \num{#4}\times\sin(\widehat{\NomB\NomA\NomC})&=\num{#3}\\
        \sin(\widehat{\NomB\NomA\NomC})&=\frac{\num{#3}}{\num{#4}}\\
        \widehat{\NomB\NomA\NomC}&\IfInteger{\fpeval{round(asind(#3/#4),9)}}{=}{\approx}\ang{\fpeval{round(asind(#3/#4),\useKV[ClesTrigo]{Precision})}}%
      \end{align*}%
    }{%
      \begin{align*}
        \sin(\widehat{\NomB\NomA\NomC})&=\frac{\NomB\NomC}{\NomA\NomC}\\
        \sin(\widehat{\NomB\NomA\NomC})&=\frac{\num{#3}}{\num{#4}}\\
        \widehat{\NomB\NomA\NomC}&\IfInteger{\fpeval{round(asind(#3/#4),9)}}{=}{\approx}\ang{\fpeval{round(asind(#3/#4),\useKV[ClesTrigo]{Precision})}}%
      \end{align*}%
    }%
    \fi%
    \fi%
  }{}%
  \ifboolKV[ClesTrigo]{Tangente}{%
    \ifx\bla#3\bla%on calcule le c\^ot\'e oppos\'e
    \xdef\ResultatTrigo{\fpeval{round(#4*tand(#5),\useKV[ClesTrigo]{Precision})}}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomB\times\tan(\widehat{\NomB\NomA\NomC})&=\NomB\NomC\\%
        \num{#4}\times\tan(\ang{#5})&=\NomB\NomC%\\%
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \SI{\fpeval{round(#4*tand(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}&\IfInteger{\fpeval{round(#4*tand(#5),9)}}{=}{\approx}\NomB\NomC}%
      \end{align*}%
    }{%
      \begin{align*}
        \tan(\widehat{\NomB\NomA\NomC})&=\frac{\NomB\NomC}{\NomA\NomB}\\
        \tan(\ang{#5})&=\frac{\NomB\NomC}{\num{#4}}\\
        \num{#4}\times\tan(\ang{#5})&=\NomB\NomC%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \SI{\fpeval{round(#4*tand(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}&\IfInteger{\fpeval{round(#4*tand(#5),9)}}{=}{\approx}\NomB\NomC}%
      \end{align*}%
    }%
    \else
    \ifx\bla#4\bla%on calcule l'adjacent
    \xdef\ResultatTrigo{\fpeval{round(#3/tand(#5),\useKV[ClesTrigo]{Precision})}}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomB\times\tan(\widehat{\NomB\NomA\NomC})&=\NomB\NomC\\
        \NomA\NomB\times\tan(\ang{#5})&=\num{#3}\\
        \NomA\NomB&=\frac{\num{#3}}{\tan(\ang{#5})}%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \NomA\NomB&\IfInteger{\fpeval{round(#3/tand(#5),9)}}{=}{\approx}\SI{\fpeval{round(#3/tand(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}}%
      \end{align*}%
    }{%
      \begin{align*}
        \tan(\widehat{\NomB\NomA\NomC})&=\frac{\NomB\NomC}{\NomA\NomB}\\
        \tan(\ang{#5})&=\frac{\num{#3}}{\NomA\NomB}\\
        \NomA\NomB&=\frac{\num{#3}}{\tan(\ang{#5})}%\\
        \ifboolKV[ClesTrigo]{ValeurExacte}{}{\\%
        \NomA\NomB&\IfInteger{\fpeval{round(#3/tand(#5),9)}}{=}{\approx}\SI{\fpeval{round(#3/tand(#5),\useKV[ClesTrigo]{Precision})}}{\PfCTrigoUnit}}%
      \end{align*}%
    }%
    \else%on calcule l'angle
    \setKV[ClesTrigo]{Precision=0}%
    \setKV[ClesTrigo]{#1}%
    \xdef\ResultatTrigo{\fpeval{round(atand(#3/#4),\useKV[ClesTrigo]{Precision})}}%
    \ifboolKV[ClesTrigo]{Propor}{%
      \begin{align*}
        \NomA\NomB\times\tan(\widehat{\NomB\NomA\NomC})&=\NomB\NomC\\
        \num{#4}\times\tan(\widehat{\NomB\NomA\NomC})&=\num{#3}\\
        \tan(\widehat{\NomB\NomA\NomC})&=\frac{\num{#3}}{\num{#4}}\\
        \widehat{\NomB\NomA\NomC}&\IfInteger{\fpeval{round(atand(#3/#4),9)}}{=}{\approx}\ang{\fpeval{round(atand(#3/#4),\useKV[ClesTrigo]{Precision})}}%
      \end{align*}%
    }{%
      \begin{align*}
        \tan(\widehat{\NomB\NomA\NomC})&=\frac{\NomB\NomC}{\NomA\NomB}\\
        \tan(\widehat{\NomB\NomA\NomC})&=\frac{\num{#3}}{\num{#4}}\\
        \widehat{\NomB\NomA\NomC}&\IfInteger{\fpeval{round(atand(#3/#4),9)}}{=}{\approx}\ang{\fpeval{round(atand(#3/#4),\useKV[ClesTrigo]{Precision})}}%
      \end{align*}%
    }%
    \fi%
    \fi%
  }{}%
}%

\newcommand\Trigo[5][]{%
  \useKVdefault[ClesTrigo]%
  \setKV[ClesTrigo]{#1}%
  % #1 Cl\'es
  % #2 Nom du triangle ABC, rectangle en B, angle connu ou pas : BAC
  % #3 Longueur #4 Longueur #5 angle
  % On d\'efinit les points
  \StrMid{#2}{1}{1}[\NomA]%
  \StrMid{#2}{2}{2}[\NomB]%
  \StrMid{#2}{3}{3}[\NomC]%
  % On r\'edige
  \ifboolKV[ClesTrigo]{FigureSeule}{%
    \ifx\bla#5\bla%
    \ifboolKV[ClesTrigo]{Cosinus}{%
      \MPFigTrigoAngle{\NomA}{\NomB}{\NomC}{-1}{#3}{#4}{\useKV[ClesTrigo]{Angle}}
    }{}%
    \ifboolKV[ClesTrigo]{Sinus}{%
      \MPFigTrigoAngle{\NomA}{\NomB}{\NomC}{#3}{-1}{#4}{\useKV[ClesTrigo]{Angle}}
    }{}%
    \ifboolKV[ClesTrigo]{Tangente}{%
      \MPFigTrigoAngle{\NomA}{\NomB}{\NomC}{#3}{#4}{-1}{\useKV[ClesTrigo]{Angle}}
    }{}%
    \else%}{%figure pour calculer une longueur
    \ifboolKV[ClesTrigo]{Cosinus}{%
      \ifx\bla#3\bla%adjacent inconnu
        \MPFigTrigo{\NomA}{\NomB}{\NomC}{-1}{0}{#4}{#5}{\useKV[ClesTrigo]{Angle}}
      \else%
        \MPFigTrigo{\NomA}{\NomB}{\NomC}{-1}{#3}{0}{#5}{\useKV[ClesTrigo]{Angle}}
      \fi
    }{}%
    \ifboolKV[ClesTrigo]{Sinus}{%
      \ifx\bla#3\bla%adjacent inconnu
        \MPFigTrigo{\NomA}{\NomB}{\NomC}{0}{-1}{#4}{#5}{\useKV[ClesTrigo]{Angle}}
      \else
        \MPFigTrigo{\NomA}{\NomB}{\NomC}{#3}{-1}{0}{#5}{\useKV[ClesTrigo]{Angle}}
      \fi
    }{}%
    \ifboolKV[ClesTrigo]{Tangente}{%
      \ifx\bla#3\bla%adjacent inconnu
      \MPFigTrigo{\NomA}{\NomB}{\NomC}{0}{#4}{-1}{#5}{\useKV[ClesTrigo]{Angle}}
      \else%
      \MPFigTrigo{\NomA}{\NomB}{\NomC}{#3}{0}{-1}{#5}{\useKV[ClesTrigo]{Angle}}
      \fi%
    }{}%
    \fi%
  }{%
    \ifboolKV[ClesTrigo]{Figure}{%
      \begin{multicols}{2}%
        {\em La figure est donn\'ee \`a titre indicatif.}%
        \ifx\bla#5\bla%
        \ifboolKV[ClesTrigo]{Cosinus}{%
          \begin{center}
            \MPFigTrigoAngle{\NomA}{\NomB}{\NomC}{-1}{#3}{#4}{\useKV[ClesTrigo]{Angle}}
          \end{center}
        }{}%
        \ifboolKV[ClesTrigo]{Sinus}{%
          \begin{center}
            \MPFigTrigoAngle{\NomA}{\NomB}{\NomC}{#3}{-1}{#4}{\useKV[ClesTrigo]{Angle}}
          \end{center}
        }{}%
        \ifboolKV[ClesTrigo]{Tangente}{%
          \begin{center}
            \MPFigTrigoAngle{\NomA}{\NomB}{\NomC}{#3}{#4}{-1}{\useKV[ClesTrigo]{Angle}}
          \end{center}
        }{}%
        \else%}{%figure pour calculer une longueur
        \ifboolKV[ClesTrigo]{Cosinus}{%
          \ifx\bla#3\bla%adjacent inconnu
          \begin{center}
            \MPFigTrigo{\NomA}{\NomB}{\NomC}{-1}{0}{#4}{#5}{\useKV[ClesTrigo]{Angle}}
          \end{center}
          \else
          \begin{center}
            \MPFigTrigo{\NomA}{\NomB}{\NomC}{-1}{#3}{0}{#5}{\useKV[ClesTrigo]{Angle}}
          \end{center}
          \fi
        }{}%
        \ifboolKV[ClesTrigo]{Sinus}{%
          \ifx\bla#3\bla%adjacent inconnu
          \begin{center}
            \MPFigTrigo{\NomA}{\NomB}{\NomC}{0}{-1}{#4}{#5}{\useKV[ClesTrigo]{Angle}}
          \end{center}
          \else
          \begin{center}
            \MPFigTrigo{\NomA}{\NomB}{\NomC}{#3}{-1}{0}{#5}{\useKV[ClesTrigo]{Angle}}
          \end{center}
          \fi
        }{}%
        \ifboolKV[ClesTrigo]{Tangente}{%
          \ifx\bla#3\bla%adjacent inconnu
          \begin{center}
            \MPFigTrigo{\NomA}{\NomB}{\NomC}{0}{#4}{-1}{#5}{\useKV[ClesTrigo]{Angle}}
          \end{center}
          \else%
          \begin{center}
            \MPFigTrigo{\NomA}{\NomB}{\NomC}{#3}{0}{-1}{#5}{\useKV[ClesTrigo]{Angle}}
          \end{center}
          \fi%
        }{}%
        \fi%
        \par\columnbreak\par
        \TrigoCalculs[#1]{#2}{#3}{#4}{#5}%
      \end{multicols}
    }{%
      \TrigoCalculs[#1]{#2}{#3}{#4}{#5}%
    }%
  }%
}%

\makeatletter
\NewDocumentCommand\NTrigo{om}{%
  \useKVdefault[ClesTrigo]%
  \setKV[ClesTrigo]{#1}%
  \PfC@Trigo@i#2,%
  \edef\PfCAroValeurHypo{\PfC@ValeurHypo}%
  \edef\PfCAroValeurAdj{\PfC@ValeurAdj}%
  \edef\PfCAroValeurOpp{\PfC@ValeurOpp}%
  \edef\PfCAroValeurAngle{\PfC@ValeurAngle}%
  \ifnum\PfC@NumOpp>0\relax%
    \ifnum\PfC@NumHypo>0\relax%
      \IfStrEq{\PfC@ValeurOpp}{?}{%
        \Trigo[Sinus,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{}{\PfCAroValeurHypo}{\PfCAroValeurAngle}%
      }{%
        \IfStrEq{\PfC@ValeurHypo}{?}{%
          \Trigo[Sinus,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{\PfCAroValeurOpp}{}{\PfCAroValeurAngle}%
        }{%
          \Trigo[Sinus,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{\PfCAroValeurOpp}{\PfCAroValeurHypo}{}%
        }%
      }%
    \else%
      \IfStrEq{\PfC@ValeurOpp}{?}{%
        \Trigo[Tangente,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{}{\PfCAroValeurAdj}{\PfCAroValeurAngle}%
      }{%
        \IfStrEq{\PfC@ValeurAdj}{?}{%
          \Trigo[Tangente,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{\PfCAroValeurOpp}{}{\PfCAroValeurAngle}%
        }{%Je cherche l'angle.%
          \Trigo[Tangente,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{\PfCAroValeurOpp}{\PfCAroValeurAdj}{}%
        }%
      }%
    \fi%
  \else%
    \IfStrEq{\PfC@ValeurAdj}{?}{%
      \Trigo[Cosinus,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{}{\PfCAroValeurHypo}{\PfCAroValeurAngle}%
    }{%
      \IfStrEq{\PfC@ValeurHypo}{?}{%
        \Trigo[Cosinus,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{\PfCAroValeurAdj}{}{\PfCAroValeurAngle}%
      }{%
        \Trigo[Cosinus,#1]{\PfCSommetAngle\SommetAngleDroit\PfCTroisiemeSommet}{\PfCAroValeurAdj}{\PfCAroValeurHypo}{}%
      }%
    }%
  \fi%
}%

\def\PfC@Trigo@i#1=#2,#3=#4,#5=#6,{%
  % On récupère les infos
  \edef\PfC@NumHypo{0}%
  \edef\PfC@NumAdj{0}%
  \edef\PfC@NumOpp{0}%
  \edef\PfC@NumAngle{0}%
  \edef\PfC@ValeurHypo{0}%
  \edef\PfC@ValeurAdj{0}%
  \edef\PfC@ValeurOpp{0}%
  \edef\PfC@ValeurAngle{0}%
  \edef\PfC@Hypo{}%
  \edef\PfC@Adjacent{}%
  \edef\PfC@Oppose{}%
  \edef\PfC@Angle{}%
  \IfEndWith{#1}{*}{%
    \edef\PfC@NumHypo{1}%
    \StrCut{#1}{*}\PfC@Hypo\csAa%
    \edef\PfC@ValeurHypo{#2}%
  }{\IfEndWith{#1}{-}{%
      \edef\PfC@NumAdj{1}%
      \StrCut{#1}{-}\PfC@Adjacent\csAa%
      \edef\PfC@ValeurAdj{#2}%
    }{\IfEndWith{#1}{|}{%
        \edef\PfC@NumOpp{1}%
        \StrCut{#1}{|}\PfC@Oppose\csAa%
        \edef\PfC@ValeurOpp{#2}%
      }{%
        \edef\PfC@NumAngle{1}%
        \StrCut{#1}{=}\PfC@Angle\csAa%
        \edef\PfC@ValeurAngle{#2}%
      }%
    }%
  }%
  \IfEndWith{#3}{*}{%
    \edef\PfC@NumHypo{2}%
    \StrCut{#3}{*}\PfC@Hypo\csAa%
    \edef\PfC@ValeurHypo{#4}%
  }{\IfEndWith{#3}{-}{%
      \edef\PfC@NumAdj{2}%
      \StrCut{#3}{-}\PfC@Adjacent\csAa%
      \edef\PfC@ValeurAdj{#4}%
    }{\IfEndWith{#3}{|}{%
        \edef\PfC@NumOpp{2}%
        \StrCut{#3}{|}\PfC@Oppose\csAa%
        \edef\PfC@ValeurOpp{#4}%
      }{%
        \edef\PfC@NumAngle{2}%
        \StrCut{#3}{=}\PfC@Angle\csAa%
        \edef\PfC@ValeurAngle{#4}%
      }%
    }%
  }%
  \IfEndWith{#5}{*}{%
    \edef\PfC@NumHypo{3}%
    \StrCut{#5}{*}\PfC@Hypo\csAa%
    \edef\PfC@ValeurHypo{#6}%
  }{\IfEndWith{#5}{-}{%
      \edef\PfC@NumAdj{3}%
      \StrCut{#5}{-}\PfC@Adjacent\csAa%
      \edef\PfC@ValeurAdj{#6}%
    }{\IfEndWith{#5}{|}{%
        \edef\PfC@NumOpp{3}%
        \StrCut{#5}{|}\PfC@Oppose\csAa%
        \edef\PfC@ValeurOpp{#6}%
      }{%
        \edef\PfC@NumAngle{3}%
        \StrCut{#5}{=}\PfC@Angle\csAa%
        \edef\PfC@ValeurAngle{#6}%
      }%
    }%
  }%
  % 
  \StrMid{\PfC@Angle}{2}{2}[\PfCSommetAngle]%
  \ifnum\PfC@NumHypo=0\relax%
    \StrCount{\PfC@Adjacent}{\PfCSommetAngle}[\PfC@PresenceSommetAngle]%
    \ifnum\PfC@PresenceSommetAngle=1\relax%
      \StrDel{\PfC@Adjacent}{\PfCSommetAngle}[\PfC@AdjacentCourt]%
      \StrDel{\PfC@Oppose}{\PfC@AdjacentCourt}[\PfC@OpposeCourt]%
      \edef\PfC@Hypo{\PfCSommetAngle\PfC@OpposeCourt}%
    \else%
      \StrDel{\PfC@Oppose}{\PfCSommetAngle}[\PfC@OpposeCourt]%
      \StrDel{\PfC@Adjacent}{\PfC@OpposeCourt}[\PfC@AdjacentCourt]%
      \edef\PfC@Hypo{\PfCSommetAngle\PfC@AdjacentCourt}%
    \fi%
  \fi%
  \StrMid{\PfC@Hypo}{1}{1}[\PfC@Tutu]%
  \StrMid{\PfC@Hypo}{2}{2}[\PfC@Tata]%
  \StrDel{\PfC@Angle}{\PfC@Tutu}[\PfC@SupportTriangle]%
  \StrDel{\PfC@SupportTriangle}{\PfC@Tata}[\SommetAngleDroit]%
  \StrDel{\PfC@Hypo}{\PfCSommetAngle}[\PfCTroisiemeSommet]%
}%
\makeatother