Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7512
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: drawing polygon diagonals |
| Date | 2012-01-01 07:32 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jdp273$rqq$1@smc.vnet.net> (permalink) |
| References | <i6755n$873$1@smc.vnet.net> |
On 2010-09-08 04:58:31 +0000, MH said:
> 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.
To get some practice with GraphicsComplex, I spent some time figuring
out how to distinguish the diagonals from the other line segments.
Thanks very much to the others who explained GraphicsComplex. It looks
like a big time-saver. It must also help when figuring out shared
borders of polygons, since the indices are just integers, rather than
the real numbers you'd need to match up vertices.
There's a screen shot at
http://home.comcast.net/~cy56/DiagonalsOfPolygon.png
and a notebook at
http://home.comcast.net/~cy56/DiagonalsOfPolygon.nb
I use short horizontal lines, via the keyboard shortcut esc-hline-esc
(where "esc" stands for the Escape key) to distinguish any names I use
starting with a capital letter from Mathematica's functions. I use two
of them in a row to separate words in a Boolean flag, such as
"show_border", since we can't use the underscore character, which is
reserved for pattern matching. Apparently, Mathematica will allow a lot
of these special characters in names, which is very handy.
Manipulate[
Module[
{P = \[HorizontalLine]CrcPts[n]},
Graphics[
GraphicsComplex[
P,
{
PointSize[Large],
If[show\[HorizontalLine]\[HorizontalLine]points,
Table[{Hue[(k - 1)/n], Point[k], Black,
Text[k, P[[k]], -2.5*P[[k]]]}, {k, 1, n}]
],
If[show\[HorizontalLine]\[HorizontalLine]border,
{Thick, Line[Range[1, n]~Append~1]}
],
If[show\[HorizontalLine]\[HorizontalLine]diagonals,
{Thin, Dashed,
Line[Select[
Subsets[Range[1, n], {2}], #[[2]] - #[[1]] > 1 &]]}
]
}
]]],
{{show\[HorizontalLine]\[HorizontalLine]points, True}, {True, False}},
{{show\[HorizontalLine]\[HorizontalLine]border, True}, {True, False}},
{{show\[HorizontalLine]\[HorizontalLine]diagonals, True}, {True,
False}},
{{n, 6}, 2, 12, 1}
]
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: drawing polygon diagonals Chris Young <cy56@comcast.net> - 2012-01-01 07:32 +0000
csiph-web