程序代写代做 algorithm 1. (12 points)

1. (12 points)
a) Explain the main steps in Gouraud shading method and Phone shading method. (4 points)
solution: Gouraud shading:
Find average normal at each vertex (vertex normal); Apply modified Phong model at each vertex; Interpolate vertex shades across each polygon.
Phong shading:
Find vertex normal;
Interpolate vertex normal across edges; Interpolate edge normal across polygon;
Apply modified Phong model at each fragment.
b) Discuss the differences between these two methods, in terms of efficiency and quality. (4 points)
solution:
If the polygon mesh approximates surfaces with a high curvatures, Phong shading may look smooth while Gouraud shading may show edges;
Phong shading requires much more work than Gouraud shading.
c) Explain why highlight is often missing in displays rendered with Gourand shading method. (4 points)
solution:
In the Gouraud shading, there are areas that the camera cannot see or the light cannot arrive. The modified Phong model is applied at each vertex, and the interpolate vertex shades across each polygon. The entire lighting calculation is performed for each pixel, based on the interpolated normal. Comparing with the Phong shading, the highlight is often missing in displays rendered with Gourand shading method.
2. (10 points)
Suppose we have a sphere centered at the origin, x2 + y2 + z2= r2. There is a light source at (a,b,c). Generate a formula for finding the color at any point (x,y,z) on the surface of the sphere, assuming that the Phong illumination model is applied. Define any additional terms you introduce.
Solution:
The Phong illumination model = ambient + diffuse reflection + specular reflection.
𝐼 = 𝑘𝑎𝐼𝑎 + 𝑘𝑑(𝑁 ∙ 𝐿)𝐼𝐿 + 𝑘𝑠(𝑁 ∙ 𝐻)𝑛𝐼𝐿

𝑘𝑎: The material reflection coefficient; 𝐼𝑎: the ambient light intensity
𝑘𝑑: The diffuse reflection coefficient N: Surface normal
cos θ = N · L if vectors normalized 𝐼𝐿: The incoming light light intensity
𝑘𝑠: The absorption coefficient
𝐻 : is the normal to the (imaginary) surface that maximaly reflects light in the V
direction, 𝐿+𝑉. 2
n: shininess coefficient
There are also three coefficients, 𝑘𝑎𝑟 , 𝑘𝑎𝑔 , 𝑘𝑎𝑏 , 𝑘𝑑𝑟 , 𝑘𝑑𝑔 , 𝑘𝑑𝑏 , 𝑘𝑠𝑟 , 𝑘𝑠𝑔 , 𝑘𝑠𝑏 that show how much of each color component is reflected
Normal given by gradient vector.
𝜕𝑓 𝜕𝑓 𝜕𝑓𝑇 2𝑥 2𝑦 2𝑧𝑇 𝑁=[𝜕𝑥 𝜕𝑦 𝜕𝑧] =[𝑟2 𝑟2 𝑟2]
𝑁 = [𝑥 𝑦 𝑧 ]𝑇. 𝑟2 𝑟2 𝑟2
L = [a-x, b-y, c-z].
3. (8 points)
Can we interpolate texture coordinates linearly in screen space? Draw a figure to explain.
Solution:
No.
In particular, equal distances along a line in eye space do not map to equal distances in screen space.
Linear interpolation in screen space is not equal to linear interpolation in eye space.

On the left is the eye space, and the line PQR is in the screen space. The interpolate of the PQR is different with the view plane.
4. (6 points)
Can we interpolate z linearly in screen space? Explain.
Solution: No.
𝑧′ =𝑧(𝑓𝑎𝑟+𝑛𝑒𝑎𝑟)+2∙𝑓𝑎𝑟∙𝑛𝑒𝑎𝑟 𝑧 ∙ (𝑓𝑎𝑟 − 𝑛𝑒𝑎𝑟)
This mapping is non‐linear: uniform differences in 3D (z) depth values do not correspond to uniform differences in z’ values
The number of discernable depths is greater near the near plane than the far plane
Common mistake: set near = 0, far = infty. Don’t do this. Can’t set near = 0; lose depth resolution.
Tip: Choose the near plane as far away as possible.
5. (13 points)
a) Please write the implicit equation for a double-cone of angle θ centered on the origin and oriented along the z direction. (3 points)

Solution:
𝜃2 𝜃2 (𝑥2+𝑦2)(cos2) −𝑧2(sin2) =0
b) Give the parametric equation of a ray with origin O and direction d. (2 points) solution:
p(t) = O + t*d
where t is the coefficient.
c) Give the equation for the parameter t at the ray-cone intersection. Solve for t. Do you always find a solution? Why or why not? (5 points)
solution:
𝑓(𝑡)= ((𝑂 +𝑡𝑑 )2+ (𝑂 +𝑡𝑑 )2)(cos𝜃)2− (𝑂 +𝑡𝑑 )2(sin𝜃)2.
𝑥𝑥𝑦𝑦2𝑧𝑧2
When the origin O is (0,0,0):
Because the ray is with origin O and the double-cone is also with origin O, there is at least one intersection point, origin O. If the direction d is tangent with the double- cone, there will be infinite intersection points. Hence, there is always find a solution.
When the origin O of the ray is any other point:

