+ All Categories
Home > Documents > 3eChap5 Exercise Solutions

3eChap5 Exercise Solutions

Date post: 07-Apr-2015
Category:
Upload: lmelhem
View: 562 times
Download: 0 times
Share this document with a friend
19
Computer Graphics Using OpenGL - Hill/Kelley 3 rd Edition Chapter 5 – Solutions to Selected Practice Exercises Solutions to Selected exercises for Chapter 5 (preliminary version) 5.2.2. Solution : Sketch the effect. (Q x , Q y ) = (S x P x , S y P y ) S x = 3, S y = -2 a). The circle scales into an ellipse 3 times as wide and twice as high; b). The square scales to a rectangle 3 times as wide and twice as high, as well as being upside down; The points of the square scale as shown: (1,1), (1, 2), (2, 2), (2,1) → (3, -2), (3, -4), (6, -4), (6, -2) 5.2.4. Solution : Shearing Lines. Use Q x = P x , Q y = gP x + P y Page 1 of 19 file: document.doc
Transcript
Page 1: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

Chapter 5 – Solutions to Selected Practice Exercises

Solutions to Selected exercises for Chapter 5 (preliminary version)

5.2.2. Solution: Sketch the effect.

(Qx, Qy) = (SxPx, SyPy) Sx = 3, Sy = -2

a). The circle scales into an ellipse 3 times as wide and twice as high;b). The square scales to a rectangle 3 times as wide and twice as high, as well as being upside down; The points of the square scale as shown:(1,1), (1, 2), (2, 2), (2,1) → (3, -2), (3, -4), (6, -4), (6, -2)

5.2.4. Solution: Shearing Lines.

Use Qx= Px, Qy = gPx + Py

Each line is transformed into another straight line (this will be proved in general subsequently), with transformed endpoints:

a) (-3, 2.8), (2, 4.8)b) (-3, -5.2), (2, -3.2)c) (-2, 4.2), (-2, -1.8)d) (-1, -2.4), (3, 3.2)

The given figures in F5.12 shear into the figures with new points:a) (-1,0), (0,1), (1,0), (0, -1) → (-1, 0), (0, 1), (1, 0.4), (0, -1)b) (0,0), (0,1), (1,1), (1, 0) → (0, 0), (0, 1), (1, 1.4), (1, 0.4)c) (1,1), (1, 2), (2, 2), (2,1) → (1, 1.4), (1, 2.4), (2, 2.8), (2, 1.8)

Page 1 of 14 file: document.doc

Page 2: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

5.2.5. Solution: To invert a Shear.

By the equation 5.11 and 5.12:

M = /(1-gh). This is a shear only if gh = 0

5.2.7. Solution: An Inverse Matrix.By direct calculation ( see Appendix 2 for methods and details:M =

M =

5.2.8. Solution: Fixed Points of an Affine Transformation.

a) when the third column of M is (0,0,1), M=

M (0, 0, 1)T = (0, 0, 1) T = (0, 0, 1) T

Origin is a fixed pointb) T(P) = T(P-F+F) = T(P-F)+T(F) = M(P - F)+ F.c) Point V is the fixed point for a rotation about point V.

MV= (Vx, Vy, 1)T

=( )

Since

MV= ( ) =Point V is the fixed point for a rotation about point V.e) Point V is the fixed point for a scaling with scale factors Sx and Sy, about V.f) T(T(P)) = T(M(P - F)+ F) = M2(P - F)+ FT(T(T(P))) = T(M2(P - F)+ F) = T(M2(P - F))+ T(F)= M3(P - F)+ F

Page 2 of 14 file: document.doc

Page 3: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

T(T(T(T(P)))) = T(M3(P - F)+ F) = T(M3(P - F))+ T(F)= M4(P - F)+ FT(T(T(T(T(P))))) = T(M4(P - F)+ F) = T(M4(P - F))+ T(F)= M5(P - F)+ F

5.2.9. Solution: To Find Matrices.

a)

.

b)

100

33Sy-Sy0

22S-0S

100

110

101 xx

c) =

5.2.10. Solution: To Normalize a Box.

The given box is a rectangle, with its lower edge tiled at angle = 301. rotate through -302. scale by (1/w, 1/2w), where w =

M = =

5.2.11. Solutions: Some Transformations Commute.Do this by direct multiplying out SR and RS

SR = =

Page 3 of 14 file: document.doc

Page 4: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

RS = =

For uniform scaling, = , SR = RS. So the uniform scaling commutes with rotation. The differential scaling does not commute with rotation.

5.2.12. Solutions: Reflection plus a rotation.Reflection:1. reflection in x2. reflection in y

M1 = =

Rotate 180

M2 = =

M1 = M2

So a reflection in x followed by a reflection in y is the same as a rotation by 1800.

5.2.13. Solution: Two Successive Rotations.Rotation1. rotation through angle 1, R(1)

