# Rendering polygon as graph with directed edges in Mathematica

In Mathematica I'm trying to render a polygon as a set of vertices and directed edges.

What I have so far:

Graphics[Polygon[{{1, 10}, {2, 4}, {10, 5}, {20, 10}}]]


I see Mathematica has the Graph and PathGraph commands - both of which have a DirectedEdges option - but it seems like I have no control over the position of the vertices with these commands.

If I could customize the fill and edge/stroke of the Polygon command, that would be acceptable - but I'm not seeing how to do it. It looks like this command is specifically meant to draw filled polygons.

I'd also be OK with a custom Mathematica routine to draw what I want using a loop and multiple Line commands within a Graphics command - but I can't see how to draw the lines as arrows (I'm sure I could make the routine do this with three Lines per edge, but I really just think I'm missing something here.)

Graph has the option VertexCoordinates which allows you to specify the coordinates of the vertices, so you could do something like

crds = {{1, 10}, {2, 4}, {10, 5}, {20, 10}};
vertices = Range[Length[crds]];

Graph[vertices, edges, VertexCoordinates -> crds,
EdgeShapeFunction -> GraphElementData[{"Arrow", "ArrowSize" -> .1}]] You can also use Graphics primitives, for example

edges1 = Thread[{crds, RotateLeft[crds]}];

Graphics[{Red, Arrow /@ edges1}] • Loving the new Mathematica SE site! That's awesome... thank you very much. Just what I was looking for. – Steve May 28 '12 at 22:05
n = 5;
Graphics@Arrow@Table[{Sin[2 Pi i/n], Cos[2 Pi i/n]}, {i, 1, n + 1}] Edit

GraphicsGrid[Partition[
Table[Graphics@
Arrow@Partition[Table[{Sin[2 Pi i/j], Cos[2 Pi i/j]}, {i, 1, j + 1}], 2, 1],
{j,3, 12}], 3], Frame -> All] • Thanks! Two good answers... but I had to pick one. I really appreciate the help. – Steve May 28 '12 at 22:11

pol = Graphics[Polygon[{{1, 10}, {2, 4}, {10, 5}, {20, 10}}]];

pol /. Polygon[i_] :> Thread@Arrow@Partition[i, 2, 1, 1] 