6

I have a list of named points (from mark-1 to mark-26) and I want to use them as vertexes of a polygon, which should be filled blue.

I don't want to write them down in a path manually because they will change in other versions of the document (going from 26 to 20 or something like that).

I've tried this:

\newcommand{\aaa}{
    \foreach \x [count=\xi from 2] in {1,...,25} {(mark-\x) -- (mark-\xi)}
};
\fill[blue] \aaa -- (mark-1) -- cycle;

but it seems that \aaa catches just the last 2 points (25 and 26).

Update: Since the answer requires some details, I'm generating the nodes using decorations along a path:

\begin{scope}[
          every path/.style={
            decoration={
                markings,
                mark=between positions 0.57 and 1.2 step 6pt with {
                    \node[
                          red,
                          %nodes going from mark-1 to mark-26
                          name=mark-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}
                         ] circle (2pt);
                }
            }
          }
]
    % load base compound path
    \input{img/comp}
\end[scope]

Thank you

  • 1
    you are not creating a polygon but a lot of standalone paths. So only the last path is filled. – percusse Feb 15 '14 at 8:55
  • Are you trying to draw a polygon of 26 sides? – user11232 Feb 15 '14 at 9:42
  • definitely, yes. – fradeve Feb 15 '14 at 9:43
12

Something like this?

\documentclass[tikz,border=0.125cm]{standalone}
\begin{document}
\begin{tikzpicture}
% Create random(ish) points
\foreach \i in {1,...,26}
  \fill [opacity=0.5] (360/26*\i:1+rnd*1) circle [radius=.025] coordinate (mark-\i);

% Join them up
\fill [opacity=0.5,blue]
  (mark-1) \foreach \i in {2,...,26}{ -- (mark-\i) } -- cycle;
\end{tikzpicture}
\end{document}

enter image description here

  • Your solution works as standalone example, I've compiled it correctly, but it fails in my context (img here). I've updated the question with my code, since I'm generating the mark-n points as decoration nodes. – fradeve Feb 15 '14 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.