0
$\begingroup$

How can I draw a polytope with the Graphics function? The documentation simply says that you can do it, but does not explain how. The example given only plots vertices, not the edges of the polytope. Using:

Graphics[Octagon]

gives an error. I also tried the following from a different question:

Graphics[Octagon & /@ Vertices[Octagon]]

and that does not work either. I also tried the following:

Graphics[Line[{{0, 0}, #}] & /@ Vertices[Octagon]]

and that does not work either. I also tried this:

Graphics[Line[{{0, 0}, #}] & /@ EdgeList[Octagon]]

and that gives an error as well. I also tried this:

Graphics[Line[{{0, 0}, #}] & /@ Faces[Octagon]]

and that does not work. It would be useful to have an answer that explains how this stuff works, because I just don't get it and the documentation does not explain enough that I can figure out the internal logic of these functions. The documentation page on Polytopes says it is a "tutorial", but there is no tutorial. It just lists the functions and then gives four short examples.

I almost got it to work with this:

Graphics[Line[Vertices[Octagon]]]

But it does not close up the last point.

$\endgroup$
9
  • $\begingroup$ Graphics[{Red, RegularPolygon[8], White, Text[Style["STOP", 110]]}] $\endgroup$
    – Jason B.
    Oct 14, 2016 at 16:32
  • 2
    $\begingroup$ Nothing in the documentation for the Polytopes Package says you can use it with Graphics. But this seems to work Graphics@Polygon@Vertices@Octagon $\endgroup$
    – Jason B.
    Oct 14, 2016 at 16:36
  • 1
    $\begingroup$ you mean this? $\endgroup$
    – yode
    Oct 14, 2016 at 16:37
  • $\begingroup$ @yode - that is really odd. If you look at the resulting Graphics, you see they are using 1070 vertices to make an octagon!!! $\endgroup$
    – Jason B.
    Oct 14, 2016 at 16:41
  • $\begingroup$ If what you want is the outline of a polytope: Graphics[{Black, RegularPolygon[1, 8], White, RegularPolygon[0.95, 8]}] $\endgroup$
    – bill s
    Oct 14, 2016 at 18:49

1 Answer 1

1
$\begingroup$

I figured out a way to do this, maybe not optimal, but it does work:

Graphics[Line[Append[Vertices[Octagon], First[Vertices[Octagon]]]]]

which produces:

enter image description here

Vertices produces a list of x-y coordinates and Line builds a list of line objects for each of the vertices in a chain. You have to append the coordinates of the first vertice to the end of the list so that the last vertice connects to the first one and closes the figure.

Note that Polygon does not solve the problem economically because it does not generate a figure of lines, it generates a region.

$\endgroup$
1
  • $\begingroup$ Try Graphics[{FaceForm[None], EdgeForm[Black], Polygon[Vertices[Octagon]]}], or Graphics[Line[{##, #1} & @@ Vertices[Octagon]]]. $\endgroup$ Oct 15, 2016 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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