# How to repair Dimension too large when I draw this triangle?

I use this code to draw triangle. When I choose a = b = c = 5, I got the result.

\documentclass[12pt, border = 1mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{intersections,calc,backgrounds}
\begin{document}
\tdplotsetmaincoords{70}{80}
\begin{tikzpicture}[tdplot_main_coords,line join = round, line cap = round]

\pgfmathsetmacro{\a}{5}
\pgfmathsetmacro{\b}{5}
\pgfmathsetmacro{\c}{5}
\pgfmathsetmacro\myr{{sqrt(- pow(\a,2) *pow(\b,2)* pow(\c,2)/(pow(\a,4)  + pow(\b,4)  + pow(\c,4)- 2 *pow(\a,2) *pow(\b,2)  - 2*pow(\c,2) *pow(\b,2)-2*pow(\c,2) *pow(\a,2) ))}}
\coordinate (A) at (0,0,0);
\coordinate (B) at (\c,0,0);
\coordinate (C) at  ({(pow(\b,2) + pow(\c,2) - pow(\a,2))/(2*\c)},{sqrt((\a+\b-\c) *(\a-\b+\c) *(-\a+\b+\c)* (\a+\b+\c))/(2*\c)},0);
\coordinate (T) at  (\c/2, {\c* (\a*\a + \b*\b - \c*\c)/(2*sqrt((\a+\b-\c) *(\a-\b+\c)* (-\a+\b+\c)* (\a+\b+\c)))},0);

\foreach \point/\position in {A/left,B/below,C/above,T/below}
{
\fill (\point) circle (1.8pt);
\node[\position=3pt] at (\point) {$\point$};
}
\begin{scope}[canvas is xy plane at z=0]
\draw[thick] (T) circle (\myr);
\end{scope}
\end{tikzpicture}
\end{document}


If I use a = b = c = 6 or larger, I cannot obtain the result. How can I get the result?

• Your code draws a circle seen in perspective, why would you want it to draw a triangle? – AndréC Aug 11 '19 at 15:38
• @AndréC This is only one part of a completed code. – minhthien_2016 Aug 11 '19 at 15:40
• I don't understand your problem. In addition, you do not use in this code pgfplots. Please make a minimum example that contains only the necessary packages. – AndréC Aug 11 '19 at 15:42
• Do not use pow(\a,2) etc instead of \a*\a. – John Kormylo Aug 11 '19 at 15:54
• \a*\a*\a*\a BTW, one should expand the polynomial $ax^2+bx+c$ as (a*x+b)*x+c. It is both faster and more accurate (roundoff). – John Kormylo Aug 11 '19 at 16:04

There are some standard ways to deal with this. One of them is to use the fpu library. (fpu is mentioned in the comment by John Kormylo, but I do not have the problems mentioned there.) However, as you noted yourself in some constructions like arc just switching on fpu can lead to problems. In order to make things more convenient for you, I added a macro \PgfmathsetmacroFPU, which switches the library on locally, parses the expression, and "smuggles" the result out of the group. Therefore, the definition of the macro will be local, just like in the case of the ordinary \pgfmathsetmacro. Note that \pgfmathsmuggle has been added to the more recent versions of pgf, so if you have an outdated TeX installation it may not work. Sorry overleaf users! Further information on smuggling as well as alternative commands can be found in the answers to this question.

\documentclass[12pt, border = 1mm]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{intersections,calc,backgrounds,fpu}
\newcommand{\PgfmathsetmacroFPU}[2]{\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathsetmacro{#1}{#2}%
\pgfmathsmuggle#1\endgroup}
\begin{document}
\tdplotsetmaincoords{70}{80}
\begin{tikzpicture}[tdplot_main_coords,line join = round, line cap = round]
\pgfmathsetmacro{\a}{6}
\pgfmathsetmacro{\b}{6}
\pgfmathsetmacro{\c}{6}
\PgfmathsetmacroFPU{\myr}{{sqrt(-
pow(\a,2) *pow(\b,2)* pow(\c,2)/ (pow(\a,4)  + pow(\b,4)  + pow(\c,4)- 2
*pow(\a,2) *pow(\b,2)  - 2*pow(\c,2) *pow(\b,2)-2*pow(\c,2) *pow(\a,2) ))}}
\PgfmathsetmacroFPU{\Angleone}{-90}
\PgfmathsetmacroFPU{\Angletwo}{60}
\coordinate (E) at ({\c/2 + \myr*cos(\Angleone)},{\c* (\a*\a + \b*\b -
\c*\c)/(2*sqrt((\a+\b-\c) *(\a-\b+\c)* (-\a+\b+\c)* (\a+\b+\c))) +
\myr*sin(\Angleone)},0 );  \coordinate (F) at ({\c/2 +
\myr*cos(\Angletwo)},{\c* (\a*\a + \b*\b - \c*\c)/(2*sqrt((\a+\b-\c)
*(\a-\b+\c)* (-\a+\b+\c)* (\a+\b+\c))) + \myr*sin(\Angletwo)},0 );
\coordinate (A) at (0,0,0);
\coordinate (B) at (\c,0,0);
\coordinate (C) at  ({(pow(\b,2) + pow(\c,2) - pow(\a,2))/(2*\c)},{sqrt((\a+\b-\c) *(\a-\b+\c) *(-\a+\b+\c)* (\a+\b+\c))/(2*\c)},0);
\coordinate (T) at  (\c/2, {\c* (\a*\a + \b*\b - \c*\c)/(2*sqrt((\a+\b-\c) *(\a-\b+\c)* (-\a+\b+\c)* (\a+\b+\c)))},0);
\foreach \point/\position in {A/left,B/below,C/above,T/below}
{
\fill (\point) circle (1.8pt);
\node[\position=3pt] at (\point) {$\point$};
}
\begin{scope}[canvas is xy plane at z=0]
\draw[thick] (T) circle (\myr);
\end{scope}
\pgfmathsetmacro{\Angleone}{-90}
\pgfmathsetmacro{\Angletwo}{60}

• I add \pgfmathsetmacro{\Angleone}{-90} \pgfmathsetmacro{\Angletwo}{60} and \coordinate (E) at ({\c/2 + \myr*cos(\Angleone)},{\c* (\a*\a + \b*\b - \c*\c)/(2*sqrt((\a+\b-\c) *(\a-\b+\c)* (-\a+\b+\c)* (\a+\b+\c))) + \myr*sin(\Angleone)},0 ); \coordinate (F) at ({\c/2 + \myr*cos(\Angletwo)},{\c* (\a*\a + \b*\b - \c*\c)/(2*sqrt((\a+\b-\c) *(\a-\b+\c)* (-\a+\b+\c)* (\a+\b+\c))) + \myr*sin(\Angletwo)},0 ); \draw [thick] (E) arc (\Angleone:\Angletwo:\myr); I cannot obtain the result. Please help me. – minhthien_2016 Aug 12 '19 at 1:35
• @minhthien_2016 Yes, good point: some constructions like arc have problems with fpu. I added general way to fix this: a macro \PgfmathsetmacroFPU that switches on the library only locally in the parsing. – user121799 Aug 12 '19 at 1:56