![如何使用符号名称表示坐标和缩放?](https://linux22.com/image/422062/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E7%AC%A6%E5%8F%B7%E5%90%8D%E7%A7%B0%E8%A1%A8%E7%A4%BA%E5%9D%90%E6%A0%87%E5%92%8C%E7%BC%A9%E6%94%BE%EF%BC%9F.png)
我希望在以下不起作用的 TikZ 代码中清楚表明完成任务的正确语法是什么?
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (basePt) at (4, 2);
% HOW accomplish this multiplication with hard-coded factors?
\coordinate (newPt) at (0.65,0.65)*basePt; % or perhaps 0.65*basePt
% And how to do it if, instead, a "symbolic name", e.g., myscale, were used?
% and how define that symbolic name?
% Missing here: how to define myscale to be, e.g., 0.65?
\coordinate (newerPt) at myscale*basePt;
\draw (0,0) -- (basePt) -- (newerPt);
\end{tikzpicture}
\end{document}
换句话说,如何使用坐标进行计算——既使用具体数字,又使用这些数字的符号名称——然后如何定义这些符号名称的值?
我的目的是能够轻松地修改代码开头的几个命名变量的值,tikzpicture
而不必在整个代码中更改坐标值。
答案1
该calc
库允许您计算坐标,请参阅第 13.5 节坐标计算在手册中。例如,您可以使用declare function
来定义myscale
。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
declare function={myscale=0.65;}
]
\coordinate (basePt) at (4, 2);
\coordinate (newPt) at ($0.65*(basePt)$); %
\coordinate (newerPt) at ($myscale*(basePt)$);
\draw (0,0) -- (basePt) node{a} -- (newerPt) node{b};
\end{tikzpicture}
\end{document}