intro to computer graphics transformations...5 cs5620 intro to computer graphics copyright c....
TRANSCRIPT
![Page 1: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/1.jpg)
1
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 1
Transformations
Specifying Complex Scenes
(x,y,z)
(0,0,0) 2
Specifying Complex Scenes
β’ Absolute position is not very natural
β’ Need a way to describe βrelativeβ relationship:
β βThe panel is on top of the roof, which is above the houseβ
β’ Work βlocallyβ for every object and then combine
3
Transformations
β’ Transforming an object = transforming all its points
β’ For a polygon = transforming its vertices
4
Scaling
β’ π£ =π£π₯
π£π¦ β vector in ππ plane
β’ Scaling operator π with parameters (π π₯ , π π¦):
(0,0) (sx,sy)=(0.7, 0.7) (sx,sy)=(0.7, 1.0) (sx,sy)=(3.0, 1.5)
π(π π₯,π π¦) π£ =π£π₯π π₯π£π¦π π¦
5
Matrix Form
β’ Convenient math for representing linear transformations
β Composition β multiplication
β Inverse transformation β matrix inverse
β More on that laterβ¦
6
![Page 2: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/2.jpg)
2
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 2
Scaling Matrix Form
β’ Independent in π₯ and π¦
β Non-uniform scaling is allowed
ππ π₯,π π¦ π£ =π π₯ 00 π π¦
π£π₯
π£π¦=
π£π₯π π₯π£π¦π π¦
7
Rotation
β’ Polar form:
π£ =π£π₯
π£π¦=
π cos πΌπ sin πΌ
β’ Rotate v anti-clockwise by to w:
π π(π£) =π€π₯
π€π¦=
π cos πΌ + ππ sin πΌ + π
=π£π₯ cos π β π£π¦ sin π
π£π₯ sin π + π£π¦ cos π
(0,0)
w π
v
π
r
(0,0)
vy
vx
= -45o = -135o
8
Rotation
β’ Matrix form:
π π π£ =cos π β sin πsin π cos π
π£
β’ Rotation operator π with parameter π:
π π =cos π βsin πsin π cos π
9
Rotation Properties
β’ π π is orthogonal
π π β1= π π π
β’ Rotation by βπ is
π βπ =cos (β π) β sin βπ
sin (βπ) cos βπ
=
cos π sin πβsin π cos π
= π π β1
π π = cos π β sin πsin π cos π
10
Translation
β’ Translation operator π with parameters (π‘π₯, π‘π¦):
ππ‘π₯,π‘π¦ π£ =π£π₯ + π‘π₯π£π¦ + π‘π¦
β’ Can we express π in a matrix form?
(tx,ty)=(0.0, 1.0) (tx,ty)=(1.0, 0.0) (tx,ty)=(1.5, 0.3)
11
Homogeneous Coordinates in π 2
β’ Points of the form
π£β =
π£π₯β
π£π¦β
π£π€β
β’ Where we identify
π£π₯
β
π£π¦β
π£π€β
β‘
ππ£π₯β
ππ£π¦β
ππ£π€β
for all nonzero π
12
![Page 3: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/3.jpg)
3
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 3
Conversion Formulae
β’ From Euclidean to homogeneous
π£ =π£π₯
β
π£π¦β β π£β =
π£π₯β
π£π¦β
1
β’ From homogeneous to Euclidean
π£β =
π£π₯β
π£π¦β
π£π€β
β π£ =
π£π₯β
π£π€β
π£π¦β
π£π€β
13
Example
β’ In homogeneous coordinates
221
=442
=110.5
14
Translation using Homogeneous Coordinates
ππ‘π₯,π‘π¦ π£β =1 0 π‘π₯0 1 π‘π¦0 0 1
π£π₯
π£π¦
1=
=π£π₯ + π‘π₯π£π¦ + π‘π¦
1
15
Matrix Form
Why bother expressing transformations in matrix form?
16
Transformation Composition
What operation rotates by π around π =ππ₯
ππ¦?
β Translate π to origin
β Rotate around origin by π
β Translate back
17
p p
17
Transformation Composition
β’ π1 performs one transformation
β’ π2 performs a second transformation
π2 π1π£ = π2π1π£ = π2π1 π£
β’ π2π1 performs the composed transformation
18
![Page 4: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/4.jpg)
4
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 4
Transformation Composition
π ππ₯,ππ¦ π ππ βππ₯,βππ¦ π£ =
1 0 ππ₯
0 1 ππ¦
0 0 1
cos π β sin π 0sin π cos π 00 0 1
1 0 βππ₯
0 1 βππ¦
0 0 1
π£
19
Transformation Quiz
β’ What do these Euclidean transformations do?
1 00 1
,1 00 β1
,β1 00 1
1 01 1
,1 π0 1
20
Transformation Quiz
β’ And these homogeneous ones?
1
1β1
1
10.5
21
Transformation Quiz
β’ Can one rotate in the plane by reflection?
β’ How can one reflect through an arbitrary line in the plane?
22
Arbitrary Reflection
β’ Shift by 0,βπ
β’ Rotate by βπΌ
β’ Reflect through π₯
β’ Rotate by πΌ
β’ Shift by (0, π)
π 0,π π πΌπ πππ₯π
βπΌπ 0,βπ
23
π·
π·β π = ππ + π
πΆ (π, π)
π
π
Rotate by Shear
β’ Shear 1 01 1
,1 10 1
,1 π0 1
,1 0π 1
β’ Rotation by 0 β€ π β€π
2β‘ composition of 3 shears
cos π½ βsin π½sin π½ cos π½
=1 π0 1
1 0π 1
1 π0 1
=
=1 + π₯π¦ π₯
π¦ 11 π0 1
=
=1 + π₯π¦ π§ + π₯π¦π§ + π₯
π¦ π¦π§ + 1
24
![Page 5: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/5.jpg)
5
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 5
Rotate by Shear
cos π βsin πsin π cos π
=1 + π₯π¦ π§ + π₯π¦π§ + π₯
π¦ π¦π§ + 1
β’ Solve for π₯, π¦, π§:
cos π = 1 + π₯π¦ = π¦π§ + 1 sin π = π¦ = β(π§ + π₯π¦π§ + π₯)
β’ Solution: π¦ = sin π , π₯ = π§ = β tan(π/2)
cos π βsin πsin π cos π
=1 βtan π 2 0 1
1 0sin π 1
1 βtan π 2 0 1
β’ When is this useful?
25
Rotate by Shear Image Rotation
26
http://www.datagenetics.com/blog/august32013/index.html
Rotate by Shear
β’ Can we rotate with two (scaled) shears?
1 sin π0 cos π
sec π 0βtan π 1
=cos π βsin πsin π cos π
β’ What happens for π βπ
2 ?
27
Rotation Approximation
β’ For small angles π β 0 we have: cos π β 1 and sin π β π (Taylor expansion of sin/cos)
β’ Can approximate:
π₯ = π₯ cos π β π¦ sin π β π₯ β π¦π π¦ = π₯ sin π + π¦ cos π β π₯π + π¦
Examples (steps of π):
28
3D Transformations
β’ All 2D transformations extend to 3D β’ In homogeneous coordinates:
π π π₯,π π¦,π π§ =
π π₯π π¦
π π§
1
, π π‘π₯,π‘π¦,π‘π§
11
1
π‘π₯π‘π¦π‘π§1
π π§π =
cos π β sin πsin π cos π
1
1
β’ What is π π₯π ? π π¦
π ?
29
3D Transformations
β’ Questions (commutativity):
β Scaling: Is S1S2 = S2S1?
β Translation: Is T1T2 = T2T1?
β Rotation: Is R1R2 = R2R1?
30
![Page 6: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/6.jpg)
6
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 6
Rotation Non-Commutativity
31
3D Coordinate Systems
OpenGL
swap any two axes
or reverse any one axis
Example: Arbitrary Rotation
Problem: Given two orthonormal coordinate systems
π, π, π and [π, π,π], find a transformation from one to the other.
π π
π
π
π
π
33
Arbitrary Rotation Answer:
Transformation matrix π whose columns are π, π,π:
π =
π’π₯ π£π₯ π€π₯
π’π¦ π£π¦ π€π¦
π’π§ π£π§ π€π§
Proof:
π π =
π’π₯ π£π₯ π€π₯
π’π¦ π£π¦ π€π¦
π’π§ π£π§ π€π§
100
=π’π₯π’π¦
π’π§
= π
Similarly π (π) = π and π (π) = π
34
Arbitrary Rotation (cont.)
Inverse (=transpose) transformation, π β1, maps [π, π,π] to π, π, π :
π β1 π =
π’π₯ π’π¦ π’π§
π£π₯ π£π¦ π£π§
π€π₯ π€π¦ π€π§
π’π₯π’π¦
π’π§
=π’ 2
00
=100
= π
35
3D Graphics Coordinate Systems
36
β’ How can we view (draw) 3D objects on a 2D screen?
3D World space
3D Camera space
2D View space
3D Object space
![Page 7: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/7.jpg)
7
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 7
Viewing Pipeline β’ object - world positioning the objectβ modeling transformation glTranslate(tx,ty,tz), glScale(sx,sy,sz), glRotate(ang, xa,ya,za)
β’ world - camera positioning the camera β viewing transformation gluLookAt(cx,cy,cz, ax,ay,az, ux,uy,uz)
β’ camera β view taking a picture β projection transformation glFrustum(left, right, bottom, top, near,far)
β’ view - screen displaying the image β viewport transformation glViewport(llx,lly, width,height)
37
3D World space
3D Camera space
2D View space
3D Object space
Viewing Transformations World β Camera/Eye
38
World space
Camera/eye space
Viewing Transformations Camera β View
39
π
π
π
π
π
Camera space View space
Projection transformation
Projection Transformations
β’ Canonical projection
β Ignore π§ coordinate, use π₯, π¦ coordinates as view coordinates
40
1000
0000
0010
0001
π
π
π
1 0 0 0
0 0 0 0
0 0 1 0
0 0 0 1
0 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Perspective Projector Lines
A line connecting a point in 3D with its 2D projection
41
object projection
plane
center of
projection
Pinhole Camera Model
42
![Page 8: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/8.jpg)
8
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 8
Comparison
43
Vanishing Points where 3D parallel lines meet in 2D
under perspective
44 Triple point perspective
Perspective Projection
45
π
π
Projection plane
π§ = π Center of projection
π₯π
π=
π₯
π§ ,π¦π
π=
π¦
π§
π₯π =π₯
π§/π , π¦π =
π¦
π§/π
β’ Viewing is from point at a finite distance
β’ Without loss of generality: β Viewpoint at origin β Projection (viewing) plane is
π§ = π
Triangle similarity:
π₯π¦π§
π₯π
π¦π
π
Perspective Projection β’ Euclidean coordinates:
π₯π
π¦π
π=
π₯
π§ π π¦
π§ π π§
π§ π
β’ Homogeneous coordinates:
π₯π
π¦π
π1
=
π₯
π§ π π¦
π§ π π§
π§ π 1
=
π₯π¦π§
π§/π
β’ Matrix form:
π
π₯π¦π§1
=
1 0 0 00 1 0 00 0 1 0
0 01
π0
π₯π¦π§1
=
π₯π¦π§
π§/π
β’ π is not injective & singular: det (π) = 0 46
π
π π§ = π
π₯π¦π§
π₯π
π¦π
π
π₯π
π=
π₯
π§ ,π¦π
π=
π¦
π§
47
www.pinterest.com/explore/forced-perspective/
Fun with Perspective
48
![Page 9: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/9.jpg)
9
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 9
Scale vs. Dolly What is the difference between:
β’ Moving the projection plane (scale, zoom)
β’ Moving the viewpoint (center of projection) (dolly)
Z
Z
49
Scale
y y
Zz z
y
z
Dolly
Scale Dolly
50
Original
The Dolly-Zoom Effect aka βHitchcock effectβ
β’ Dolly + scale s.t. subject remains same size
β’ Zoom-in camera while moving away from subject (or the opposite)
51
vimeo.com/moogaloop.swf?clip_id=84548119
Perspective Warp
1 0 0 0
0 1 0 0
( )0 0
10 0 1/ 0 /
xx
yy
d d d zz
d d d
d z d
2
/
/
p
p
p
x
z dxy
yz d
zd z
z d
52
2 2( )( ) 1
( )
d z df z
z d d z
z
f(z)
monotonic increasing in z
preserves z ordering
z1 z2
53
2d
d
d
d
f(z2) f(z1)
View Frustrum
54
![Page 10: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/10.jpg)
10
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 10
55
1 0 0 0
0 1 0 0
0 0
0 0 1/ 0
d d
d d
d
20 0
20 0
( ) 20 0
0 0 1 0
n r l
r l r l
n t b
t b t b
f n fn
f n f n
Projection Matrix From View Frustrum
Important special case:
π = βπ, π‘ = βπ
perspective
warp normalized
device
coordinates
56
Viewport Matrix From NDC to Viewport
normalized
device
coordinates
(llx,lly) width
height
57
Fun with Perspective
3D Sidewalk Art by Julian Beever
58
59 60
![Page 11: Intro to Computer Graphics Transformations...5 CS5620 Intro to Computer Graphics Copyright C. Gotsman, G. Elber, M. Ben-Chen Computer Science Dept., Technion Transformations Page 5](https://reader033.vdocument.in/reader033/viewer/2022042908/5f38a3c87adabb1f3a20292c/html5/thumbnails/11.jpg)
11
CS5620
Intro to Computer Graphics
Copyright
C. Gotsman, G. Elber, M. Ben-Chen
Computer Science Dept., Technion
Transformations
Page 11
61 62
63