3

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

\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?

1 Answers1

2

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}  
    \draw[thick] (E) arc[start angle=\Angleone,end angle=\Angletwo,radius=\myr]; 
\end{tikzpicture}
\end{document}

enter image description here

  • 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 01:35
  • 2
    @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. –  Aug 12 '19 at 01:56
  • Thank you very much. – minhthien_2016 Aug 12 '19 at 02:04
  • How can I show coordinates of the point T and radius myr below the figure? – minhthien_2016 Aug 12 '19 at 03:04
  • 1
    @minhthien_2016 I do not know, which is why I asked this question: https://tex.stackexchange.com/q/503603/121799. AFAIK there is no built-in way that allows us to store the 3d coordinates in points. –  Aug 12 '19 at 03:06
  • 2
    I have removed some comments here which seem to constitute a separate question rather than a clarification of this answer. The answer here is appropriate to the question posed, and the generic technical issue raised in comments would be better handled separately. – Joseph Wright Aug 13 '19 at 07:36