CS488 - Introduction to Computer Graphics - Lecture 6
Public Service Announcements
- Assignment 2 due 4 June, one week from now.
- Affine transformations
- occur in the form M-1 T M, where T can be any transform, including
T = N-1 S N
- If M commutes with T then M-1 T M = T
Clipping
What is it?
Clipping in 2D
Representations of Lines
- Explicit:
- y = mx + b
- y = b + x (y2 - y1) / (x2 - x1) = (x - x1) (y2 - y1) / (x2 -
x1)
- Parametric,
- L(t) = P +
t v = P + t ( Q - P )
- To calculate b above
- Lx(t) = 0 = Px + t(Qx - Px)
- t = Px / (Px - Qx)
- Ly = Py - Px ( Py - Qy) / (Px - Qx)
- Implicit
- n - unit vector(s) normal to
line
- For L(t) = P + t ( Q - P )
- 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. This requires the chosen normal to lie in the plane defined by
(R - O) and (P -
O).
- Checks (for homework)
- If R is on the line then
d( R ) = 0.
- If R is off the line
then d( R ) != 0.
Clip a Point against a Half-space.
Representation of a Half-space.
- Use the implicit representation of a line (P, n).
- P on the separating
plane
- n perpendicular to the
separating plane
- Let the direction of the normal vector point to the inside.
Calculate d = ( R - P ) \dot n
- If d > 0, inside.
- If d < 0, outside.
- If d = 0, on the line.
Clipping in 3D
Clip a Line Segment to a Half-space.
The line segment
- L(t) = R + t ( S - R ), 0 < t < 1.
- R is at one end of the line
segment
- S is at the other end
Test if each of R and S are inside. Calculate
- d(R) = ( R - P ) \dot n
- d(S) = ( S - P ) \dot n
There are three cases
- Both inside: keep the segment as is.
- Both outside: discard the segment.
- One inside, one outside: the segment crosses the boundary of the
half-space.
- Calculate the intersection
- ( L(t) - P ) \dot n = 0.
- t = { ( P - R ) \dot n } / { ( S - R ) \dot n }
- Optimize (??)
- t = { ( P - R ) \dot n } / { ( S - P ) \dot n - ( R - P )\dot. n }
- Replace one of the end points by L(t), (Which one?)
Clip a Line Segment to a Rectangular Parallellopiped
Straightforward, BUT what if the line segment crosses a corner?
Two Good Examination Questions
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.
- They do not preserve ratios of distance.
- They do not preserve affine combinations.
- They do not map vectors.
- They do preserve the cross ratio.
Show 1D transformation on the board
- Illustration in 2D. What does this mean? (Hint. homogeneous
coordinates)
- Projection point on one of the lines.
- Relevance of the intersection point of two lines.
- How the transformation changes as the projection point moves
around.
General projections from 1D to 1D
- Put the projection point anywhere
- on one of the lines.
- at infinity
- The general form of a projection
- Mobius transformation: x' = (a*x + b ) / ( c*x + d )
- Really is the general form
- A general point on one line is O + x*i, on the other line, O' +
x'*i'.
- A general point P is the projection point.
- It's a projection iff (O + x*i - P) \dot (O' + x' * i' - P) =
0. Why?
- Solve for x'
x' = (x * (i \dot (P - O') - (P - O) \ldot (P - O') ) / ( x *
(i \dot i') - (P - O) \dot i' )
- Compositions of Mobius transformation are Mobius
transformations
- The inverse of a Mobius transformation is a Mobius
transformation
- A Mobius transformation is the product of a translation, a
reflective inversion, a dilated rotation, and a translation.
- Matrix form of the Mobius transformation
/ \
| a b |
| c d |
\ /
The composition of Mobius transformations is the multiplication of
matrices (up to a multiplicative constant - Why?).
- What if P is on one of the lines?
- P = O' + y*i'
- Do a little algebra...
- x' = y'
- The matrix is singular.
- We can work out that it must be
/ \
| 0 y |
| 0 1 |
\ /
- Draw a picture.
This is actually a projection from 1D to 0D.
Projection from 2D to 1D
We can draw it in 2D (Why?)
- three components:
- plane, containing the stuff to be projected
- line, onto which the stuff will be projected
- point of projection
all must lie in the same plane
- projection point in/out of the plane
- line in out/of the plane
How is it done?
- Define a coordinate frame, the view coordinates,
- origin at the projection point
- z-axis perpendicular to the line
- x-axis parallel to the line
- Transform points in the plane into view coordinates
- (xw, zw, 1) -> (xv, zv, 1) using an affine transformation
- In the view coordinates, x' = z' * ( xv / zv )
- But xv = a * xw + b * zw + c, and zv = d * xw + e * zw + f
- Once again we have a Mobius transformation
Projection from 2D to 2D
We don't want to throw away z, so we'll do a 2D to 2D projection:
- view frustrum to cube centred on the origin
That is,
- Near plane goes to z' = -1.
- Far plane goes to z' = 1
- Top plane goes to x' = 1
- Bottom plane goes to x' = -1
Represent the Mobius transformation as a matrix
/ \
| a b c |
| d e f |
| g h i |
\ /
Then, using the code
- zn: z coordinate of the near plane
- zf: z coordinate of the far plane
- mu: slope of the upper limit of the frustrum
- md: slope of the lower limit of the frustrum
we can map the four planes.
- (x, zn, 1 ) -> (sx', -s, s )
- (x, zf, 1 ) -> (tx'', t, t )
- (mu*z, z, 1 ) -> (u, uz', u )
- (md*z, z, 1 ) -> (-v, vz'', v )
Each of these gives two ordinary linear equations. (Why?) Just the right
number. (Why?) Solve them.
The result is
/ \
| 1 (mu + md) / (mu - md) 0 |
| 0 (zf + fn) / (zf - zn) -2*zf*zn / (zf - zn) |
| 0 1 0 |
\ /
Exercise. Check that this matrix creates the correct Mobius
transformation.
Exercise. Compare this matrix to the one in the notes. It should be the
same with the y row and column deleted. Why is it different?
Exercise. Solve the equations.
Exercise. Show that our 2D to 2D projection, followed by orthogonal
projection is the same as the 2D to 1D projection just above.
Exercise. Extend these results to 3D, and compare to the matrices given in
the notes.
Properties of this Projection
z' -> (z*(zf + zn) -2*zf*zn ) / z*(zf - zn)
- z = zf
- z = zn
- What maps to zero? z' = 2*zf*zn / (zf + zn )
Note the possible numeric problems.
- z -> +0
- z -> -0
z -> infinity, z' = (zf + zn) / (zf - zn)
Return to: