TiKZ 中包计算器的引用变量

TiKZ 中包计算器的引用变量

我有这个代码:

\documentclass[letterpaper,12pt]{report}
\usepackage[letterpaper, landscape, margin=0in]{geometry}
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfmath}
\pgfplotsset{width=15cm,compat=1.9}
\usepackage{pstricks}
\usepackage{amsmath}
\usepackage[none]{hyphenat}
\usepackage{bigstrut}
\allowdisplaybreaks  
\usepackage{calculator} 
\usetikzlibrary{calc} 
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usetikzlibrary{babel}


\begin{document}

\COPY{0.5}{\d_h_relation} % d/h relation

\COPY{1.4}{\h} % Plate thickness
\MULTIPLY{\d_h_relation}{\h}{\equivalent_circle_diameter}
\MULTIPLY{\equivalent_circle_diameter}{\equivalent_circle_diameter}{\A_part_1}
\MULTIPLY{\A_part_1}{\numberPI}{\A_part_2}
\DIVIDE{\A_part_2}{4}{\Area}% Area of the hole.
\SQUAREROOT{\Area}{\temp1r_h11}
\DIVIDE{\temp1r_h11}{2}{\temp2r_h11}

\COPY{6.304640974884}{\r1} % Central radius of the first hole.
\SUBTRACT{\r1}{\temp2r_h11}{\rh11} % Internal radius of hole 1.
$\rh11$
\ADD{\r1}{\temp2r_h11}{\rh12} % External radius of hole 1
$\rh12$
\DIVIDE{1}{\r1}{\theta_hs1_part1}
\MULTIPLY{\temp2r_h11}{\theta_hs1_part1}{\theta_hs1}
\COPY{0.187226105362745}{\varph1} % angle of the first hole.
\SUBTRACT{\varph1}{\theta_hs1}{\thetarad11_rad} % angle in radians of the first border of hole 1
\DIVIDE{\thetarad11_rad}{\numberPI}{\thetadeg11_part1}
\MULTIPLY{\thetadeg11_part1}{180}{\thetadeg11}
$\thetadeg11$
\ADD{\varph1}{\theta_hs1}{\thetarad12_rad} % angle in radians of the second border of hole 1
\DIVIDE{\thetarad12_rad}{\numberPI}{\thetadeg12_part1}
\MULTIPLY{\thetadeg12_part1}{180}{\thetadeg12}
$\thetadeg12$

\begin{tikzpicture}

\draw (0,0) circle [radius=10.75cm];
\draw (0,0) circle [radius=4.2cm];

\begin{scope}[even odd rule]
\draw[fill=gray!20,thick] (0,0) circle [radius=8cm] circle [radius=6cm];
\end{scope}

\draw[fill=white] (7.908394:5.994461) node (a1) {} arc[radius=5.994461, start angle=7.908394, end angle= 13.546137] --  (13.546137:6.61482) node (a2) {} arc[radius=6.61482, start angle=13.546137, end angle= 7.908394] -- cycle;
\path (a1) -- (a2) node[inner sep=2pt,circle,fill,pos=0.5] (x1) {};

\draw (0,0) -- (x1) node[pos=0.5,fill=white,circle] {$r_1$};

\draw (0,0) -- ++(3.5,0);

\draw[->] (0:2.5cm) arc (0:10.72:2.5cm) node[pos=0.5,label={0:$\varphi_1$}] {};

\end{tikzpicture}

\end{document}

我想使用变量:“ rh11,,rh12thetadeg11thetadeg12,在 TiKZpicture 之前用计算器包计算,用作 TiKZpicture 中孔的坐标。我曾尝试过这个:

\documentclass[letterpaper,12pt]{report}
\usepackage[letterpaper, landscape, margin=0in]{geometry}        
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfmath}
\pgfplotsset{width=15cm,compat=1.9}
\usepackage{pstricks}
\usepackage{amsmath}
\usepackage[none]{hyphenat}
\usepackage{bigstrut}
\allowdisplaybreaks  
\usepackage{calculator} 
\usetikzlibrary{calc} 
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usetikzlibrary{babel}


\begin{document}    
\COPY{0.5}{\d_h_relation} % d/h relation
\COPY{1.4}{\h} % Plate thickness
\MULTIPLY{\d_h_relation}{\h}{\equivalent_circle_diameter}
\MULTIPLY{\equivalent_circle_diameter}{\equivalent_circle_diameter}{\A_part_1}
\MULTIPLY{\A_part_1}{\numberPI}{\A_part_2}
\DIVIDE{\A_part_2}{4}{\Area}% Area of the hole.
\SQUAREROOT{\Area}{\temp1r_h11}
\DIVIDE{\temp1r_h11}{2}{\temp2r_h11}

