Painter's Algorithm:
As the name recommend, the algorithm follows the standard practice of a painter, who would paint the background (such as a backdrop) first, then the major details (such as a face), and finally the finer details (such as eyes). It is also called Depth Sort or Priority algorithm.
To find out the specific nature of the relative positions of polygons, it is essential to define the x-, y-, and z-extents, of a polygon in 3-D space as the respective coordinate ranges of the bounding (that means enclosing) box, as illustrated in Figure For the quadrilateral ABCD, the x-extent is (xD - xB), y-extent is (yA - yC), and z-extent is (zB - zD). The x- and y-extents of two polygons shall enable decisions to be made on their overlap, and the z-extent shall define their relative positions with respect to the viewer.
Depend on the extents, the farthest polygon is stored first, and over it the next farther polygon, and so on, until all of the polygons are stored. The second and subsequent polygons automatically superpose themselves over the earlier ones, and reveal just the visible portions. Figure shows the sequence of operations:
(a) (b) (c)
Figure: Painter's Algorithm
1. The farthest polygon, say the rectangle PQRS, is stored first.
2. The next farthest, the quadrilateral ABCD, is superposed, covering the portion PQUT of the rectangle and leaving visible the portion TURS of the rectangle.
3. At last the closest, say the triangle EFG, is superposed, wholly within the quadrilateral, and covering it in the region EFG.
The primary needs for this algorithm is the sorting of polygons by priority, depend on whether a polygon covers (or is covered by) another polygon partly or wholly. This determination is built by comparing the x-, y-, and z-extents of the various polygons.
In case the z-extents of any two polygons overlap, after that, if the two polygon planes are parallel to each other there is obscuring of one by the other; if the two polygon planes are not parallel, they can intersect each other. In such cases, the covered/uncovered or penetrated invisible/visible portions are found out by geometrical and clipping procedures, involving the determination of the line of intersection of the two polygons if essential, and separated into independent regions.