2. rotation through angle 2, R(2)

=

=

= R (1 + 2)

Page 4 of 14 file: document.doc

Page 5: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

R(1) followed by R() is equivalent to applying the single rotation R(1 + ). Thus successive rotations are additive.

5.2.14. Solutions: A Succession of Shears

=

Which is a shear if gh = 0.

5.2.24 Solution: The argument generalized.W = a1 P1 + a2 P2 + … + aN PN where a1 + a2 + … + aN = 1T(W) = T(a1 P1 + a2 P2 + … + aN PN) = a1 T(P1) + a2 T(P2) + … + aN T(PN)

5.2.25. Solutions: Show that relative ratios are preserved.

P = A + bt where b = B - A.So P = A + bt = A + (B – A)t = (1 - t) A + t B|P - A| = | t B – t A| = t |B – A||P - B| = | (1– t) A +(t -1) B | = |(1 - t) (B – A)| = (1 - t) |A – B| = (1 - t) |B – A|This is true if t lies outside of the range 0 to 1 because t + (1 – t) = 1. T(P) = (1 - t) T(A) + t T(B)|T(P) - T(A)| = | - t T(A) + t T(B)| = t | T(B) – T(A)||T(P) - T(B)|.= (1 - t) | T(B) – T(A)|

Exercise 5.3.1.Solution. Yes, by direct visualization, 90o rotations about each axis rotate each axis into another To visualize the 90° .Rotating a point on the x – axis about the x – axis has no effect for the point. Rotations

For example as x – roll, there is c = cos90 = 0, s = sin90 =1, we have

Q =

Also we can get the familiar results for y – roll and z – roll. So a 90 rotation about each axis rotates the other axes into one another.

Page 5 of 14 file: document.doc

Page 6: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

Exercise 5.3.2. To Rotate the Basic Barn.Sketching not done here.

5.3.3. Solution: Do a Rotation, a –roll of 45 degrees.

Q = , where c = s = 0.707, based on a

rotation by 45 degrees.This is reasonable since the y-coord Is not affected, due to the placement of zeroes in the matrix.

5.3.4. Solution: Test 90° Rotations of the Axes.

cos90 = 0, sin90 =1For x – roll,

= =

= =

i i ; j k ; k -j

for y-roll,

= = =

i -k ; j j ; k i

for z-roll,

= = =

i k ; j -i ; k k

5.3.5. Solution: Is a y-roll indeed different?

Q = = (x, cy-sz, sy + cz)

Q = x, Q = cy – sz, Q = sy + cz , P = x, P = y, P = zAlso Q = (cx + sz, y, cz – sx) Q = y, Q = c z – sx, Q = sz + cx , P = y, P = z, P = xQ = (cx - sy, sx + cy, z)

Page 6 of 14 file: document.doc

Page 7: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

Q = z, Q = c x – sy, Q = sx + cy , P = z, P = x, P = y

5.3.6. Solution: Which ones commute?

a) pure translations : T T = T T : yes, commute.b) both are scaling :

T T = = commute. T T

c) shear:

T T =

=

T T =

=

They commute if fk = 0.

d) A rotation and a translationfor example x – roll

T T = =

Page 7 of 14 file: document.doc

Page 8: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

T T = =

T T is not the same as T T . Familiar with x-roll, we can get the same result by y – roll and z – roll.

e) A rotation and a scalingfor example x – roll

T T = =

T T =

T T is not the same as T T .

f) a scaling and a shear, for example in x-axes shear

T T = =

Page 8 of 14 file: document.doc

Page 9: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

T T =

T T is not the same as T T .

5.3.7. Solution: Special cases of rotation about a general axis u.

Using Equation 5.33a) X- axis, i

R () =

It’s the same as x – roll.We also can get the familiar results of y – axis, j ; z – axis , k.

5.3.8. Solution: Classic Approach to Rotation about an Axis.It’s Equation 5.32.Ru() = Rz( -) Ry( -) Rz() Ry() Rz() =

Where = 30 cos = 0.866, sin = 0.5; = 45 cos = 0.707, sin = 0.707; = 35 cos = 0.819, sin = 0.5735So we can get the final result is:

5.3.9. Solution: Orthogonal Matrices.

By direct calculation each of the three rotation matrices has orthogonal columns (and rows), each of length 1. The determinant of an orthogonal matrix is 1. Partition orthogonal matrix M into its columns:

M = (c1| c2 | c3), so M = . Now note that M M = I, the identity matrix,

due to the properties of the columns. So M = M .

Page 9 of 14 file: document.doc

Page 10: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

5.3.10. Show that the Matrix of Equation 5.33 Is Orthogonal.

Based on the hint that accompanies this problem we need only show that the product of two orthogonal matrices is orthogonal. Suppose A and B are orthogonal, and set C = A * B. Now examine C-1.

