Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)

share|improve this question

migrated from May 28 '12 at 21:45

This question came from our site for people studying math at any level and professionals in related fields.

up vote 4 down vote accepted

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]];
edges = Thread[vertices \[DirectedEdge] RotateLeft[vertices]];

Graph[vertices, edges, VertexCoordinates -> crds,
 EdgeShapeFunction -> GraphElementData[{"Arrow", "ArrowSize" -> .1}]]

Mathematica graphics

You can also use Graphics primitives, for example

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

Graphics[{Red, Arrow /@ edges1}]

Mathematica graphics

share|improve this answer
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}]

enter image description here


    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]

enter image description here

share|improve this answer
Thanks! Two good answers... but I had to pick one. I really appreciate the help. – Steve May 28 '12 at 22:11

You had this already

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

You can turn it into something similar to what you want with

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

Mathematica graphics

share|improve this answer
+1 Very nice! Thank you! – Steve May 29 '12 at 15:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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