<s>
The	O
painter	O
’s	O
algorithm	O
(	O
also	O
depth-sort	O
algorithm	O
and	O
priority	B-Algorithm
fill	I-Algorithm
)	O
is	O
an	O
algorithm	O
for	O
visible	B-Algorithm
surface	I-Algorithm
determination	I-Algorithm
in	O
3D	O
computer	O
graphics	O
that	O
works	O
on	O
a	O
polygon-by-polygon	B-General_Concept
basis	O
rather	O
than	O
a	O
pixel-by-pixel	B-Algorithm
,	O
row	O
by	O
row	O
,	O
or	O
area	O
by	O
area	O
basis	O
of	O
other	O
Hidden-Surface	B-Algorithm
Removal	I-Algorithm
algorithms	O
.	O
</s>
<s>
The	O
painter	O
’s	O
algorithm	O
creates	O
images	O
by	O
sorting	B-Algorithm
the	O
polygons	B-General_Concept
within	O
the	O
image	O
by	O
their	O
depth	O
and	O
placing	O
each	O
polygon	B-General_Concept
in	O
order	O
from	O
the	O
farthest	O
to	O
the	O
closest	O
object	O
.	O
</s>
<s>
The	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
was	O
initially	O
proposed	O
as	O
a	O
basic	O
method	O
to	O
address	O
the	O
Hidden-surface	B-Algorithm
determination	I-Algorithm
problem	O
by	O
Martin	O
Newell	O
,	O
Richard	O
Newell	O
,	O
and	O
Tom	O
Sancha	O
in	O
1972	O
,	O
while	O
all	O
three	O
were	O
working	O
at	O
CADCentre	O
.	O
</s>
<s>
The	O
name	O
"	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
"	O
refers	O
to	O
the	O
technique	O
employed	O
by	O
many	O
painters	O
where	O
they	O
begin	O
by	O
painting	O
distant	O
parts	O
of	O
a	O
scene	O
before	O
parts	O
that	O
are	O
nearer	O
,	O
thereby	O
covering	O
some	O
areas	O
of	O
distant	O
parts	O
.	O
</s>
<s>
Similarly	O
,	O
the	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
sorts	O
all	O
the	O
polygons	B-General_Concept
in	O
a	O
scene	O
by	O
their	O
depth	O
and	O
then	O
paints	O
them	O
in	O
this	O
order	O
,	O
farthest	O
to	O
closest	O
.	O
</s>
<s>
Thus	O
,	O
a	O
valid	O
ordering	O
can	O
be	O
described	O
as	O
a	O
topological	B-Algorithm
ordering	I-Algorithm
of	O
a	O
directed	O
acyclic	O
graph	O
representing	O
occlusions	O
between	O
objects	O
..	O
</s>
<s>
Conceptually	O
Painter	B-Algorithm
's	I-Algorithm
Algorithm	I-Algorithm
works	O
as	O
follows	O
:	O
</s>
<s>
sort	O
polygons	B-General_Concept
by	O
depth	O
for	O
each	O
polygon	B-General_Concept
p	O
:	O
</s>
<s>
for	O
each	O
pixel	B-Algorithm
that	O
p	O
covers	O
:	O
</s>
<s>
The	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
's	O
time-complexity	O
is	O
heavily	O
dependent	O
on	O
the	O
sorting	B-Algorithm
algorithm	I-Algorithm
used	O
to	O
order	O
the	O
polygons	B-General_Concept
.	O
</s>
<s>
Assuming	O
the	O
use	O
of	O
the	O
most	O
optimal	O
sorting	B-Algorithm
algorithm	I-Algorithm
,	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
has	O
a	O
worst-case	O
complexity	O
of	O
O( n	O
log	O
n	O
+	O
m*n	O
)	O
,	O
where	O
n	O
is	O
the	O
number	O
of	O
polygons	B-General_Concept
and	O
m	O
is	O
the	O
number	O
of	O
pixels	B-Algorithm
to	O
be	O
filled	O
.	O
</s>
<s>
The	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
's	O
worst-case	O
space-complexity	O
is	O
O( n+m	O
)	O
,	O
where	O
n	O
is	O
the	O
number	O
of	O
polygons	B-General_Concept
and	O
m''	O
is	O
the	O
number	O
of	O
pixels	B-Algorithm
to	O
be	O
filled	O
.	O
</s>
<s>
The	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
not	O
as	O
complex	O
in	O
structure	O
as	O
its	O
other	O
depth	O
sorting	B-Algorithm
algorithm	I-Algorithm
counterparts	O
.	O
</s>
<s>
The	O
algorithm	O
can	O
fail	O
in	O
some	O
cases	O
,	O
including	O
cyclic	O
overlap	O
or	O
piercing	O
polygons	B-General_Concept
.	O
</s>
<s>
In	O
the	O
case	O
of	O
cyclic	O
overlap	O
,	O
as	O
shown	O
in	O
the	O
figure	O
to	O
the	O
right	O
,	O
Polygons	B-General_Concept
A	O
,	O
B	O
,	O
and	O
C	O
overlap	O
each	O
other	O
in	O
such	O
a	O
way	O
that	O
it	O
is	O
impossible	O
to	O
determine	O
which	O
polygon	B-General_Concept
is	O
above	O
the	O
others	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
offending	O
polygons	B-General_Concept
must	O
be	O
cut	O
to	O
allow	O
sorting	B-Algorithm
.	O
</s>
<s>
The	O
case	O
of	O
piercing	O
polygons	B-General_Concept
arises	O
when	O
one	O
polygon	B-General_Concept
intersects	O
another	O
.	O
</s>
<s>
Similar	O
to	O
cyclic	O
overlap	O
,	O
this	O
problem	O
may	O
be	O
resolved	O
by	O
cutting	O
the	O
offending	O
polygons	B-General_Concept
.	O
</s>
<s>
In	O
basic	O
implementations	O
,	O
the	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
be	O
inefficient	O
.	O
</s>
<s>
It	O
forces	O
the	O
system	O
to	O
render	O
each	O
point	O
on	O
every	O
polygon	B-General_Concept
in	O
the	O
visible	O
set	O
,	O
even	O
if	O
that	O
polygon	B-General_Concept
is	O
occluded	O
in	O
the	O
finished	O
scene	O
.	O
</s>
<s>
This	O
means	O
that	O
,	O
for	O
detailed	O
scenes	O
,	O
the	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
can	O
overly	O
tax	O
the	O
computer	O
hardware	O
.	O
</s>
<s>
Newell	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
proposed	O
as	O
the	O
extended	O
algorithm	O
to	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
,	O
provides	O
a	O
method	O
for	O
cutting	O
cyclical	O
and	O
piercing	O
polygons	B-General_Concept
.	O
</s>
<s>
Another	O
variant	O
of	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
includes	O
reverse	O
painter	O
's	O
algorithm'''	O
.	O
</s>
<s>
Reverse	B-Algorithm
painter	I-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
paints	O
objects	O
nearest	O
to	O
the	O
viewer	O
first	O
—	O
with	O
the	O
rule	O
that	O
paint	O
must	O
never	O
be	O
applied	O
to	O
parts	O
of	O
the	O
image	O
that	O
are	O
already	O
painted	O
(	O
unless	O
they	O
are	O
partially	O
transparent	O
)	O
.	O
</s>
<s>
The	O
flaws	O
of	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
led	O
to	O
the	O
development	O
of	O
Z-buffer	O
techniques	O
,	O
which	O
can	O
be	O
viewed	O
as	O
a	O
development	O
of	O
the	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
by	O
resolving	O
depth	O
conflicts	O
on	O
a	O
pixel-by-pixel	B-Algorithm
basis	O
,	O
reducing	O
the	O
need	O
for	O
a	O
depth-based	O
rendering	O
order	O
.	O
</s>
<s>
Even	O
in	O
such	O
systems	O
,	O
a	O
variant	O
of	O
the	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
is	O
sometimes	O
employed	O
.	O
</s>
<s>
These	O
are	O
overlaps	O
or	O
gaps	O
at	O
joints	O
between	O
polygons	B-General_Concept
.	O
</s>
<s>
To	O
avoid	O
this	O
,	O
some	O
graphics	O
engines	O
implement	O
"	O
over-rendering	O
"	O
,	O
drawing	O
the	O
affected	O
edges	O
of	O
both	O
polygons	B-General_Concept
in	O
the	O
order	O
given	O
by	O
the	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
This	O
means	O
that	O
some	O
pixels	B-Algorithm
are	O
actually	O
drawn	O
twice	O
(	O
as	O
in	O
the	O
full	O
painter	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
)	O
,	O
but	O
this	O
happens	O
on	O
only	O
small	O
parts	O
of	O
the	O
image	O
and	O
has	O
a	O
negligible	O
performance	O
effect	O
.	O
</s>
