快速提问:见下文,我无法veclen
在基本数学计算中使用值。我认为 - 但我不确定 - 这是一个关于我们从哪种单位获得的问题veclen
,我知道不是cm
,但我不知道如何转换为它。
\documentclass[24pt,a4paper,landscape]{scrartcl} %%KOMA class
\setkomafont{sectioning}{\rmfamily\bfseries\boldmath} %%
\usepackage{tikz}
\usepackage{calculator}
\usepackage{pgfplots}
\usetikzlibrary{rulercompass}
\usetikzlibrary{intersections,quotes,angles}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw [color=black!5] (0,0) grid (6,5);
\draw (6,0) coordinate (a) node[right, below] {x}
-- (0,0) coordinate (b) node[left] {(0,0)}
-- (0,5) coordinate (c) node[left] {y};
\path (0,3) coordinate (ad) -- (35:4cm) coordinate (dd);
\path (0,0) coordinate (ad) -- (30:4cm) coordinate (dd);
\draw (ad) -- (dd) coordinate[pos=0.455](c1);
\coordinate (c2) at ($(c1)!2*2.365 cm!(dd)$);
\draw[->, ultra thick, red]
let
\p1=(ad),\p2=(c2), \n1={{veclen(\x2-\x1,\y2-\y1)}}
in
(\x1,\y1) -- (\x2,\y2)
node[label={{$*$}}] {}
\pgfextra{\xdef\var{\n1}} ;
\end{tikzpicture}
\DEGREESSIN{30}{\sol}
\TRUNCATE[2]{\sol}{\sol}
$sin(30)$ = \sol \newline
\sol*\var \newline
\MULTIPLY{\var}{\sol}{\res} <<< IT DOES NOT WORK!!
\begin{equation}
V = \var + \res <<< IT DOES NOT WORK!!
\end{equation}
\end{document}
注意,我想使用该包calculator
,但除此之外也很好。
答案1
您可以使用 PGF 函数从 中scalar
删除单位 ( pt
) \var
,例如如下所示。我个人可能不会使用calculator
,但之后\pgfmathsetmacro\var{scalar(\var)}
,我认为您也可以使用\var
该包。
\documentclass[24pt,a4paper,landscape]{scrartcl} %%KOMA class
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\round[2][2]{\pgfmathprintnumber[precision=#1]{#2}}
\begin{document}
\begin{tikzpicture}
\draw [color=black!5] (0,0) grid (6,5);
\draw (6,0) coordinate (a) node[right, below] {$x$}
-- (0,0) coordinate (b) node[left] {(0,0)}
-- (0,5) coordinate (c) node[left] {$y$};
\coordinate (ad) at (3,0);
\coordinate (ad) at (0,0);
\coordinate (dd) at ((30:4cm);
\draw (ad) -- (dd) coordinate[pos=0.455](c1);
\coordinate (c2) at ($(c1)!2*2.365 cm!(dd)$);
\draw[->, ultra thick, red]
let
\p1=(ad),\p2=(c2), \n1={{veclen(\x2-\x1,\y2-\y1)}}
in
(\x1,\y1) -- (\x2,\y2)
node[label={{$*$}}] {}
\pgfextra{\xdef\var{\n1}} ;
\end{tikzpicture}
% strip away unit
\pgfmathsetmacro\var{scalar(\var)}
\pgfmathsetmacro\sol{sin(30)}
\pgfmathsetmacro\res{\sol*\var}
$\sin(30) = \sol$ and $\sol\cdot\var$
\begin{equation}
V = \round{\var} + \round{\res}
\end{equation}
or with one decimal
\begin{equation}
V = \round[1]{\var} + \round[1]{\res}
\end{equation}
\end{document}