0

I'm facing the following problem: I'm given a set of coordinates on an integer grid that define the vertices of a polygon. The polygon is guaranteed to be convex. It's proven that such a polygon can always be cut into 4 equal area parts by 2 orthogonal lines. Let's call the point of these lines' intersection P. Given that set, I should calculate the coordinates of P within the polygon and the angle the lines need to be turned on so that the lines cut the polygon into 4 equal parts.

I realise that, put generally, the cake cutting problem has no "good" solution. But this particular case of it should. I've searched for an algorithm to solve that problem, but found nothing useful. Where should I look?

My approach would be to calculate the coordinates of the centre of the polygon (that can be done more or less easily), place Pthere and then "wiggle" the lines until the areas of the parts match. But that sounds too inelegant.

UPD: that's the problem I'm dealing with. Perhaps this question should be suspended until I come up with actual code questions.

Chiffa
  • 1,486
  • 2
  • 19
  • 38
  • i have a feeling that the coordinates are integer so that searches can be performed on them, like finding a mean x coordinate. But it doesn't help much. – Chiffa Aug 15 '14 at 20:39

1 Answers1

1

Here is a partial sketch of the solution:

Choose an arbitrary direction and find the line parallel to that direction that splits the polygon in two. To achieve this, draw a line by every vertex to decompose the polygon in slabs. The respective areas of the slabs will tell you what slab the desired line intersects. Simple linear interpolation will give the exact location of the line.

Now your polygon is split in two convex polygons. For each halve, repeat the above procedure using the perpendicular direction. In general, you will get two distinct splitters, and what remains to be done is to find the direction such that they do coincide.

In the given direction, the splitters intersect four specific edges of the polygon. If you slightly rotate, they still intersect the same four edges. You can decompose a full turn in angular ranges such that the four intersected edges remain the same.

Knowing the four intersected edges, you can establish the relation that tells you the distance between the two perpendicular splitters as a function of the angle. Then you can compute the angle at which the two splitters coincide, and check if this angle belongs to the range defined for these edges.

By trying all ranges in turn, you will find the solution.

enter image description here

Note: the limits of the angular ranges correspond to directions parallel or perpendicular to the lines joining two vertexes.

  • I was thinking about something similar, but it looks like I'll have to recalculate the areas of the parts I get a lot -- probably after each rotation. – Chiffa Aug 13 '14 at 10:01
  • I guess that a dichotomic can allow to accelerate the process. This would be welcome as it seems that there are O(N²) intervals. –  Aug 13 '14 at 10:05