ABSTRACT

This chapter begins with simple objects – lines, segments, boxes and finish with polygon algorithms. It discusses C++ code showing the discussed algorithms. The code uses the vec2 class for working with 2-dimensional vectors. One common problem in a two-dimensional -case is clipping one shape against another shape, i.e., computing part of the first shape contained inside the second. It can be clipping a line, a segment, a box or a polygon against another box or polygon. Another clipping problem often encountered in computer graphics is clipping a polygon by a line. Barycentric coordinates are a very convenient tool for processing triangles, interpolating a function over the triangle or subdividing the triangle into several triangles.