I was typesetting a triangle with tkz-euclide, trying to automate the process as much as possible, and noticed that there is some calculation mistakes when using \tkzCalcLength
and \tkzGetLength
AND different values for \tkzInit[xmin=_,xmax=_,ymin=_,ymax=_]
it's easier if I just show the issue:
\documentclass[letterpaper,12pt]{book}
\usepackage{tkz-euclide}
\usetikzlibrary{shapes,backgrounds,calc,arrows.meta,fit,positioning,intersections}
\usetkzobj{all}
\tikzset{ptgrs/.style={thick,transform shape,scale=\tikzscale}}
\usepackage{environ}
\makeatletter
\newsavebox{\measure@tikzpicture}
\NewEnviron{scaletikzpicturetowidth}[1]{%
\def\tikz@width{#1}%
\def\tikzscale{1}\begin{lrbox}{\measure@tikzpicture}%
\BODY
\end{lrbox}%
\pgfmathparse{#1/\wd\measure@tikzpicture}%
\edef\tikzscale{\pgfmathresult}%
\BODY
}
\makeatother
\begin{document}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=35,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=40,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=45,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=50,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\begin{center}\begin{scaletikzpicturetowidth}{0.66\textwidth}\begin{tikzpicture}[ptgrs]
\tkzInit[xmin=-0.5,xmax=55,ymin=-2,ymax=15] \tkzClip %\tkzGrid
\def\AX{12}
\def\angXAC{25.5}
\def\angBXC{38.25}
\tkzDefPoint(0,0){A}
\tkzDefPoint(\AX,0){X}
\path[name path=b] (A) -- (\angXAC:40cm);
\path[name path=l] (A) -- (X) --+ (\angBXC:30cm);
\draw [name intersections={of=b and l, by={F,C}}];
\coordinate (B) at ($(A)!(C)!(X)$);
\tkzDrawPolygon(A,B,C)
\draw (C) -- (X);
%\tkzMarkAngle[size=2.7,](X,A,C)
% \tkzLabelAngle[pos=2,transform shape=false](X,A,C){$\alpha$}
%\tkzMarkAngle[size=6,](A,C,X)
% \tkzLabelAngle[pos=5,transform shape=false](A,C,X){$\beta$}
%\tkzMarkAngle[size=1.4,](C,X,A)
% \tkzLabelAngle[pos=0.8,transform shape=false](C,X,A){$\delta$}
%\tkzMarkAngle[size=2.7,](B,X,C)
% \tkzLabelAngle[pos=2,transform shape=false](B,X,C){$\gamma$}
%\tkzMarkRightAngle[size=1](C,B,X)
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](X)--(A)
node [midway,yshift=-12pt] {$\AX$};
\tkzCalcLength[cm](B,C)\tkzGetLength{BC} \FPround\BC\BC{3}
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](C)--(B)
node [midway,xshift=32pt] {$\BC$};
\draw[transform shape=false,thin,decorate,decoration={brace,amplitude=7pt}](B)--(X)
node [midway,yshift=-12pt] {$A$};
\draw[blue](current bounding box.south west)rectangle(current bounding box.north east);
\end{tikzpicture}\end{scaletikzpicturetowidth}\end{center}
\end{document}
The output is as follows:
The imprecision gets worse, or different, if I use for example \FPround\BC\BC{4}
or if I use different margins with geometry.
To be clear I don't think it's a terrible bug or even if it's a bug since as you can see there's a lot of stuff going on in the code but I would like to know what causes this and if there's a way to get more accurate lengths.
tkzCalcLength
uses the packagefp
and the precision is correct. Whentikz
usesTeX
to calculate the results can be inaccurate.