4

I've got some 2D polygons, each as a list of clockwise coordinates. The polygons are simple (i.e. they may be concave but they don't intersect themselves) and they don't overlap eachother.

I need to subdivide these polygons into smaller polygons to fit a size constraint. Just like the original polygons, the smaller ones should be simple (non-self-intersecting) and the constraint is they should each fit within one 'unit square' (which, for sake of simplicity, I can assume to be 1x1).

The thing is, I need to do this as efficiently as possible, where 'efficient' means the lowest number of resulting (small) polygons possible. Computation time is not important.

Is there some smart algorithm for this? At first I thought about recursively subdividing each polygon (splitting it in half, either horizontally or vertically whichever direction is larger) which works, but I don't seem to get very optimal results with this. Any ideas?

Sheldon Pinkman
  • 1,086
  • 4
  • 15
  • 21
  • You need something like a "triangulator" ? – huseyin tugrul buyukisik Sep 10 '12 at 11:29
  • @tuğrul büyükışık: (oh there was a question about a 20x20 square before - just in case: yes, if I have a square of 20x20, the optimal subdivision in this case would be 400 squares of 1x1 each) Regarding a "triangulator": I'm not sure, I don't think so, the smaller polygons don't need to be triangles. They can be any random simple polygon, as long as it fits in a 1x1 square. – Sheldon Pinkman Sep 10 '12 at 11:30
  • 1
    Is it allowed to rotate the polygons? – Qnan Sep 10 '12 at 11:52
  • What is an optimal result for you? Small number of resulting polygons/vertices? – ltjax Sep 10 '12 at 12:00
  • @ltjax it's in the text, the optimal subdivision is the one with the least number of polygons – Qnan Sep 10 '12 at 12:00
  • @SheldonPinkman: Just out of curiosity: What are you using this for? Texture mapping? – ltjax Sep 10 '12 at 12:17

2 Answers2

9

Draw a circle with a center of one of the initial points of initial polygon and radius of your desired length constraint.

The circle will intersect at least two lines at two points. Now you have your first triangle by the biggest as possible. Then choose those intersections as next target. Do until there is no initial points left outside. You have your triangles as large as possible(so as few as possible)

  • Do not account the already-created triangle edges as an intersection point.
  • Resulting polygons are not always triangle, they can be quads too. Maybe larger point-numbers too!
  • They all just nearly equal to the desired size.

enter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description here

Fine-tuning the interior parts would need some calculation.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

huseyin tugrul buyukisik
  • 11,469
  • 4
  • 45
  • 97
  • The four dots (1 black, 3 red) in your fourth picture produce the leftmost quadrilateral in the final picture. That quadrilateral cannot fit inside any unit square since it has an obtuse angle adjacent to a side of length 1. All but one of the diamond shapes in the final picture appear to have the same problem. More explicitly: Draw a standard unit square. Translate and rotate that square until a base of it coincides with a diamond's side that is unit-length and next to an obtuse angle. Then a line from that angle has an endpoint outside the translated rotated unit square. – James Waldby - jwpat7 Sep 10 '12 at 14:40
  • You are right. Your are saying that using the square for `the diamonds of this example` or for whole shape from the beginnning? – huseyin tugrul buyukisik Sep 10 '12 at 14:48
  • A simple fix is to draw a line across the shorter diagonal of each diamond. Note, for circles method, suppose ABC and CDE are original polygon sides, angle ACE acute, and BC, CD unit length. Both of ABD and BDE are obtuse. I don't know what your method does if BD exceeds unit length. However, it might not be worthwhile to spell out your circle-method details: a method of moving squares may be simpler to do. Ie, slide a unit square along each side of the polygon, and recurse inside the polygon; offhand I'd expect the intersection calculations to be simpler than for the circle. – James Waldby - jwpat7 Sep 10 '12 at 15:35
  • That's awesome man, thanks a lot for the very thorough description! Currently reading in detail to fully grasp it. One thing though: the size constraint implies that the unit square (in which any sub-polygon should fit) cannot be rotated. But I guess that's not too hard to fix (divide circle radius and join criterium by sqrt(2) or something). – Sheldon Pinkman Sep 10 '12 at 23:40
4

I suggest you use the following:

  1. Triangulate the polygon, e.g. using a sweep line algorithm.

  2. Make sure all the triangles do not violate the constraint. If one violates the constraint, first try edge-flips to fix it, otherwise subdivide on the longest edge.

  3. Use dynamic programming to join the triangles, while maintaining the constraint and only joining adjacent polygons.

ltjax
  • 15,837
  • 3
  • 39
  • 62