我使用此代码绘制三角形。当我选择时a = b = c = 5
,我得到了结果。
\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}
如果我使用a = b = c = 6
或更大的值,则无法获得结果。我该如何获得结果?
答案1
有一些标准方法来处理这个问题。其中之一是使用库fpu
。(fpu
在John Kormylo 的评论,但我没有那里提到的问题。)但是,正如你自己注意到的,在某些构造中,例如arc
仅仅打开fpu
可能会导致问题。为了让你更方便,我添加了一个宏\PgfmathsetmacroFPU
,它在本地打开库,解析表达式,并将结果“走私”出组。因此,宏的定义将是本地的,就像普通的情况一样\pgfmathsetmacro
。请注意,\pgfmathsmuggle
已添加到较新版本的中pgf
,因此如果您的 TeX 安装过时,它可能无法工作。对不起 overleaf 用户!有关走私的更多信息以及替代命令可以在以下答案中找到这个问题。
\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}