\COPY{6.304640974884}{\r1} % Central radius of the first hole.
\SUBTRACT{\r1}{\temp2r_h11}{\rh11} % Internal radius of hole 1.
$\rh11$
\ADD{\r1}{\temp2r_h11}{\rh12} % External radius of hole 1
$\rh12$
\DIVIDE{1}{\r1}{\theta_hs1_part1}
\MULTIPLY{\temp2r_h11}{\theta_hs1_part1}{\theta_hs1}
\COPY{0.187226105362745}{\varph1} % angle of the first hole.
\SUBTRACT{\varph1}{\theta_hs1}{\thetarad11_rad} % angle in radians of the first border of hole 1
\DIVIDE{\thetarad11_rad}{\numberPI}{\thetadeg11_part1}
\MULTIPLY{\thetadeg11_part1}{180}{\thetadeg11}
$\thetadeg11$
\ADD{\varph1}{\theta_hs1}{\thetarad12_rad} % angle in radians of the second border of hole 1
\DIVIDE{\thetarad12_rad}{\numberPI}{\thetadeg12_part1}
\MULTIPLY{\thetadeg12_part1}{180}{\thetadeg12}
$\thetadeg12$

\begin{tikzpicture}

\draw (0,0) circle [radius=10.75cm];
\draw (0,0) circle [radius=4.2cm];

\begin{scope}[even odd rule]
\draw[fill=gray!20,thick] (0,0) circle [radius=8cm] circle [radius=6cm];
\end{scope}

\draw[fill=white] (\thetadeg11:\rh11) node (a1) {} arc[radius=\rh11, start angle=\thetadeg11, end angle= \thetadeg12] --  (\thetadeg12:\rh12) node (a2) {} arc[radius=\rh12, start angle=\thetadeg12, end angle= \thetadeg11] -- cycle;
    \path (a1) -- (a2) node[inner sep=2pt,circle,fill,pos=0.5] (x1) {};

\draw (0,0) -- (x1) node[pos=0.5,fill=white,circle] {$r_1$};

\draw (0,0) -- ++(3.5,0);

\draw[->] (0:2.5cm) arc (0:10.72:2.5cm) node[pos=0.5,label={0:$\varphi_1$}] {};

\end{tikzpicture}

\end{document}

但它无法编译,而是显示错误警告。我该如何引用它们?

答案1

我认为 Torbjørn T'. 的建议是最简洁的解决方法。不过,作为某种学术练习(或者更多,取决于你如何看待事物),下面我将展示一种相当简单的方法来实现这一点。不过,我要强调的是

该代码引发了几个与 pstricks 相关的警告,我没有尝试让它们消失。

我已经使用 pstricks 十多年了,最近才换成 TiZ. 我一直很喜欢使用 pstricks,也非常感谢那些编写和维护这个出色软件包的人。然而,不幸的是,我再也找不到足够的动力去弄清楚这些有时可能有些神秘的警告是什么意思了。

\documentclass[letterpaper,12pt]{report}
\usepackage[letterpaper, landscape, margin=0in]{geometry}        
\usepackage{graphicx}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfmath}
\pgfplotsset{width=15cm,compat=1.9}
\usepackage{pstricks}
\usepackage{amsmath}
\usepackage[none]{hyphenat}
\usepackage{bigstrut}
\allowdisplaybreaks  
\usepackage{calculator} 
\usetikzlibrary{calc} 
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usetikzlibrary{babel}


\begin{document}    
\COPY{0.5}{\d_h_relation} % d/h relation
\COPY{1.4}{\h} % Plate thickness
\MULTIPLY{\d_h_relation}{\h}{\equivalent_circle_diameter}
\MULTIPLY{\equivalent_circle_diameter}{\equivalent_circle_diameter}{\A_part_1}
\MULTIPLY{\A_part_1}{\numberPI}{\A_part_2}
\DIVIDE{\A_part_2}{4}{\Area}% Area of the hole.
\SQUAREROOT{\Area}{\temp1r_h11}
\DIVIDE{\temp1r_h11}{2}{\temp2r_h11}

\COPY{6.304640974884}{\r1} % Central radius of the first hole.
\SUBTRACT{\r1}{\temp2r_h11}{\rh11} % Internal radius of hole 1.
$\rh11$
\xdef\tmpa{\rh11}
%\typeout{\tmpa}
\ADD{\r1}{\temp2r_h11}{\rh12} % External radius of hole 1
$\rh12$
\xdef\tmpb{\rh12}
\typeout{\tmpb}
\DIVIDE{1}{\r1}{\theta_hs1_part1}
\MULTIPLY{\temp2r_h11}{\theta_hs1_part1}{\theta_hs1}
\COPY{0.187226105362745}{\varph1} % angle of the first hole.
\SUBTRACT{\varph1}{\theta_hs1}{\thetarad11_rad} % angle in radians of the first border of hole 1
\DIVIDE{\thetarad11_rad}{\numberPI}{\thetadeg11_part1}
\MULTIPLY{\thetadeg11_part1}{180}{\thetadeg11}
$\thetadeg11$
\xdef\tmpc{\thetadeg11}
%\typeout{\tmpc}
\ADD{\varph1}{\theta_hs1}{\thetarad12_rad} % angle in radians of the second border of hole 1
\DIVIDE{\thetarad12_rad}{\numberPI}{\thetadeg12_part1}
\MULTIPLY{\thetadeg12_part1}{180}{\thetadeg12}
$\thetadeg12$
\xdef\tmpd{\thetadeg12}
%\typeout{\tmpd}


