1

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.

e.doroskevic
  • 5,959
  • 1
  • 13
  • 32
Tsin
  • 41
  • 2

2 Answers2

3

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}}]

polygon

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
e.doroskevic
  • 5,959
  • 1
  • 13
  • 32
1

To avoid polygons whose edges cross themselves, try this:

ConvexHullMesh[a]

For instance:

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

Graphics[Polygon[a]]

enter image description here

ConvexHullMesh[a]

enter image description here

or

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

enter image description here

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

enter image description here

which is not convex.

David G. Stork
  • 41,180
  • 3
  • 34
  • 96
  • 1
    Why is it a problem if the FindShortestTour solution is not convex? –  Dec 18 '15 at 01: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 01: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. –  Dec 18 '15 at 01: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 01:29
  • @David that's self intersection, but non convex is probably fine. – LLlAMnYP Jan 17 '16 at 01:26