我只是想计算两点之间的欧几里得距离并将其保存在一个变量中。
这就是我所做的
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\def\klen{10em}
\begin{document}
\begin{tikzpicture}
\node[
draw,
regular polygon,
regular polygon sides=5,
minimum size=\klen,
] (P1) {};
\newlength{\kside}
\setlength{\kside}{let \p1=(P1.corner 1), \p2=(P1.corner 2), \kside={veclen(\x1-\x2,\y1-\y2)}}
\end{tikzpicture}
\end{document}
我这里出了什么错误?在花括号内计算某些东西不应该吗?
给定一个用绘制的形状,shapes.geometric
可以检索它的侧面吗?
答案1
法语文档 MANUEL DE PRISE EN MAIN POUR TIKZ Yves SOULET Mise à jour article Cahiers GUT no 50—septembre 2012 p.14 我建议这样做
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\def\klen{10em}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%cf doc MANUEL DE PRISE EN MAIN
% POUR TIKZ
% Yves SOULET
% Mise à jour article Cahiers GUT no 50—septembre 2012
% p.14
\begin{tikzpicture}
\node[
draw,
regular polygon,
regular polygon sides=5,
minimum size=\klen,
] (P1) {$P1$};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\foreach \x in {1,2,...,5}
\node at (P1.corner \x){$\x$};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\path let\p1=($(P1.corner 1)$),\p2=($(P1.corner 2)$),\n1={veclen(\x1-\x2,\y1-\y2)} in \pgfextra{\xdef\kside{\n1}};
\draw [red] (P1.corner 1)--node[midway]{\kside}(P1.corner 2);
\end{tikzpicture}
\end{document}