
Quiero crear macros que devuelvan valores reales. Por ejemplo, me gustaría tener algo como el siguiente 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}
En última instancia, tendré varios de estos tipos de macros para evaluar geometrías en tikz
diagramas. Gracias
Respuesta1
Una posible implementación con un declarado function
usando la math
biblioteca de 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}