Computer Graphics
description
Transcript of Computer Graphics
![Page 1: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/1.jpg)
Computer Graphics
Recitation 2
![Page 2: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/2.jpg)
2
The plan today
Learn about rotations in 2D and 3D. Representing rotations by quaternions.
![Page 3: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/3.jpg)
3
Rotation in 2D
Rotation about the origin by angle .
O
Positive angle meanscounter-clockwise direction.
![Page 4: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/4.jpg)
4
Rotation in 2D
Positive angle meanscounter-clockwise direction.
O
Rotation about the origin by angle .
![Page 5: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/5.jpg)
5
Rotation in 2D – matrix representation
Multiply (x, y) by the rotation matrix:
O
P (x, y)
P’ = R (P)
cossin
sincos
cossin
sincos
)(
yxy
yxx
y
x
y
x
PRP
![Page 6: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/6.jpg)
6
Interpolating rotations in 2D
O
We want to generate N intermediate positions:
![Page 7: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/7.jpg)
7
Interpolating rotations in 2D
O
Divide the arc into N pieces of equal length
![Page 8: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/8.jpg)
8
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 9: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/9.jpg)
9
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 10: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/10.jpg)
10
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 11: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/11.jpg)
11
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 12: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/12.jpg)
12
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 13: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/13.jpg)
13
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 14: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/14.jpg)
14
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 15: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/15.jpg)
15
Interpolating rotations in 2D
Apply rotations for i = 1, 2, …, N
O
NiR
![Page 16: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/16.jpg)
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
<Ru, Rv> = <u, v> (length and angle preservation) => ||Ru|| = ||u||
In matrix representation: let R be n n matrix: RRT = I => R-1 = RT
det(R) = +1 The rows of R are orthonormal vectors (unit-length pairwise
orthogonal vectors). They form a “right-hand” basis of Rn.
![Page 17: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/17.jpg)
17
2D rotations as complex numbers multiplication
Represent points (x, y) as (x + iy) in C. Multiplying by ei is equivalent to rotation by angle :
ei = cos + i sinei (x + iy) = (cos + i sin) (x + iy) =
(x cos y sin) + i (x sin + y cos)
O
Re
Im
P = x + iy
P’ = ei (x + iy)
![Page 18: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/18.jpg)
18
Rotations in 3D
![Page 19: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/19.jpg)
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.
![Page 20: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/20.jpg)
20
Rotations in 3D
We express the rotation in terms of the rotation axis n = (nx , ny , nz), ||n|| = 1, and the rotation angle .
O
n P
![Page 21: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/21.jpg)
21
Rotations in 3D
We express the rotation in terms of the rotation axis n = (nx , ny , nz), ||n|| = 1, and the rotation angle .
O
n P
P’
![Page 22: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/22.jpg)
22
The formula for P’
Decompose v into to components:
v = v|| + v
v|| = <v, n> n => v|| || n
v = v – v|| => v nO
n
P
v
v
v||
![Page 23: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/23.jpg)
23
The formula for P’
The rotation doesn’t affect the axis of rotation, therefore:
v’ = Rn, (v) = Rn, (v|| + v) =
= Rn, (v||) + Rn, (v) =
= v|| + Rn, (v)
We only need to rotate v by angle in the plane perpendicular to n.
O
n
P
v
v
v||
P’
v’
![Page 24: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/24.jpg)
24
The formula for P’
O
n
P
v
v||
The rotation doesn’t affect the axis of rotation, therefore:
v’ = Rn, (v) = Rn, (v|| + v) =
= Rn, (v||) + Rn, (v) =
= v|| + Rn, (v)
We only need to rotate v by angle in the plane perpendicular to n.
![Page 25: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/25.jpg)
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,
Rn, (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|| R (v)
v
n v
R (v) = (cos, sin)
![Page 26: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/26.jpg)
26
The formula for P’
v’ = Rn, (v) = v|| + Rn, (v) =
= <n, v>n + cos v + sin (n v) =
= <n, v>n + cos (v <n, v>n) +
+ sin (n v) =
= cos v + (1 cos) <n, v> n +
+ sin (n v).
n
v
v||
P’
Rn, (v) = cos v + (1 cos ) <n, v> n + sin (n v).
![Page 27: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/27.jpg)
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 R1 and R2.
![Page 28: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/28.jpg)
28
How to define an interpolation??
We can try to interpolate the two rotation matrices:
R(t) = (1 t) R1 + t R2
Doesn’t work – the result is not a rotation matrix
![Page 29: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/29.jpg)
29
Solution
Use extension of ei to 3D => quaternions Interpolate the quaternions…
![Page 30: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/30.jpg)
30
Multiplication by ei 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 i2 = j2 = 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.
![Page 31: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/31.jpg)
31
Quaternions
The ring of quaternions = {s +xi + yj + zk } i2 = j2 = k2 = 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)
q1 q2 = (s1, v1) (s2, v2) =
= (s1 s2 <v1, v2 >, s1 v2 + s2 v1 + v1 v2)
![Page 32: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/32.jpg)
32
Conjugate and inner product
q = (s1, v1) = s xi yj zk
< q1 , q2 > = q1 q2 = s1 s2 + <v1, v2 >
||q||2 = <q, q> = s2 + x2 + y2 + z2
q1 = q / ||q||2
![Page 33: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/33.jpg)
33
Rotating with quaternions
Represent a vector v as vQ = (0, v). Rotating about axis n, ||n|| = 1, by angle :
Rn, (v) = qvQq
q = (cos( /2), sin( /2) n)
Proof:
sincossin2
cos1sin2
,,)(
)(sin,)cos1(cos,0(
)(sincos2,sin2)sin(cos,0(
)sin,)(cos,0)(sin,(cos
22
22
2222
22
22
2222
cbabcacba
vnnvnv
vnnvnv
nvnqvq
:factsbasicfollowingtheUsing
![Page 34: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/34.jpg)
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.)
![Page 35: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/35.jpg)
35
Now, how do we interpolate?
Given two rotations q1 and q2
Simple interpolation q(t) = (1 t) q1+t q2 is not good enough – doesn’t give “constant speed”:
q1q2
![Page 36: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/36.jpg)
36
Now, how do we interpolate?
Given two rotations q1 and q2
Simple interpolation q(t) = (1 t) q1+t q2 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 q1 to q2 on that sphere (it gives the shortest path on the sphere).
q1
q2
![Page 37: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/37.jpg)
37
Spherical interpolation (slerp)
q1
q2
21
21
,cos
]1,0[,sin
)sin(
sin
))1sin(()(
tqt
qt
tq
thatsuchiswhere
q(t)
![Page 38: Computer Graphics](https://reader036.fdocuments.us/reader036/viewer/2022062520/56815a95550346895dc811ff/html5/thumbnails/38.jpg)
See you next time
Next week the lesson will be presented by Andrei, you will learn about SVD…