We must show C-1 is the same as CT. But for any matrix C the inverse can be written as the reversed product of its individual inverses, so C-1 = B-1 * A-1, and since these guys are orthogonal, we have C-1 = BT * AT. Now since the transpose of a product can be written as the product of transposes (but reverse their order), C-1 = (A*B)T, so yes indeed, C-1is CT!

5.3.11. Solution: Structure of a rotation matrix.

Use Equation 5.33, where c is cos, s is sina) The first row the second row is:[c + (1-c)u ]i[(1– c)u u + su ]i + [(1– c)u u - su ]k [c + (1-c)u ]k

+ [(1– c)u u + su ]j [(1– c)u u - su ]j

= 2c(1-c)u u + (1- c) u u + (1- c) u u + (1-c)u u u -s u u

= (1- c) u u ( -1 + u + u + u )= 0They are orthogonal.Also there are the first the third = 0; the second the third = 0b) Use Equation 4.28First Second = Third

5.3.12. Solution: What if the axis of rotation does not pass through the origin?1. translate to the origin through –S2. apply the rotation3. translate back through S

Page 10 of 14 file: document.doc

Page 11: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

=

5.4.1. Solution: How transforming a coordinate system relates to transforming a point.

Suppose we have a 2D coordinate frame #1 as shown in Figure 5.31, with origin and axes i and j. Further suppose we have an affine transformation T(.) represented by matrix M. So T(.) transforms coordinate frame #1 into coordinate frame #2, with new origin ’ = T( ), and new axes i’ = T(i) and j’ = T(j).i’= M(1, 0, 0)T = Mi ; j’= M(0, 1, 0)T = Mjci’ + dj’ + ’ = cM(1, 0, 0)T + dM(0, 1, 0)T+ M(0, 0, 1)T= c Mi + d Mj + M

M(c, d, 1)T= M = c Mi + d Mj + M

M(c, 0, 0)T+ M(0, d, 0)T + M(0, 0, 1) T = c Mi + d Mj + Mci’ + dj’ + ’ is the same as M(c, d, 1)T and M(c, 0, 0)T+ M(0, d, 0)T + M(0, 0, 1) T.The same result in Equation 5.35.

5.4.2. Solution: Using elementary examples.

a) P = =

The point (e, f) in the new system lies at (e + m, f + n) in the original system.

Page 11 of 14 file: document.doc

Page 12: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

b) P = =

The point (e, f) in the new system lies at (e cos(a) - f sin(a), e sin(a) + f cos(a)), where a = A / 180 radians.

c) P = =

The point (e, f) in the new system lies at (3e, 2f) in the original system.

d) P = =

The point (e, f) lies in the original system at (e, -f).

5.5.3. Solution: A hexagonal tiling.

a) OAB is equilateralSo OA=AB=RLength of a hexagon is R too

b) The distance between two rows can be expressed as:OO’= 2OC = 2 OA .Sin60 = RThe distance between two columns can be expressed as:

OE= OD+DE=R+ OA .Cos60= R

c)# define PI 3.1415926

Page 12 of 14 file: document.doc

Page 13: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

cvs.pushCT(); // so we can return herecvs.translate2D(0, 0); // position in origin for the first motiffor(i = 0; i < numberofColumns; i++)// for each column {

cvs.pushCT();for(j = 0; j <numberofRows; j++) // for each row{

drawmotif();// move to the right cvs.translate2D(0, 2* sin(PI/3.)*R);

}

// back to the start of this columncvs.popCT(); // move to the next columncvs.translate2D(1.5*R,pow(-1,i+1)* sin(PI/3.)*R);

}cvs.popCT();

5.6.1. Solution: What does gluLookAt() do?

a).

So that u.v = 0; u.n = 0; n.v = 0; u, v, and n are mutually perpendicular.

b)

= ==

Page 13 of 14 file: document.doc

Page 14: 3eChap5 Exercise Solutions

Computer Graphics Using OpenGL - Hill/Kelley 3rd Edition

= =

Similarly,

c)= (4, 3, 4)

= = (4, 0,-4)

= (-12, 32, -12)

Normalize u, v, and n, = (0.70711, 0, 0.70711)= (-0.3313, 0.8834, - 0.3313) = (0.6247, 0.4685, 0.6247)

dx =-eye.u =(4, 4, 4) . (-0.3313, 0.8834, - 0.3313) = 0dy =-eye.v =(4, 4, 4) . (0.6247, 0.4685, 0.6247) = -0.88345dz =-eye.n =(4, 4, 4) . (0.70711, 0, 0.70711) = -6.872

So that,

5.6.2. Inquiring of the values in a matrix in OpenGL.This solution not included.

5.6.3. Inquiring of the values in a matrix in OpenGL.This solution not included.

Page 14 of 14 file: document.doc


Recommended