tikz computation dimension too large square of x

by the world is not flat   Last Updated June 12, 2019 08:23 AM

I want to make extensive trigonometric computation involving coordinates on a diagram with a circle of a variable radius. Way too quickly, with radius value of 5, I got "dimension too large" errors. Here is my MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{math, calc, fpu}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};

\draw  ($(C) + (0:{\r})$) arc (0:\angleTheta:\r);

\pgfgetlastxy{\xb}{\yb}
\node at (-\r,-1) {xb=\xb};
\node at (-\r,-2) {yb=\yb};

\tikzmath{\carre= \xb*\xb;}  

\pgfmathsetmacro\rayon{sqrt(\xb*\xb +\yb*\yb)}

\tikzmath{\rayon= sqrt(\xb*\xb +\yb*\yb);}  

\node at (-\r,-3) {rayon=\rayon};


\end{tikzpicture}
\end{document}
Tags : tikz-pgf


Answers 2


You can use the xfp package for the calculation of big numbers instead:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{xfp}
\usetikzlibrary{math, calc, fpu}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};

\draw  ($(C) + (0:{\r})$) arc (0:\angleTheta:\r);

\pgfgetlastxy{\xb}{\yb}
\node at (-\r,-1) {xb=\xb};
\node at (-\r,-2) {yb=\yb};

\edef\carre{\fpeval{\xb*\xb}pt}

\edef\rayon{\fpeval{sqrt(\xb*\xb + \yb*\yb)}pt}

\node at (-\r,-3) {rayon=\rayon};


\end{tikzpicture}
\end{document}

You can also use the fpu of TikZ, but it has to be activated:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{math, calc, fpu}
\title{MWE}

\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};

\draw  ($(C) + (0:{\r})$) arc (0:\angleTheta:\r);

\pgfgetlastxy{\xb}{\yb}
\node at (-\r,-1) {xb=\xb};
\node at (-\r,-2) {yb=\yb};

\pgfset{fpu=true,fpu/output format=fixed}
\tikzmath{\carre= \xb*\xb;}  

\pgfmathsetmacro\rayon{sqrt(\xb*\xb +\yb*\yb)}

\tikzmath{\rayon= sqrt(\xb*\xb +\yb*\yb);}  

\node at (-\r,-3) {rayon=\rayon pt};


\end{tikzpicture}
\end{document}
Skillmon
Skillmon
June 12, 2019 08:17 AM

Use the let operation.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\def\angleTheta{180}
\def\r{5}

\node (C) at (0,0) {C};
\draw ($(C) + (0:{\r})$) arc (0:\angleTheta:\r) coordinate (ref);
\path let \p1=(ref),
          \n2={veclen(\x1,\y1)}
    in 
        node at (-\r,-1) {xb=\x1}
        node at (-\r,-2) {yb=\y1}
        node at (-\r,-3) {rayon=\n2};

\end{tikzpicture}
\end{document}

enter image description here

Henri Menke
Henri Menke
June 12, 2019 08:21 AM

Related Questions




Drawing similar picture with tikz

Updated November 20, 2018 12:23 PM

Complicated curves interwined in the link figures

Updated December 17, 2018 22:23 PM

Complicated curves intertwined in the link figures (II)

Updated December 18, 2018 02:23 AM