\begin{tikzpicture}

\draw (0,0) circle [radius=10.75cm];
\draw (0,0) circle [radius=4.2cm];

\begin{scope}[even odd rule]
\draw[fill=gray!20,thick] (0,0) circle [radius=8cm] circle [radius=6cm];
\end{scope}

 \draw[fill=white] (\tmpc:\tmpa) coordinate (a1) 
 arc[radius=\tmpa, start angle=\tmpc, end angle= \tmpd] --  
 (\tmpd:\tmpb) coordinate (a2)  arc[radius=\tmpb, start angle=\tmpd, end angle=
 \tmpc] -- cycle;
  \path (a1) -- (a2) node[inner sep=2pt,circle,fill,pos=0.5] (x1) {};

\draw (0,0) -- (x1) node[pos=0.5,fill=white,circle] {$r_1$};

\draw (0,0) -- ++(3.5,0);

\draw[->] (0:2.5cm) arc (0:10.72:2.5cm) node[pos=0.5,label={0:$\varphi_1$}] {};

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

我认为@marmot 的回答已经解决了原始问题,这个答案解释了如何使用另一种方式来计算数量。

\documentclass[border=3pt]{standalone}
%\usepackage[letterpaper, landscape, margin=0in]{geometry}
%\usepackage{graphicx}
%\usepackage[spanish]{babel}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfmath}
\pgfplotsset{width=15cm,compat=1.9}
%\usepackage{pstricks}
%\usepackage{amsmath}
%\usepackage[none]{hyphenat}
%\usepackage{bigstrut}
% \allowdisplaybreaks  
%\usepackage{calculator} 
\usetikzlibrary{calc} 
\usetikzlibrary{arrows}
\usetikzlibrary{trees}
\usetikzlibrary{babel}

\usepackage{xintexpr}
\newcommand\xuse[1]{\xinttheiexpr[6]#1\relax}% rounds and format to fixed point
                                             % with 6 fractional decimal digits 
% 3.141592653589793238462643383279502884197169399375105820974944...
\xintdeffloatvar Pi := 3.141592653589793;% rounded to 16 digits of precision


\begin{document}

\xintdeffloatvar doverh := 0.5; % d/h relation
\xintdeffloatvar h := 1.4; %  Plate thickness
\xintdeffloatvar equivalent_circle_diameter := doverh * h;
\xintdeffloatvar Area := Pi * equivalent_circle_diameter^2/4;
\xintdeffloatvar temp2r_h11 := sqrt(Area)/2;

\xintdeffloatvar r1 := 6.304640974884; % Central radius of the first hole.
\xintdeffloatvar rh11 := r1 - temp2r_h11; % Internal radius of hole 1.
\xintdeffloatvar rh12 := r1 + temp2r_h11;%  External radius of hole 1

\xintdeffloatvar theta_hs1 := temp2r_h11 /r1;
\xintdeffloatvar varph1 :=  0.187226105362745; % angle of the first hole.

\xintdeffloatvar thetarad11_rad := varph1 - theta_hs1; % angle in radians of the first border of hole 1
\xintdeffloatvar thetadeg11 := 180 * thetarad11_rad/Pi;

\xintdeffloatvar thetarad12_rad := varph1 + theta_hs1; % angle in radians of second border of hole 1
\xintdeffloatvar thetadeg12 := 180 * thetarad12_rad/Pi;

\begin{tikzpicture}

\draw (0,0) circle [radius=10.75cm];
\draw (0,0) circle [radius=4.2cm];

\begin{scope}[even odd rule]
\draw[fill=gray!20,thick] (0,0) circle [radius=8cm] circle [radius=6cm];
\end{scope}

\draw[fill=white] 
 (\xuse{thetadeg11}:\xuse{rh11}) 
  node (a1) {}
   arc[radius=\xuse{rh11},
       start angle=\xuse{thetadeg11},
       end angle=\xuse{thetadeg12}] 
 --  
 (\xuse{thetadeg12}:\xuse{rh12})
  node (a2) {}
   arc[radius=\xuse{rh12},
       start angle=\xuse{thetadeg12},
       end angle= \xuse{thetadeg11}]
 -- cycle;

\path (a1) -- (a2) node[inner sep=2pt,circle,fill,pos=0.5] (x1) {};

\draw (0,0) -- (x1) node[pos=0.5,fill=white,circle] {$r_1$};

\draw (0,0) -- ++(3.5,0);

\draw[->] (0:2.5cm) arc (0:10.72:2.5cm) node[pos=0.5,label={0:$\varphi_1$}] {};

\end{tikzpicture}

\end{document}

备注:每次使用宏时,都会将数字四舍五入到小数点后 6 位(从 16 位浮点精度开始)\xuse。如果要多次使用变量,也可以提前进行四舍五入,并将结果存储在 TikZ 语法中使用的宏中(如果它们可以扩展,则显然允许在这些位置使用此类宏 - 根据coordinates我的经验,我知道有时允许的扩展步骤不超过 100 个,我不知道此限制是否适用于此处)。

在此处输入图片描述

相关内容