# Plot region from given coordinates [duplicate]

This question already has an answer here:

How can I connect given coordinates and create figure from it? Can I fill it with colour? I tried:

Line[{a[[1]], a[[2]], a[[3]], a[[4]], a[[5]], a[[1]]}]

where a is my list. It doesnt look good.

a consists of coordinates in 2D {x,y} pairs. I want to connect all points to form a region/space/figure and fill that region with colour.

## marked as duplicate by Yves Klett, Öskå, MarcoB, user9660, Jason B.Jan 18 '16 at 9:41

• We need more information. Provide an example list a. What do you mean by "fill it with color"? - the line has a color? - color fill between the line and the axis? What do you mean by "it doesn't look good"? Did you embed the Line in a Graphics object? Etc. – march Dec 17 '15 at 19:45
• a consists of coordinates {{-0.9504, -0.31103}, {-0.946885, -0.321572}, {0.848087, 0.529857}, {0.998268, -0.0588254}} I want to connect them to form a region/space/figure and fill that region with colour. – Tsin Dec 17 '15 at 19:48
• Please add relevant information to your post by clicking the grey edit button at the bottom of the post. In addition, please format your code correctly. – march Dec 17 '15 at 19:50
• Done. Can you answer my question please? – Tsin Dec 17 '15 at 19:54
• – Rahul Dec 17 '15 at 21:38

Just for fun

(*psuedo-data*)
data = RandomReal[{0, 10}, {5, 2}];

(*process*)
Manipulate[
Graphics[{col, Polygon @ pts}],
{{pts, data}, Locator},
{{col, Green, "Color"}, {Green, Blue, Red}}]


• Omg 1k reputation! – e.doroskevic Jan 17 '16 at 16:03

To avoid polygons whose edges cross themselves, try this:

ConvexHullMesh[a]


For instance:

a = RandomReal[{0, 1}, {5, 2}];

Graphics[Polygon[a]]


ConvexHullMesh[a]


or

ConvexHullMesh[a, PlotTheme -> "Lines", MeshCellStyle -> Black]


Note that FindShortestTour does not work:

a = {{0, 0}, {1, 0}, {1, .1}, {2, .1}, {2, 0}, {3, 0}, {1.5, 1}};

Graphics[Line[a[[FindShortestTour[a][[2]]]]]]


which is not convex.

• Why is it a problem if the FindShortestTour solution is not convex? – Rahul Dec 18 '15 at 1:22
• There is no reason the shortest tour need be convex... The shortest tour must go through every point, which includes those in the interior of the convex hull. Hence the shortest tour will rarely be convex. – David G. Stork Dec 18 '15 at 1:25
• Yes, that's fine, but why is that a problem? You say this approach "does not work", but the asker didn't ask for a convex figure. – Rahul Dec 18 '15 at 1:28
• Yes he did... when he wrote: "it doesn't always work. For some values sometimes it creates figures like this i.imgur.com/tAeOCSa.png?1 I want it to create geometric figures." – David G. Stork Dec 18 '15 at 1:29
• @David that's self intersection, but non convex is probably fine. – LLlAMnYP Jan 17 '16 at 1:26