Finding the largest area axis-parallel square with a known center in a polygon

Finding the maximum volume shape that will fit inside of another shape is a common class of geometric optimization problem that occurs in many applications (computer graphics, collision detection, GIS, etc.). General problem formulations, such as finding the largest area axis-parallel rectangle in a polygon, involve complex analysis and do not have simple algorithmic solutions that are easy to implement.

Finding the largest area axis-parallel square with a known center in a polygon is a sufficiently restricted problem to admit a simple O(n) time and O(1) space solution. The analysis, algorithm, and implementation are very straightforward. I have found this problem formulation useful in computing cropping regions for eye images stenciled by hidden area meshes in virtual reality systems, but it should be general enough to be useful in other contexts.

Continue reading

Floating-Point Expansions: The Nonoverlapping Property

When evaluating geometric predicates with floating-point arithmetic, roundoff error can cause programs to make incorrect or inconsistent branching decisions. Jonathan Shewchuk refined and applied arbitrary precision floating-point techniques developed by Douglas Preist and others to the most commonly used geometric predicates. His adaptively evaluated predicates guarantee that their result is consonant with an exact evaluation and allow for the robust implementation of algorithms designed for Real-RAM machines.

Shewchuk’s technique is based on a structure called an expansion. An expansion is a set of regular floating point numbers \{x_1, ..., x_n\} whose exact sum x_n + ... + x_1 is equal to the number x that the expansion represents. He requires expansions to be nonoverlapping and sorted by magnitude (x_n largest, x_1 smallest). Two floating-point values x and y are nonoverlapping if the least significant nonzero bit of x is more significant than the most significant nonzero bit of y, or vice versa. The number zero does not overlap any number. Formally, x and y are nonoverlapping if there exist integers r and s such that x = r2^s and |y| < 2^s, or y = r2^s and |x| < 2^s.

Continue reading