Game Mathematics

Week 7 Official Solutions

1.

a. [Graphics:Images/solutions_gr_1.gif]

b. [Graphics:Images/solutions_gr_2.gif]

c. 20

d. [Graphics:Images/solutions_gr_3.gif]

2.

First, we translate the player to the origin by subtracting p. The location of the test point relative to the new origin then becomes [Graphics:Images/solutions_gr_4.gif], where [Graphics:Images/solutions_gr_5.gif] is the location of the test point in the old coordinate system. Now we compute the dot product between the translated test point and the direction the player is facing, like so,

[Graphics:Images/solutions_gr_6.gif]

where [Graphics:Images/solutions_gr_7.gif] is the angle between the vectors. Solving for [Graphics:Images/solutions_gr_8.gif], we find,

[Graphics:Images/solutions_gr_9.gif]

We want a function [Graphics:Images/solutions_gr_10.gif] such that [Graphics:Images/solutions_gr_11.gif] for test points within the view cone, and [Graphics:Images/solutions_gr_12.gif] for points outside the cone. Such a function is shown below:

[Graphics:Images/solutions_gr_13.gif]

A figure graphically illustrating the behavior of this function is shown below.

[Graphics:Images/solutions_gr_14.gif]

The viewer is situated at the origin, looking down the positive y-axis. The slanted lines represent the boundaries of what the viewer can see. The line [Graphics:Images/solutions_gr_15.gif] represents all the test points sent to the function [Graphics:Images/solutions_gr_16.gif]. Lastly, the remaining graph represents the function [Graphics:Images/solutions_gr_17.gif], for all [Graphics:Images/solutions_gr_18.gif] on the line [Graphics:Images/solutions_gr_19.gif].

As you can see, the function dips below 0 for [Graphics:Images/solutions_gr_20.gif] outside the view cone.

3.

Let the line be defined by the set of equations,

[Graphics:Images/solutions_gr_21.gif]
[Graphics:Images/solutions_gr_22.gif]
[Graphics:Images/solutions_gr_23.gif]

and the plane, by the equation,

[Graphics:Images/solutions_gr_24.gif]

The intersection point [Graphics:Images/solutions_gr_25.gif] satisfies all equations. So we have,

[Graphics:Images/solutions_gr_26.gif]
[Graphics:Images/solutions_gr_27.gif]
[Graphics:Images/solutions_gr_28.gif]

[Graphics:Images/solutions_gr_29.gif]

Substituting the parametric equations into the plane equation, we find,

[Graphics:Images/solutions_gr_30.gif]

Expanding and collecting like terms, we get,

[Graphics:Images/solutions_gr_31.gif]

Solving for t, we find,

[Graphics:Images/solutions_gr_32.gif]

This value of t can be substituted into the parametric equations to yield the intersection point.

If the denominator of the above equation is zero, the line does not intersect the plane.

4.

For an n-sided obstructing polygon, there are n rays we cast out from the viewer and through the polygon's vertices. Let these rays be designated [Graphics:Images/solutions_gr_33.gif], where p is the location of the viewer, and [Graphics:Images/solutions_gr_34.gif] are the vertices of the polygon.

The first step is to form a series of planes that enclose the volume defined by the rays. This can be done by computing the cross products [Graphics:Images/solutions_gr_35.gif], which define the normals of the planes, and by using the fact that the planes all pass through the point p (since all of the rays do). This leads to a series of [Graphics:Images/solutions_gr_36.gif] plane equations that together define the volume enclosed by the rays.

The second step is to check to see if all points that comprise the test polygon fall on the "inner" side of all the planes (using the general form of the plane equation). If they do, then the polygon is obscured (assuming it is, in fact, behind the "obstructing" polygon), but otherwise it is visible.

5.

The area of the triangle is just half the magnitude of the cross product of u and v (two of the triangles form a parallelogram, whose area is equal to the magnitude of the cross product).

6.

The distance is the magnitude of the vector projection of [Graphics:Images/solutions_gr_37.gif] onto [Graphics:Images/solutions_gr_38.gif], where [Graphics:Images/solutions_gr_39.gif] is the point, [Graphics:Images/solutions_gr_40.gif] is a point on the line, and [Graphics:Images/solutions_gr_41.gif] is a vector perpendicular to the line. For a 2D line, [Graphics:Images/solutions_gr_42.gif] is most easily calculated by a [Graphics:Images/solutions_gr_43.gif] rotation of the line's direction vector.

7.

The angle between the light source and the normal is given by the following equation,

[Graphics:Images/solutions_gr_44.gif]

The polynomial from Week 3 assumed the angle is measured off the polygon, not the normal. So we define a new angle [Graphics:Images/solutions_gr_45.gif], and send this angle to the polynomial.

8.

Let the locations of the m vertices defining the mesh at discrete time interval n be denoted by [Graphics:Images/solutions_gr_46.gif]. Further, let the function [Graphics:Images/solutions_gr_47.gif] (a linear interpolator between [Graphics:Images/solutions_gr_48.gif] and [Graphics:Images/solutions_gr_49.gif], with [Graphics:Images/solutions_gr_50.gif] corresponding to [Graphics:Images/solutions_gr_51.gif], and [Graphics:Images/solutions_gr_52.gif] corresponding to [Graphics:Images/solutions_gr_53.gif]). Then the location of the ith vertex at time [Graphics:Images/solutions_gr_54.gif], where n [Graphics:Images/solutions_gr_55.gif], is given by the following equation:

[Graphics:Images/solutions_gr_56.gif]

Note there are many other ways to express the solution to this problem. All solutions, however, use a linear interpolator function in the same form as [Graphics:Images/solutions_gr_57.gif].

9.

Consider the coordinate components of a given vertex separately (x, y, and z). We must force each component to pass through 3 values. Consequently, we will need 3 quadratics -- one for each coordinate component.

The general form of a quadratic function is [Graphics:Images/solutions_gr_58.gif] (here written a function of time, since the position of the vertices depends on time). Let the constraints be given by [Graphics:Images/solutions_gr_59.gif], [Graphics:Images/solutions_gr_60.gif], and [Graphics:Images/solutions_gr_61.gif], where [Graphics:Images/solutions_gr_62.gif] denote the locations the given component must pass through at times [Graphics:Images/solutions_gr_63.gif], [Graphics:Images/solutions_gr_64.gif], and [Graphics:Images/solutions_gr_65.gif], respectively. Then we have the following system of equations:

[Graphics:Images/solutions_gr_66.gif]

Solving for the unknowns, a, b, and c, we find,

[Graphics:Images/solutions_gr_67.gif]

So our function [Graphics:Images/solutions_gr_68.gif] becomes,

[Graphics:Images/solutions_gr_69.gif]

For convenience, we can turn the function into a function not only of t, but also of [Graphics:Images/solutions_gr_70.gif], [Graphics:Images/solutions_gr_71.gif], and [Graphics:Images/solutions_gr_72.gif], giving us,

[Graphics:Images/solutions_gr_73.gif]

Using this function, we can now define a quadratic interpolator [Graphics:Images/solutions_gr_74.gif], as follows:

[Graphics:Images/solutions_gr_75.gif]

The position of the ith vertex at time t, where [Graphics:Images/solutions_gr_76.gif], can now be written as follows:

[Graphics:Images/solutions_gr_77.gif]

The following figure illustrates the smoothness of quadratic interpolation.

[Graphics:Images/solutions_gr_78.gif]


Converted by Mathematica      December 4, 2001