1

How can I extract simple polygons out of a polygon which contains collinear edges? For the very simple case below, edge 2-3 and 6-0 are collinear. I want to separate this as 0, 1, 2 and 3, 4, 5, 6.

I could compare collinearity of every edge against every other edge, but that is a slow O(n^2) approach. Is there a faster method?

alt text

Morrowless
  • 6,856
  • 11
  • 51
  • 81

2 Answers2

2

Find a bounding circle. Compute the upper/right intersection between the bounding circle and the line each edge lies on. This is O(n). Now sort each edge by the tuple of its angle and the angular position of its intersection with the bounding circle. That's O(nlogn), and will group the collinear edges together in your sorted list.

If you're unlikely to have lots of parallel but non-collinear edges then you can skip the bounding circle thing and just sort by angle. If there are lots of parallel non-collinear angles then just using angle still "works", it just doesn't buy you nearly as much efficiency improvement.

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
  • You can do the same thing by just converting each line to slope-intersect form. Note that either way you can also use a hash set instead of sorting. – Chris Hopman Jan 10 '11 at 08:05
  • I'm having difficulty understanding this. Which angles do I look at, if I wanted to do the bounding circle? – Morrowless Jan 10 '11 at 08:16
  • @Chris Yeah, my initial thought was to use slope-intercept form, but then you need to special case vertical edges. The bounding circle thing was an attempt to avoid that. Hashing makes it hard to deal with imprecision. Sorting puts things that are really similar close together so you can choose how to deal with small differences. You can try to "hash-away" small differences, but you'll run into trouble near hash boundaries. If you really want to hash you can have overlapping hash buckets, and place each edge in multiple buckets. – Laurence Gonsalves Jan 10 '11 at 16:42
  • @hyn If you place a bounding circle around the polygon every edge will lie on a line that intersects the bounding circle twice. Find the location of the upper/right intersection with the bounding circle, and figure out the angle around the bounding circle of that point. eg: if th point is the right-most point on the bounding circle then it's 0 radians, the top-most is pi/2 radians, etc. You then want a tuple of this angle and the angle of the edge itself. – Laurence Gonsalves Jan 10 '11 at 16:50
0

Can you find the intersection of 1-2 and 6-0? If so, you can generate a graph of edges and vertices. Then, finding the all non-overlapping polygons is simple.

Josh C.
  • 4,303
  • 5
  • 30
  • 51