# CS488 - Introduction to Computer Graphics - Lecture 6

1. View frame.

## Device Transformations

#### Windows

On the view plane

On the device

#### Normalized Device Coordinates

For the device, obviously

## Clipping

What is it?

#### Representations of Lines

1. Parametric
• The set of points L(t) on the line is given by L(t) = P + t ( Q - P )
2. Implicit
• n - unit vector normal to line (Q, P); that is, n \dot (Q - P) = 0
• Any point L on the line satisfies n . ( L - P ) = 0.
• If P is any point on the line then d( R ) = ( R - P ) . n is the signed distance to the line

Why?

1. Draw the line (Q, P) and the point R.
2. Place a point S on the line so that R-S is perpendicular to Q - P..
3. If \theta is the angle between R - S and R - P then (R - S) \dot (R - P) = |(R - S)| |(R - P)| cos(\theta)
4. But R - S = |R - S| * (sign) * n
5. Thus, n \dot (R - P) = (sign) * |R - P| * cos(\theta)

#### Clip a Point against a Line

This means: which side of a line Q - P is a point R, above it or below it?

• evaluate n \dot (R - P), or equivalently n \dot (R - Q)
• Check the magnitude
• 0 means on the line
• Check the sign
• + means one side of the line
• - means the other side

Which side depends on the direction chosen for n.

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

Representation of a Half-space.

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

Calculate d = ( R - P ) . n

• If d > 0, inside.
• If d < 0, outside.
• If d = 0, on the line.

The direction of n has been chosen to point towards the inside.

#### 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 = { - ( R - P ) . n } / { ( S - P ) . n - ( R - P ) . n }
• Is this really an optimization with todays compilers?

#### Clip a Line Segment to a Rectangle

Define a rectangle as a collection of half spaces, then it is straightforward. Really?

• What if the line segment crosses a corner?

## Perspective Projection

For a comprehensive introduction to perspective projection, more than most of you want to know, look at this pdf.

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.

#### Perspective Projection from 1D to 1D

The 1D Cartesian Space.

• A line plus an origin.

Projection from a 1D space to a 1D space.

1. We draw it in two dimensions (Why?)
2. Pencil of lines through a projection point: all points on a line are the same' point.
3. Affine transformations from 1D to 1D
• What can an affine transformation do in 1D? Translate, reflect, scale.
• Projection points at infinity translate.
• A projection point between the origins reflects.
• Projection points on the line that joins the origins, and outside the lines, scale.
• What do other projection points do?

What does this type of projection have to do with computer graphics?

• Perspective projection maps 3D world space to the 2D viewplane.
• What happens if the projection point is on one of the lines?