Estou praticando com o tkz-euclide
pacote. Eu tento executar isso:
\documentclass{article}
\usepackage{tkz-euclide,ifthen}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=4]
\tkzInit[xmin=-1,xmax=1, ymin=-1,ymax=1]
\draw (0,0) circle [radius=1];
\tkzDefPoint(.3,.5){A}\tkzDefPoint(.5,.2){B}\tkzDefPoint(0,0){O}
\tkzDrawPoints(A,B)
\tkzFindAngle(A,O,B)\tkzGetAngle{hoek}
\ifthenelse{\hoek<180}{\tkzDrawArc(O,A)(B);}{\tkzDrawArc(O,B)(A);};
\end{tikzpicture}
\end{document}
Eu recebi a seguinte mensagem de erro:
! Missing = inserted for \ifnum.
<to be read again>
.
l.12 \ifthenelse{\hoek<180}
{\tkzDrawArc(O,A)(B);}{\tkzDrawArc(O,B)...
? H
I was expecting to see `<', `=', or `>'. Didn't.
O que eu quero é um código que desenhe sempre o mesmo arco entre A e B, ou seja, o curto ou o longo. Por que isso não está funcionando?
Responder1
Se você adicionar \show\hoek
um pouco antes do teste tex irá parar e mostrar
> \hoek=macro:
->-37.234850000000000000.
\ifnum
(que é \ifthenelse
usado para testes numéricos) foi projetado para números tex, que são inteiros.
Então aqui ele reclama no.
O truque usual do TeX é usar dimensões para armazenar valores não inteiros
\ifthenelse{\lengthtest{\hoek pt<180pt}}{\tkzDrawArc(O,A)(B);}{\tkzDrawArc(O,B)(A);};
Responder2
Isso funciona:
\documentclass{article}
\usepackage{tkz-euclide,ifthen}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=4]
\tkzInit[xmin=-1,xmax=1, ymin=-1,ymax=1]
\draw (0,0) circle [radius=1];
\tkzDefPoint(.3,.5){A}\tkzDefPoint(.5,.2){B}\tkzDefPoint(0,0){O}
\tkzDrawPoints(A,B)
\tkzFindAngle(A,O,B)\tkzGetAngle{hoek}
\draw(0,0) node{\hoek};
\pgfmathparse{(\hoek<180) ? 1 : 0 }
\ifthenelse{\equal{\pgfmathresult}{1}}{\tkzDrawArc(O,A)(B);}{\tkzDrawArc(O,B)(A);};
\end{tikzpicture}
\end{document}