Plot region from given coordinates [duplicate]

This question already has an answer here:

How to ensure that Polygon[list] plots a simple polygon?

3 answers

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.

=================

=================

2 Answers
2

=================

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

1

 

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 at 1:26