# Painter's algorithm test 2 and test 3?

TEST #2: Surface S is completely behind the overlapping surface relative to the viewing position.

S1 is completely behind/inside the overlapping surface S2

How to check these conditions?

i) Set the plane equation of S2(Ax + By + Cz + D = 0), such that the surface S2 is towards the viewing position.

ii) Substitute the coordinates of all vertices of Substitute the coordinates of all vertices of S1(x', y',z') into the plane equation of S2 and check for the sign.

iii) If all vertices of S1 are inside S2 then S1 is behind S2. (Fig. 1).

i. e. Ax' + By' + Cz' + D < 0 ,x', y', z' are S1 vertices.

iv) If all vertices of S1 are outside S2 then S1 in front of S2.

My first question is why all vertices of one polygon(S1) substitute in the plane of another(S2) and value is less than 0 then we say S1 is behind S2? I don't understand when value less than 0 by the vertices of one polygon then we say one is behind another?

My second question is when Test #2 is passed (i.e. S1 is completely behind/inside the overlapping surface S2) why we coloring S1 first before S2. There is no necessitates to S1 because S1 is totally obscured by S2. So why we colored S2?

First, it's important to realize what "behind" means here, which could be confusing. The way it's being used in this context, "S1 is behind S2" doesn't actually mean that S1 is totally obscured by S2 from the camera position. Rather, it means that S1 is behind the plane containing S2. This means it's impossible for any part of S1 to obscure any of S2, thus S1 should be drawn before S2 in the painter's algorithm.

why all vertices of one polygon(S1) substitute in the plane of another(S2) and value is less than 0 then we say S1 is behind S2? I don't understand when value less than 0 by the vertices of one polygon then we say one is behind another?

That's how plane equations work. The equation $$Ax + By + Cz + D = 0$$ defines the points on the plane, but in fact it goes further: if you evaluate the left-hand side for a given point, you get a number that tells you how far that point is from the plane, and the sign tells you which side of the plane it's on.

Given the right-hand rule, plane equations are set up so that the front of the polygon (the visible side) is the side that gets positive values in the plane equation. So, all points behind the polygon will get negative values. Thus, if you check all the points of polygon S1, you will know S1 is entirely behind the plane of S2 if all of its vertices get negative values when substituted into S2's plane equation.