Consider the problem of determining whether a point lies inside relatively simple polygons, such as triangles or quadrilaterals. The general polygon case is more complex and is left to the reader (and can optionally be reduced to the triangle or quadrilateral case).
For triangles and quadrilaterals, the approaches presented here are very efficient when a single polygon must be tested against a large number of points, since they allow preprocessing. The basic idea is to transform the polygon's coordinate space into a space in which the test is easier to perform.
For example, a parallelogram defined by two generating vectors can always
be transformed into a unit square by an affine
transformation
.
A point
lies inside the parallelogram if
and
.
The same transformation also applies to triangles formed by the same
generating vectors, but with the test
and
.
Testing whether a point lies inside the parallelogram requires only four
multiplications and six additions.
Creating the affine transformation is more costly, but when many tests are
performed, this fixed cost is negligible.
To transform general quadrilaterals into a unit square , a
homographic transformation must be used (see Section 1.11).
Although computing the transformation has a high initial cost, checking
whether a point lies inside the geometric shape is relatively simple:
| (1.127) |
Paolo medici