
Quero construir macros que retornem valores reais. Por exemplo, eu gostaria de ter algo como o seguinte pseudocódigo:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{calculator}
\newcommand{\scale}[3]{%
\ifnumgreater{#1}{10}
{\return{#1}}
{\ifnumgreater{#2}{10}
{\return{#2}}
{\return{#3}}
}
}
\begin{document}
\begin{tikzpicture}[scale=1]
%* Polar Ray - Centerline - Origin at (0,0), 45degs from horizontal to a length of \scale
\draw [red,dashed] (0,0) -- ++(45:\scale{9}{12}{10});
\end{tikzpicture}
\end{document}
Por fim, terei vários desses tipos de macros para avaliar geometrias em tikz
diagramas. Obrigado
Responder1
Uma implementação possível com um declarado function
usando a math
biblioteca do TikZ:
\documentclass[tikz]{standalone}
\usetikzlibrary{math}
\tikzmath{function myscalefun(\a,\b,\c) {
if \a>10 then { return \a; } else {
if \b>10 then { return \b; } else {
return \c; }; };
};}
\begin{document}
\begin{tikzpicture}[scale=1]
\clip (0,0) rectangle (15.5,9);
\foreach \r in {8,...,15} {
\draw[gray!20] (0,0) circle (\r);
\node[above] at (\r,0) {\r};
}
\draw (0,0) -- ++(45:{myscalefun(9,12,10)});
\draw (0,0) -- ++(30:{myscalefun(11,12,10)});
\draw (0,0) -- ++(15:{myscalefun(9,8,9)});
\end{tikzpicture}
\end{document}