CS 4390
Computer Graphics

Fall 1998
College of Computing 201
MWF 11:00-12:00


Homework Solutions

Here's a pointer back to the homework.

3D Transforms

  1. A triangle is defined by the following vertices:

    (A) Find the outward pointing unit normal of this triangle.

    Find edge vectors:

    q = (v2-v1) = [0 -2 0 0]T
    r = (v3-v1) = [-2 -3 -2 0]T.

    The outward pointing normal is (q x r) = [4 0 -4 0]T.
    The outward pointing unit normal is then [.707 0 -.707 0]T.

    (B) Find the angle between vectors q=(v2-v1) and r=(v3-v1).

    Use (q . r) = ||q|| ||r|| cos(theta)
    theta = 0.76 radians

    (C) Derive the equation for the plane defined by this triangle.

    We know that the normal is in the direction [1 0 -1 0]T
    This implies that:

    x - z + D = 0

    Point v1 is in the plane. Substituting v1 into the above equation, we get:

    1 - 1 + D = 0, or
    D = 0

    The plane equation is then:

    x - z = 0

  2. Given the plane 3x+y-7z+2=0

    (A)Find the projection Q of point P=[1 2 3 1]T onto this plane.

    Choose an arbitrary point A in the plane:

    A = [0 -2 0 1]T
    (P-A) = [1 4 3 0]T

    From the plane equation, the plane normal is [3 1 -7 0]T

    Normalizing, the unit normal nHat is [0.391 0.130 -0.911 0]T

    Find Q by subtracting from P the normal component of (P-A):

    Q = P - [(P-A) . nHat] nHat

    Q = P - [-1.822] nHat

    Q = [1 2 3 1]T - [-.712 -.237 1.660 0]T

    Q = [1.71 2.24 1.34 1]T

    (B)Use the plane equation to check that Q is on the plane.

    Check: 3(1.71) + (2.24) - 7(1.34) + 2 = 0
    OK

    (C)Check that vector P-Q is in the direction of the plane normal.

    P - Q = [-0.71 -0.24 1.66]T

    This is just nHat scaled by -1.82.

  3. You are placing furniture in a 20' by 20' room. The coordinate system for the room is fixed in the SE corner, on the floor. The x-axis runs in the N direction, and the y-axis runs in the W direction. The z-axis is up. A couch and a door, with local coordinate frames shown, are to be placed in the room.
    (A) Find the transform to place the sofa in the center of the N wall.

    Rotate the sofa to its final orientation, and then translate it to the center of the N wall. This gives the following equation to transform any point P on the couch to the desired position:

    P' = T(20, 13, 0) Rz(PI) P

    (B) Find the transforms to place double doors in the center of the E wall. Place the doors so that they are opening inward at a 30 degree angle.

    DOOR 1: Make this the North door. Rotate 150 degrees about z to put into the final orientation, then translate up the East wall:

    P' = T(14, 0, 0) Rz(150degrees) P

    DOOR 2: This is the South door. Rotate 30 degrees about z to put into the final orientation, then translate up the East wall:

    P' = T(6, 0, 0) Rz(30degrees) P

  4. In class, we identified the SHxy(shx,shy) matrix, which shears by shx in the x direction and by shy in the y direction, proportional to the z coordinate. Derive the corresponding matrices SHyz(shy,shz) and SHxz(shx,shz).

    For SHyz (shy, shz)

    This matrix shears in the y and z directions proportional to the x component:

    y' = y + shy x
    z' = z + shz x

    For SHxz (shx, shz)

    This matrix shears in the x and z directions proportional to the y component:

    x' = x + shx y
    z' = z + shz y

  5. Given a unit cube with one corner at [0 0 0 1]T and the opposite corner at [1 1 1 1]T, derive the transformations necessary to rotate the cube by theta about the main diagonal (from [0 0 0 1]T to [1 1 1 1]T) in the counterclockwise direction when looking along the diagonal toward the origin. You might want to find a physical cube to help visualize this transformation. Test your transform by checking the rotation of point [1 0 0 1]T about the diagonal by angle 2pi/3.

    Basic strategy: rotate onto a main axis, rotate about that axis by theta, then undo the rotation onto the main axis. In this case, we begin by rotating the diagonal onto the x-axis.

    P' =

    Rz(PI/4)
    Ry(-tan-1(1/sqrt(2)))
    Rx(theta)
    Ry(tan-1(1/sqrt(2)))
    Rz(-PI/4)
    P

    Test the transform for P = [1 0 0 1]T, theta = 2PI/3:

    P = [1 0 0 1]T
    Q = Rz(-PI/4) P = [.707 -.707 0 1]T
    U = Ry(tan-1(1/sqrt(2))) Q = [.577 -.707 -.408 1]T
    V = Rx(2PI/3) U = [.577 .707 -.408 1]T
    W = Ry(-tan-1(1/sqrt(2))) V = [.707 .707 0 1]T
    P' = Rz(PI/4) W = [0 1 0 1]T

