How many sets of four points in an MxN grid have one point contained by three other points?

126 Views Asked by At

Given a 3x3 grid:

1 2 3
8 9 4
7 6 5

We find 126 distinct sets of 4 points $$\binom{9}{4}$$

There are 8 cases such that when the points are connected with a line in clockwise direction, one point (in this case, 9) is contained by angle formed from joining the other three points with a line:

{1,3,6,9}, {1,4,6,9}, {1,4,7,9}, {2,4,7,9},

{2,5,7,9}, {2,5,8,9}, {3,5,8,9}, {3,6,8,9}.

i.e.enter image description here, where {1,4,7,9} contains 9.

For a grid of any m and n, how can we determine the number of sets for which such a condition holds? So, the number of sets across all $$\binom{mn}{4}$$

Where one point is inside angle formed by connecting the other 3 members of the set.

1

There are 1 best solutions below

5
On

Pick's theorem will tell you for a grid how many interior grid points you have inside a given triangle, in terms of the volume (easy to compute) and number of boundary points on the triangle (also easy to compute by computing for each side, the GCD of coordinates of the vector connecting one vertex to another). Also the answer is translation and rotation and reflection invariant since you are working on a grid. So this reduces a seemingly ${{mn} \choose 4}$ complexity calculation to one that is $O({{mn} \choose 2})$, basically by assuming one vertex is $(1,1)$ and the other vertices are in the upper-right. It's still not as good as an explicit formula but it can at least handle values of $mn$ that are the square of the values of $mn$ that you could previously handle by brute force.