1

I am trying to create a polygon in VB6 using the polygon function.

I have many points in random order that I would like to create the polygon with.

Unfortunately, the order is important when developing a polygon, as i get a jagged looking polygon, as opposed to a nice closed polygon.

I was wondering if anyone had any good ideas/tricks to develop an algorithm that can go through these points and put them in an appropriate order.

Thanks so much!

gberg927
  • 1,636
  • 9
  • 38
  • 51

2 Answers2

5

To keep things simple and the solution unique, you should start with a convex hull algorithm like this one ("Gift Wrapping"):

http://en.wikipedia.org/wiki/Gift_wrapping_algorithm

Should not be too hard to implement in VB. If you have problems with that, ask a new question.

Doc Brown
  • 19,739
  • 7
  • 52
  • 88
3

I used the Graham Scan Algorithm to actually go ahead and solve this problem.

http://en.wikipedia.org/wiki/Graham_scan

If you follow the pseudocode, be careful.

The line

while ccw(points[M-1], points[M], points[i]) <= 0:

Should be

while ccw(points[M-1], points[M], points[i]) >= 0:
gberg927
  • 1,636
  • 9
  • 38
  • 51
  • Do you have a source to cite for the correction? I suspect the change may have applied to your interpretation of the pseudocode (perhaps you had something else was also reversed). I can't say either way, but it looks to me like several mathematician-types have [discussed](https://wikipedia.org/wiki/Talk:Graham_scan) the page over the years, and nobody took issue with it. On the other hand, if you find an error on Wikipedia (and can cite a [reliable source](https://wikipedia.org/wiki/Wikipedia:Reliable_sources)), you can simply [edit](https://wikipedia.org/wiki/Help:Editing) the page yourself. – ashleedawg Nov 06 '19 at 11:29