Command not producing expected output

by me--   Last Updated June 13, 2019 04:23 AM

This is a follow-on question from here. Things are almost working but something strange is going on with my \band command. It renders the first band correctly, but then the second band causes things to go haywire.





        \ifnum\xcnt=1\relax \addpathtoks{\draw[#1]}\else


    % This is what I expect the below \band invocations to produce, and this renders correctly.
    \draw[red] (360/3:1) -- (360/3*2:2) -- (360/3*3:3) --cycle;
    \draw[blue] (360/3:3) -- (360/3*2:2) -- (360/3*3:1) --cycle;


    % These bands, which should be equivalent to the above are not rendering correctly.


This renders like this:

enter image description here

The top picture is what I'd expect, but the bottom seems to re-render the same shape over the top of the existing one.

Weirder still, if two values are the same:


It renders a straight line:

enter image description here

And if all three values are the same, it renders nothing at all! It's like it's de-duplicating the list...?

So my questions are:

  1. Why does my repro above render the same triangle twice instead of the expected triangles?
  2. Why do duplicate values cause weird things to happen?
Tags : tikz-pgf

Answers 1

TikZ has all the means built in to simplify this quite a bit. All these macros can be absorbed in a simple style

band/.style={insert path={plot[samples at={0,1,2}]
    ({360/3*(\x+1)}:{#1}[\x]) -- cycle}}

with which you only need to say


You could make this a macro, but this would make it less powerful. MWE:

\begin{tikzpicture}[band/.style={insert path={plot[samples at={0,1,2}]
    ({360/3*(\x+1)}:{#1}[\x]) -- cycle}},font=\sffamily]

  \begin{scope}[xshift=-5cm,local bounding box=by hand]
    \draw[red] (360/3:1) -- (360/3*2:2) -- (360/3*3:3) --cycle;
    \draw[blue] (360/3:3) -- (360/3*2:2) -- (360/3*3:1) --cycle;
  \node[above=1ex] at (by hand.north){by hand};
  \begin{scope}[local bounding box=automatic]
  \node[above=1ex] at (automatic.north){automatic};

enter image description here

June 13, 2019 04:02 AM

Related Questions

Updated April 27, 2019 15:23 PM

Updated December 20, 2018 03:23 AM

Updated November 20, 2018 12:23 PM

Updated December 17, 2018 22:23 PM

Updated December 18, 2018 02:23 AM