Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Recitation 2. 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions.

Similar presentations


Presentation on theme: "Computer Graphics Recitation 2. 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions."— Presentation transcript:

1 Computer Graphics Recitation 2

2 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions.

3 3 Rotation in 2D Rotation about the origin by angle . O  Positive angle means counter-clockwise direction.

4 4 Rotation in 2D Positive angle means counter-clockwise direction. O  Rotation about the origin by angle .

5 5 Rotation in 2D – matrix representation Multiply (x, y) by the rotation matrix: O  P (x, y) P’ = R  (P)

6 6 Interpolating rotations in 2D O  We want to generate N intermediate positions:

7 7 Interpolating rotations in 2D O  Divide the arc into N pieces of equal length

8 8 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

9 9 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

10 10 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

11 11 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

12 12 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

13 13 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

14 14 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

15 15 Interpolating rotations in 2D Apply rotations for i = 1, 2, …, N O 

16 16 Rotations mathematically Rotation is a linear orthogonal transformation that doesn’t change the orientation. It means:  Let v, u be vectors (or points), R the rotation = (length and angle preservation) => ||Ru|| = ||u||  In matrix representation: let R be n  n matrix: RR T = I => R -1 = R T det(R) = +1  The rows of R are orthonormal vectors (unit-length pairwise orthogonal vectors). They form a “right-hand” basis of R n.

17 17 2D rotations as complex numbers multiplication Represent points (x, y) as (x + iy) in C. Multiplying by e i  is equivalent to rotation by angle  : e i  = cos  + i sin  e i  (x + iy) = (cos  + i sin  ) (x + iy) = (x cos   y sin  ) + i (x sin  + y cos  ) O  Re Im P = x + iy P’ = e i  (x + iy)

18 18 Rotations in 3D

19 19 Rotations in 3D Euler’s theorem: any orientation can be obtained from a fixed reference orientation by a single unique rotation around an appropriate axis in space.

20 20 Rotations in 3D We express the rotation in terms of the rotation axis n = (n x, n y, n z ), ||n|| = 1, and the rotation angle . O n  P

21 21 Rotations in 3D We express the rotation in terms of the rotation axis n = (n x, n y, n z ), ||n|| = 1, and the rotation angle . O n  P P’

22 22 The formula for P’ Decompose v into to components: v = v || + v   v || = n => v || || n  v  = v – v || => v   n O n P v vv v ||

23 23 The formula for P’ The rotation doesn’t affect the axis of rotation, therefore: v’ = R n,  (v) = R n,  (v || + v  ) = = R n,  (v || ) + R n,  (v  ) = = v || + R n,  (v  ) We only need to rotate v  by angle  in the plane perpendicular to n. O n P v vv v || P’ v’

24 24 The formula for P’ O n P vv v ||  The rotation doesn’t affect the axis of rotation, therefore: v’ = R n,  (v) = R n,  (v || + v  ) = = R n,  (v || ) + R n,  (v  ) = = v || + R n,  (v  ) We only need to rotate v  by angle  in the plane perpendicular to n.

25 25 The formula for P’ We rotate v  in the plane perpendicular to n. The plane = Span{v , n  v  }.  v , n  v   n  n  v   v  Therefore, R n,  (v  ) = cos  v  + sin  (n  v  ) = cos  v  + sin  (n  v) n  v = n  (v || + v  ) = n  v || + n  v  = n  v  n vv v ||  R (v)R (v) vv n  v   R  (v  ) = (cos , sin  )

26 26 The formula for P’ v’ = R n,  (v) = v || + R n,  (v  ) = = n + cos  v  + sin  (n  v) = = n + cos  (v  n) + + sin  (n  v) = = cos  v + (1  cos  ) n + + sin  (n  v). n vv v ||  P’ R n,  (v) = cos  v + (1  cos  ) n + sin  (n  v).

27 27 Interpolating rotations in 3D We are animating an object by specifying the key transformations (key frames). Suppose two consecutive key-frames are specified by rotations R 1 and R 2.

28 28 How to define an interpolation?? We can try to interpolate the two rotation matrices: R(t) = (1  t) R 1 + t R 2 Doesn’t work – the result is not a rotation matrix

29 29 Solution Use extension of e i  to 3D => quaternions Interpolate the quaternions…

30 30 Multiplication by e i  in 3D - ??? Hamilton was searching for an extension of complex numbers that would represent 3D rotations. He first tried to find a field of numbers of the form x +yi + zj, where x, y, z  R and i 2 = j 2 =  1. This is not a field (not closed under multiplication). One day, Hamilton realized that he needs four scalars: s +xi + yj + zk ! He called these objects quaternions.

31 31 Quaternions The ring of quaternions = { s +xi + yj + zk }  i 2 = j 2 = k 2 =  1  ij = k, ji =  k; jk = i, kj =  i; ki = j, ik =  j We will denote q = (s, v) = s +xi + yj + zk where v = (x, y, z) q 1  q 2 = (s 1, v 1 )  (s 2, v 2 ) = = (s 1 s 2 , s 1 v 2 + s 2 v 1 + v 1  v 2 )

32 32 Conjugate and inner product q = (s 1,  v 1 ) = s  xi  yj  zk = q 1  q 2 = s 1 s 2 + ||q|| 2 = = s 2 + x 2 + y 2 + z 2 q  1 = q / ||q|| 2

33 33 Rotating with quaternions Represent a vector v as v Q = (0, v). Rotating about axis n, ||n|| = 1, by angle  : R n,  (v) = q  v Q  q q = (cos(  /2), sin(  /2) n) Proof:

34 34 Some facts about quaternions: Rotating by q and by  q has the same effect. “Rotating” by q such that ||q|| =  has a scaling effect. So, we consider the unit quaternions only ||q|| =1 These quaterions live on the unit sphere in four dimensions… So, we have 3 degrees of freedom for our rotation quaterion (just like with n,  rotation: 1 degree for  + 2 degrees for n = 3 degrees of freedom.)

35 35 Now, how do we interpolate? Given two rotations q 1 and q 2 Simple interpolation q(t) = (1  t) q 1 +t q 2 is not good enough – doesn’t give “constant speed”: q1q1 q2q2

36 36 Now, how do we interpolate? Given two rotations q 1 and q 2 Simple interpolation q(t) = (1  t) q 1 +t q 2 is not good enough – doesn’t give “constant speed” The unit quaternions live on the unit sphere, so we want to draw a great arc from q 1 to q 2 on that sphere (it gives the shortest path on the sphere). q1q1 q2q2

37 37 Spherical interpolation (slerp) q1q1 q2q2 q(t)q(t)

38 See you next time Next week the lesson will be presented by Andrei, you will learn about SVD…


Download ppt "Computer Graphics Recitation 2. 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions."

Similar presentations


Ads by Google