Search code examples
viewgraphicspolygonviewportsurface

Painters algorithm test 2


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

S1 is completely behind/inside the overlapping surface S2 enter image description here

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?


Solution

    • If you consider the implicit equation of a plane, f(x, y, z) = ax + by + cz + d = 0, it should be clear that the points that make f(x, y, z) positive [or negative] are on the same side of the plane. Hence the sign test.

    • If S1 is not completely hidden by S2, painting S1 first will work. So you needn't test the "completely" condition.