我想对带有可变半径圆的图表上的坐标进行广泛的三角计算。太快了,半径值为 5,我得到了“尺寸太大”的错误。这是我的 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}
答案1
您可以xfp
改用用于计算大数的包:
\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}
您还可以使用fpu
Ti钾Z,但必须激活:
\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);}
\pgfset{fpu=false} % hopefully this fixes the issues of github.com/pgf-tikz/pgf/issues/678
\node at (-\r,-3) {rayon=\rayon pt};
\end{tikzpicture}
\end{document}
答案2
使用let
操作。
\documentclass{article}
\pagestyle{empty}
\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),
%\n{carre}={\x1*\x1},
\n{rayon}={veclen(\x1,\y1)}
in
node at (-\r,-1) {xb=\x1}
node at (-\r,-2) {yb=\y1}
node at (-\r,-3) {rayon=\n{rayon}};
\end{tikzpicture}
\end{document}