我正在练习使用该tkz-euclide
软件包。我尝试运行此程序:
\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}
我收到以下错误消息:
! 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.
我想要一个代码,它总是在 A 和 B 之间绘制相同的弧,即短弧或长弧。为什么这不起作用?
答案1
如果你\show\hoek
在测试前添加,tex 将停止并向你显示
> \hoek=macro:
->-37.234850000000000000.
\ifnum
(用于\ifthenelse
数字测试)是为 tex 数字(整数)设计的。
所以它在这里抱怨.
TeX 常用的技巧是使用维度来保存非整数值
\ifthenelse{\lengthtest{\hoek pt<180pt}}{\tkzDrawArc(O,A)(B);}{\tkzDrawArc(O,B)(A);};
答案2
这有效:
\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}