Mastering Algorithms With C - Kyle Loudon [213]
Testing whether line segments intersect
Using a simple algorithm consisting of two steps: first, we test whether the bounding boxes of the line segments intersect, and then we test whether the line segments straddle each other. If both tests are successful, the two line segments intersect.
Convex hulls
Minimum-size convex polygons that enclose sets of points. A polygon is convex if any line segment connecting two points inside the polygon lies completely inside the polygon itself.
Arc length on spherical surfaces
The distance along an arc between two points on the surface of a sphere. Specifically, we calculate the length of the arc that lies in the same plane as imaginary lines drawn from the center of the sphere to either endpoint of the arc on the sphere's surface.
Some applications of geometric algorithms are:
Farthest-pair problems
Problems in which we determine which two points in a set are located the farthest apart. It can be shown that these points must lie on the convex hull enclosing all of the points. Thus, the number of pairs whose distances are compared can be greatly reduced by first computing a convex hull.
Approximating distances on Earth (illustrated in this chapter)
An interesting application of arc lengths on spherical surfaces. However, since the Earth is not a perfect sphere but an ellipsoid, the distance computed is only an approximation.
Restricted regions
Polygons that enclose areas not to be entered from outside. For example, military organizations define restricted regions in which unauthorized aircraft are not permitted to fly. If the track of an aircraft consists of a series of line segments beginning outside of the region, a simple way to determine whether a proposed route of flight transgresses the region is to test whether any segment on the track intersects with any segment defining the region.
Physical enclosures
Structures that surround a number of objects, such as buildings or natural phenomena. Often one of the requirements in constructing a large enclosure is to build it using the least amount of materials. To do this, we can model the objects as points and compute the convex hull around them.
Robotics
An exciting area of research in which automated, artificially intelligent devices use geometric algorithms for vision and control. For example, a robot with navigational capabilities must be able to move around objects that get in its way and analyze various shapes to recognize where it is.
Cartographic information systems
Database systems containing geographical data generally used for mapping. Often this information is manipulated using geometric algorithms. For example, we might want to compute the distance between two geographical points stored in the system.
Virtual reality systems
Examples are flight simulators, systems for architectural visualization, and systems for molecular modeling. One important aspect of virtual reality systems is their use of computer graphics involving geometric algorithms.
Example 17.1. Header for Geometric Algorithms
/*****************************************************************************
* *
* ------------------------------ geometry.h ------------------------------ *
* *
*****************************************************************************/
#ifndef GEOMETRY_H
#define GEOMETRY_H
#include "list.h"
/*****************************************************************************
* *
* Define an approximation for Pi. *
* *
*****************************************************************************/
#ifndef PI
#define PI 3.14159
#endif
/*****************************************************************************
* *
* Define macros for comparisons. *
* *
*****************************************************************************/
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
/*****************************************************************************
* *
* Define macros for converting between degrees