I have N points on a circle, I want to draw the intersection of the convex hulls of all sets of N-k consecutive points.
The points are not evenly spaced. The values of N and k (and the actual angles of each point) will change, so I'd rather not have a hard-coded solution.
Here is the best I've come up with. The silly way does exactly what I want, but it involves a lot of cut-and-paste every time. I don't understand why the second way fails; I've read that variables in \foreach loops don't quite behave as variables (I think), but I can't figure out a way around this.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,inner sep=0mm}]
\def\rad{5cm}
\def\k{2}
\def\N{6}
\node (x1) at (15:\rad) {} ;
\node (x2) at (45:\rad) {} ;
\node (x3) at (90:\rad) {} ;
\node (x4) at (120:\rad) {} ;
\node (x5) at (210:\rad) {} ;
\node (x6) at (270:\rad) {} ;
%%% draw all the lines from xi to x(i+k)
\foreach \i in {1,2,3,4,5,6} {
\pgfmathtruncatemacro{\j}{1+mod(\i-1+\k,6)}
\draw (x\i) -- (x\j) ;
}
%%% draw the intersection of all convex hulls of 5 consecutive points among the six
%%% this is a silly way
\clip (x1.center) -- (x2.center) -- (x3.center) -- (x4.center) -- (x5.center) -- cycle ;
\clip (x2.center) -- (x3.center) -- (x4.center) -- (x5.center) -- (x6.center) -- cycle ;
\clip (x3.center) -- (x4.center) -- (x5.center) -- (x6.center) -- (x1.center) -- cycle ;
\clip (x4.center) -- (x5.center) -- (x6.center) -- (x1.center) -- (x2.center) -- cycle ;
\clip (x5.center) -- (x6.center) -- (x1.center) -- (x2.center) -- (x3.center) -- cycle ;
\fill (x6.center) -- (x1.center) -- (x2.center) -- (x3.center) -- (x4.center) -- cycle ;
%%% draw the intersection of all convex hulls of N-k+1 consecutive points among the N
%%% this is the code I think should work but doesn't
%%% error message: ! Package tikz Error: Giving up on this path. Did you forget a semicolon?.
\foreach \a in {1,...,\N}{
\pgfmathsetmacro{\b}{1+mod(\a+\k,\N)}
\draw (x\a) -- (x\b)
\foreach \x in {\k,...,\N} {
\pgfmathtruncatemacro{\xp}{1+mod(\a+\x-1,\N)}
\pgfmathtruncatemacro{\xq}{1+mod(\a+\x,\N)}
(x-\xp) -- (x-\xq)
} ;
}
\end{tikzpicture}
\end{document}