# Polygons

• Ordered sets of vertices, joined sequentially (and cyclically) by straight lines.
• Simple polygons
• convex or concave
• no line crossings
• no holes

Adding extra vertices removes the problems

• at the cost of adding degeneracies
• Polygons cover the surface of an object
• each polygon has a normal vector,
• usually pointing out
• polygonal "skin" is often called a mesh

#### Clipping

Clipping a polygon reduces to clipping edges against

• lines in 2D
• planes in 3D

The clipping algorithm takes an ordered set of vertices [vi] and produces an ordered set of vertices [wi]. It relies on the following

• If one edge leaves the clipping region, a later edge must enter it.

The algorithm is

```for each edge of clipping region
for each edge of polygon // must be in sequence
clip edge against region
switch (result of clip)
case "all inside"
case "all outside"
do nothing
case "cross edge leaving region"
output crossing point
case "cross entering region"
output crossing point
output leading vertex of edge ```

Exercise. Hand execute this algorithm on several cases to make sure that you understand exactly how it works.

#### Projecting a Polygon

Lines project to lines so projecting the vertices projects a polygon in 3D to a polygon on the view plane.

#### Triangles

Sooner or later almost all polygons are converted to triangles

• there is not a unique way of doing so
• try to avoid long skinny triangles

#### Scan Conversion

Scan converting a polygon (in 2D)

```sort vertices in direction perpendicular to the scan lines
for each scan line
if scan line contains the next vertex
update and sort edge list
inside = false
for each pixel
if on next edge
inside = !inside
if (inside)
paint pixel```

Exercise. Expand "update and sort edge list" to make this a working algorithm.

Exercise. Hand execute your expanded algorithm on a triangle to make sure that you understand how it works.

Exercise. Hand execute your expanded algorithm on a non-convex polygon.