Re: drawing polygon diagonals

*To*: mathgroup at smc.vnet.net*Subject*: [mg112315] Re: drawing polygon diagonals*From*: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>*Date*: Thu, 9 Sep 2010 04:22:03 -0400 (EDT)*References*: <i6755n$873$1@smc.vnet.net>

Hi Matthew, I simplified the code somewhat using GraphicsComplex. In this way it is pretty easy to generate all the connecting lines using Subsets. Manipulate[ pts = Table[{Cos[2 Pi*k/n], Sin[2 Pi*k/n]}, {k, 1, n}]; Graphics[ { Black, Thickness[0.005], GraphicsComplex[pts, Line[Subsets[Range[n], {2}]]], Red, PointSize[0.035], GraphicsComplex[pts, Point[Range[n]]] }, PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}} ], {n, 2, 20, 1} ] Cheers -- Sjoerd On Sep 8, 6:58 am, MH <matthewh... at gmail.com> wrote: > Hi, > > This seems basic but it has me stumped. I'm trying to illustrate the > idea of the "handshake problem", where small circles represent people > and the lines between the circles represent handshakes. With the code > below, I'm able to show (and manipulate) any number of circles, and > I'm also able to show the lines between adjacent circles. This just > generates a polygon whose vertices are all connected, as it should. > But how can I update my code to show the diagonals, too, and not just > the sides of the polygon? I'm not sure what to add. > > Thanks! > > MH > > ================= > > Manipulate[ > Graphics[{ > { > Table[{Black, Thickness[0.005], > Line[{{Cos[2 Pi*k/n], Sin[2 Pi*k/n]}, > {Cos[2 Pi*(k + 1)/n], Sin[2 Pi*(k + 1)/n]}}]}, > {k, 0, n - 1, 1} > ] > }, > { > Table[ > {Red, PointSize[0.035], Point[{Cos[2 Pi*k/n], Sin[2 Pi*k/n]}]}= , > {k, 0, n - 1, 1} > ] > } > }, > PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}} > ] > , {n, 2, 12, 1}]