When the origin O is inside the double-cone, there is always solution. 1: d is parallel with z-axis;
2: d is any other direction.
When the origin O is outside the double-cone, there is always solution.
d) How do you need to change the equation or the code to handle half-infinite cones (only the half in the positive z half space)? (3 points)
solution:
z is in the positive half space
𝑧= 𝑥2+𝑦2
√𝜃2 (tan2)
6. (10 points)
(a) Derive the 4×4 homogenous matrix representation of a rotation transformation in
3D space of 30 degree about the directed line through the origin with direction vector (0, 1, 1).
Solution:
𝑘 = [0
1 1 ],𝑐 = cos30° = √3,𝑠 = sin30° = 1. √2√2 2 2
𝑐 𝑘𝑧𝑠 −𝑘𝑦𝑠 0
−𝑘 𝑠 𝑘2(1−𝑐)+𝑐 𝑘 𝑘 (1−𝑐) 0 𝑅=𝑧𝑦𝑦𝑧
𝑘 𝑠 𝑘 𝑘 (1−𝑐) 𝑘2(1−𝑐)+𝑐 0 𝑦𝑦𝑧𝑧
[0 0 0 1]

√3 √2 −√2 0 244
= −√2 1+√3 1−√3 0 42424
√2 1−√3 1+√3 0
[42424] 0001
(b) What is the image of point (0, 3, 3) under the transformation in (a)? Solution:
7.
(1)
√3 √2 −√2 0
024400
𝑝=𝑅[√3]= −√2 1+√3 1−√3 0 [√3]= [√3] √3 4 2 4 2 4 √3 √3
1 √2 1−√3 1+√3 0 1 1
[42424] 0001
(10 points)
The following shows a texture image. Suppose the texture coordinate for the vertexs of a polygon are (0,0), (3,0), (3,3), (0,3) respectively, draw diagram if
(5 points) Clamping in s direction (horizontal) and repeating in t (vertical) direction.

(2) (5 points) Clamping in s direction and clamping in t direction.
8. The following shows a perspective projection where the eye is at the origin, the viewing direction is the opposite of the z-axis, and the projection plane is z= -1.
(1) (3 marks) A point at (x,y,z) in the viewing frustum is projected on (x’,y’,z’). Give the formula to form x’, y’, z’.
Solution:
x’= -d*x/z = -x/z y’= -d*y/z = -y/z z’= -d = -1

(2) (3 marks) Give the 4*4 matrix that represents the projection.
1000 [0 1 0 0] 0010 0 0 −1 0
(3) (3 marks) Does this projection support the depth-buffer algorithm for hidden surface removal? Explain why.
No.
In OpenGL the projection transformation place the viewing frustrum is mapped to a cube that extends from -1 to 1 in x, y, and z. And 4D homogenous coordinates to retain 3D information for hidden surface removal and shading. In this projection, the z is same (-1), which does not support the depth-buffer algorithm.
(4) (5 marks) Give a transformation matrix that computes the same x’ and y’ but different z’ such that the depth-buffer algorithm is facilitated.
1000
[0 1 0 0], where a = -𝑛𝑒𝑎𝑟+𝑓𝑎𝑟 , 𝑏 = − 2𝑓𝑎𝑟∗𝑛𝑒𝑎𝑟.
0 0 𝑎 𝑏 𝑛𝑒𝑎𝑟−𝑓𝑎𝑟 𝑛𝑒𝑎𝑟−𝑓𝑎𝑟 0 0 −1 0
9. (5 marks) It is possible for a single segment Bezier curve to intersect itself. Give four control points with all coordinates between 0 and 1 that yield a self- intersecting Bezier curve.
Solution:
Self-intersecting Bezier curve.
Bezier curve must pass through the beginning and ending points.
𝐹(𝑡)= (1−𝑡)3𝑝1 +3𝑡(1−𝑡)2𝑝2 + 3𝑡2(1−𝑡)𝑝3 +𝑡3𝑝4 0 ≤ 𝑡 ≤ 1.
10. (12 marks) Verify the C2 continuity of the cubic spline at the join points.

Solution:
𝑄′′(𝑡) = (1 − 𝑡)𝑝0 + (3𝑡 − 2)𝑝1 + (−3𝑡 + 1)𝑝2 + 𝑡𝑝3. The first segment cubic spline is formed by [𝑝0, 𝑝1, 𝑝2, 𝑝3]
𝑄′′(1)=𝑝 −2𝑝 +𝑝. 1123
The second segment cubic spline is formed by [𝑝1,𝑝2,𝑝3,𝑝4] 𝑄′′(0) = 𝑝 − 2𝑝 + 𝑝 .
(1−𝑡)3 3𝑡3 −6𝑡2 +4 −3𝑡3 +3𝑡2 +3𝑡+1 𝑡3 𝑄(𝑡)= 6 𝑝0+ 6 𝑝1+ 6 𝑝2+ 6𝑝3.
2123
So, the 𝑄′′(1) = 𝑄′′(0) means the cubic spline is C2 continuity at the join points. 12