CSCI 480/580 Lecture 27 - In-Class Problems

Let’s suppose, without loss of generality, that we’re looking to clip a triangle against the \(x = 1\) plane. We can develop a solution for this and generalize it to handle the other five clipping planes.

We saw that there are 4 cases we need to handle:

  1. all in (keep the triangle)
  2. all out (discard the triangle)
  3. one in, two out (create one clipped triangle)
  4. two in, one out (create two clipped triangles)

Case 4 is illustrated here:

  1. Given three vertices \(\mathbf{a}, \mathbf{b}, \mathbf{c}\), write pseudocode to decide which of the above cases applies to a given triangle when clipping against the \(x = 1\) plane.
  2. Write pseudocode to produce the vertices of \(\mathbf{a}', \mathbf{b}', \mathbf{c}'\) of the new triangle resulting from the case 3 (“one in, two out”).
  3. Write pseudocode to produce the vertices \(\mathbf{a}_1, \mathbf{b}_1, \mathbf{c}_1\) and \(\mathbf{a}_2, \mathbf{b}_2, \mathbf{c}_2\) of the two new triangles resulting from the case 4 (“two in, one out”).