Math Physics ML

Pick's Theorem : The area of a Polygon

This page shows a powerful trick on how to compute the area defined by any polygon with integer vertices.
Namely, the area of such a polygon is :
(number of point inside of it) + (number of points on the frontier) / 2 - 1, this is known as Pick's Theorem.
(The proper statement of the result and a proof sketch are given below).



X           Y

Enter integer point coordinates.

Draw

Area of the polygon :
Area = i + b / 2 - 1 =


Note: may not work for flat polygons



Theorem: (G. Pick, 1899)

Proof sketch :


We consider the function from the set of polygons to `mathbb{Q}`:

`A: P \mapsto i(P) +(b(P))/2 - 1`

where, as above, `i(P)` is the number of points interior to `P` and `b(P)` the number of point on its border.
The idea is to show first that the formula is valid for rectangles, then for triangles, and finally, using the property that any 2D Polygon can be decomposed into a set of triangles, we will obtain Pick's Theorem for the general case.

We consider a `m\times n` integer rectangle `R`.
Its area is given by `mathcal{A} = mn` and `i(R) = (m-1)(n-1)`, `b(R) = 2(m+n)`, we then directly have :

`A(P) = (m-1)(n-1) + (2(m+n))/2 - 1 = mn.`

Thus the formula holds for rectangles.

Next, let us consider a triangle `T` and three corresponding right triangles `U`, `V` and `W` each having as a hypotenuse one of the sides of T. This yields one of the two following cases:


We treat explicitly the first case where the orthogonal sides of `U`, `V` and `W` for a rectangle `R`, the other one is analogous. We know that Pick's formula holds for `U`, `V`, `W` and `R`, thus the area of `T` is:

`A(T) = A(R) - A(U) - A(V) - A(W).`

We have:

`b(R) = b(U) + b(V) + b(W) - b(T)`

and

`i(R) = i(A) + i(B) + i(C) + i(T) + (b(A) + b(B) + b(C) - b(R)) - 3.`

Using these equations we show that Pick's formula holds for `T`.
Any 2D polygon can be split into triangles (see triangulability), the theorem follows.


The hidden algorithms behind this simulation

While working on this simulation, I realized that there are several problems of 2D geometry that arise when studying non-self-intersecting polygons, and that the algorithms used to solve them (polygon generation from points, point-in-polygon algorithm, Ray Tracing, ...) are quite interesting in themselves. I also thought that they deserve their own small developments (if not their own page on this website).


See Also

The concept of integer polygons is related to a whole geometric and algebraic theory (Polytop Theory among others), which provides a whole lot of results dealing with the same kind of problems as the one presented on this page. For instance the Ehrhart theorem is a very nice generalization of Pick's theorem to higher dimension. This course by O. Debarre provides a very clear and concise introduction to Polytope theory, requiring only a very basic knowledge of linear algebra.


Sources :
Images : Morn, CC0, via Wikimedia Commons, Render glass scene; Wikimedia commons, Ray tracing
Autoencoders and ray tracing denoising
A paper on hardware considerations