# CS488 - Introduction to Computer Graphics - Lecture 10

## Review

1. Non-rigid transformations
2. Normalized Device Coordinates

## Clipping

What is it?

#### Representations of Lines

1. Parametric
2. Implicit
• n - unit vector normal to line
• For the line L(t) = P + t ( Q - P ),
• the normal is defined by n . ( Q - P ) = 0
• If P is any point on the line then d( R ) = ( R - P ) . n is the signed distance to the line
• Checks (for homework)
1. If R is on the line then d( R ) = 0.
2. If R is off the line then d( R ) != 0.
3. How do you figure out which side of the line is positive?

#### Clip a Point against a Half-space.

Representation of a Half-space.

• Use the implicit representation of a line (P, n).
• Let the direction of the normal vector point to the inside.

Calculate ( R - P ) . n

• If > 0, inside.
• If < 0, outside.
• If = 0, on the line that bounds the half-space.

#### Clip a Line Segment to a Half-space.

The line segment

• L(t) = R + t ( S - R ), 0 < t < 1.

Test if each of R and S are inside. Calculate

1. ( R - P ) . n
2. ( S - P ) . n

There are three cases

1. Both inside: keep the segment as is.
2. Both outside: discard the segment.
3. One inside, one outside: the segment crosses the boundary of the half-space.
• Calculate the intersection
• ( L(t) - P ) . n = 0.
• t = { ( P - R ) . n } / { ( S - R ) . n }
• Optimize ??
• t = { ( P - R ) . n } / { ( S - P ) . n - ( R - P ) . n }
• What will an optimizing compiler do?
• Replace one of the end points by L(t), (Which one?)

#### Clip a Line Segment to a Rectangle

Straightforward, BUT what if the line segment crosses a corner?

## Perspective Projection

What is a projection?

• a `linear' mapping of points to points
• `linear' in the sense that lines map to lines
• not `linear' in the sense that a projection automatically commutes with addition
• Affine transformations are linear in both senses
• based on a centre of projection
• which might be at infinity
• relevance to computer graphics?
• importance of two dimensions in everyday life. (Lots here to think about!)

Projective transformations are a superset of affine transformations.

1. They do not preserve ratios of distance.
2. They do not preserve affine combinations.
3. They do not map vectors.
4. They do preserve the cross ratio.

Show 1D transformation on the board

1. Illustration in 2D. What does this mean? (Hint. homogeneous coordinates)
2. Projection point on one of the lines.
3. Relevance of the intersection point of two lines.
4. How the transformation changes as the projection point moves around.