Projection

  1. You are standing in the center of a 20'x20'x10' room looking out a large 6'x6' window centered on the North wall. Your eye level is at a height of 6'. Your view is blocked by a skyscraper 100' outside the window. The world coordinate system (WC) is anchored at the SE corner of the room. The WC x-axis points to the North, and the WC y-axis points to the West.

    (A)Find the view volume parameters for the portion of 3D space that you can see that falls outside the window. Use the proper coordinate frame (WC or VRC) for each parameter.

    VRP: choose a point on the North wall

    [20' 0 0 1']T

    VPN: choose vector perpendicular to the North wall, pointing toward the viewer

    [-1 0 0 0]T

    VUP: z is up

    [0 0 1 0]T

    Window: umin, umax, vmin, and vmax are defined by the positions of the corners of the real window in the VRC coordinate system

    -13', -7', 2', 8'

    PRP: the position of the viewer's eye in VRC coordinates

    [-10' 6' 10' 1]T

    Front clip plane: 0

    Back clip plane: -100'

    (B) You move to the SE corner of the room. Which parameters change? (You still can't see past that skyscraper.)

    Only PRP changes, to [0' 6' 20' 1]T

  2. The animation lab uses a standard "quarter shot" to present basic demonstrations of motion. The image below is one example. Assume that the runner is 6' tall. The world coordinate system is anchored on the ground below the runner center of mass, with:
    x-axis in the direction of motion,
    y-axis in the direction to the runner's left,
    z-axis up.

    Estimate a set of view volume parameters to obtain this shot. Explain your choices.

    VRP: choose a view plane passing through the runner

    [0 0 0 1']T

    VPN: choose a vector pointing toward the viewer. The x component has a greater magnitude than the y component because we see more of the front of the runner than of his right side.

    [1 -0.5 0 0]T

    VUP: z is up

    [0 0 1 0]T

    Window: choose umin, umax, vmin, and vmax to give a little space above and below the runner. Make umax slightly larger than -umin to allow the runner "room to move." (This helps avoid the perception that the runner is trying to escape from the image.)

    -3', 4', -1', 7'

    PRP: pull the camera back from the runner, moving it in the VPN direction. This is a low shot, with the height of the camera near the runner center of mass.

    [4' -2' 3' 1]T

    Front clip plane: 0

    Back clip plane: -100' This is not very important here, although the brick wall needs to be in the image.


Projection and Clipping

  1. You are given a line segment with endpoints:
    A = [1 1 1 1]T
    B = [-1 -0.5 -2 1]T

    Trace through the Cohen-Sutherland clipping algorithm for a 3D perspective projection canonical view volume. Find the endpoints of the clipped line segment using the parametric line equation.

We are not given a zmin value for the front clipping plane, so assume it is 0.

  1. Determine codes for points A and B using the table in the text:
    A = 101001 (y > -z, x > -z, z > zmin)
    B = 000010 (z < -1)

  2. Test (A AND B) = 000000. The line segment cannot be trivially rejected.

  3. Compute the parmetric expressions for x, y, and z on the line AB. Do this by substituting actual values for the x, y, and z components of A and B into the expression P = A + t(B - A):
    x = 1 + t(-1 - 1) = 1 - 2t
    y = 1 + t(-0.5 - 1) = 1 - 1.5t
    z = 1 + t(-2 - 1) = 1 - 3t

  4. Consider A. Checking the high order 1 bit, we clip at (y = -z). First, find parameter t using the expressions above with the constraint that y = -z.
    1 - 1.5t = -(1 - 3t)
    t = 4/9

    Plug this result into the parametric expressions for x, y, and z to find A':

    x' = 1 - 2(4/9) = 1/9
    y' = 1 - 1.5(4/9) = 1/3
    z' = 1 - 3(4/9) = -1/3
    A' = [x' y' z' 1]T = [1/9 1/3 -1/3 1]T

  5. Compute outcode for A' = 000000.

  6. Test (A' AND B) = 000000. The line segment cannot be trivially rejected.

  7. Consider B. Considering the only 1 bit, we clip at z = -1. First, find parameter t using the expressions above with the constraint that z = -1.
    1 - 3t = -1
    t = 2/3

    Plug this result into the parametric expressions for x, y, and z to find B':

    x' = 1 - 2(2/3) = -1/3
    y' = 1 - 1.5(2/3) = 0
    z' = 1 - 3(2/3) = -1
    B' = [x' y' z' 1]T = [-1/3 0 -1 1]T

  8. Compute outcode for B' = 000000.

  9. Both A' and B' are 000000, so accept line segment A'B'

Visible Surface Algorithms

  1. You are given a triangle with endpoints:
    P1 = [1 1 1 1]T
    P2 = [0 2 1 1]T
    P3 = [0 0 1 1]T

    (A)The viewpoint is at the origin. Trace the steps required to determine whether this is a front-facing or back-facing polygon. Assume that the vertices appear to be numbered in counterclockwise order when the front-facing surface is visible.

    If the vertices are listed in counterclockwise order, then the outward pointing normal is in the following direction:

    n = (P2 - P1) X (P3 - P1) = [0 0 2 1]T

    Now we need to test whether this normal is pointing toward the viewer. If so, it is front facing.

    First, we construct a vector pointing from the triangle to the viewer. Let the origin be point O = [0 0 0 1]T. Then vector (O - P1) = [1 1 1 1]T points from the triangle toward the viewer.

    Next, we test whether n is in the direction of (O - P1).

    n . (O - P1) = -2

    Because this is a negative number, n is not in the direction of (O - P1). It points away from the viewer, and so this is a back-facing polygon.

    (B)How does your answer change if the viewpoint is at point V instead of at the origin:

    V = [1 3 2 1]T

    In this case, the vector from the triangle to the viewer changes. Here, we can use (V - P1) = [0 2 1 1]T. We test whether n is in the direction of (V - P1).

    n . (V - P1) = 2

    Because this is a positive number, n now points toward the viewer, and this is a front-facing polygon for the new viewpoint V.

  2. You have three polygons to scan convert onto a 4 x 4 pixel display. Depth and color information for each of the polygons is shown below. Trace the contents of the frame buffer and z-buffer as the z-buffer algorithm is used to scan convert these polygons. The background color is black (K). The minimum depth value is -7.

    Step 1: Initialize the frame buffer and z-buffer.

    Step 2: Scan convert the red polygon.

    Step 3: Scan convert the blue polygon.

    Step 4: Scan convert the green polygon.