2

I would simply like to compute the euclidean distance between 2 points and keep it in a variable.

This is what I did

\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}

What's my error here ? Shouldn't be ok to compute something inside curly braces ?

Given a shape drawn with shapes.geometric is possible to retrieve its side ?

pafao
  • 61
  • I think that this question and answers can help you: https://tex.stackexchange.com/q/295673/1952 – Ignasi Apr 26 '22 at 09:07
  • @Ignasi I haven't found anything about what P1.corner 1is. I tried several pgf utility functions/macros but nothing works. I would like some hints for my specific case. – pafao Apr 27 '22 at 07:24

1 Answers1

3

With the doc in french MANUEL DE PRISE EN MAIN POUR TIKZ Yves SOULET Mise à jour article Cahiers GUT no 50—septembre 2012 p.14 i propose this

    \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}

enter image description here

pascal974
  • 4,652