程序代写代做代考 Geometric Transformations

Geometric Transformations
Lecture: 4
Fall 2016
Computer Graphics (CS3388) Department of Computer Science
University of Western Ontario

Transformations
Outline
Translation, Rotation, Scaling, Reflection Transformation matrix
Homogeneous coordinates
3D transforms
Composite transformations
Normal transformation
(most of the materials are from Tamara Munzner (UBC))
1

Transformation
transforming an object = transforming all its points transforming a polygon = transforming its vertices
2

Matrix representation
Represent 2D transformation with matrix: multiply matrix by column vector ≡ apply transformation to point
􏰖x′􏰗 􏰔a b􏰕􏰖x􏰗 y′ = c d y
Transformations are combined by matrix multiplication:
􏰖x′􏰗 􏰔a b􏰕􏰔e f􏰕􏰔i j􏰕􏰖x􏰗 y′ = c d g h k l y
Matrices are efficient, convenient way to represent sequence of transformations!
3

Scaling
Scaling a coordinate means multiplying each of its components by a scalar
Uniform scaling means this scalar is the same for all components:
4

Scaling
Non-uniform scaling: different scalars per component
How can we represent this in the matrix form?
5

Scaling
Scaling operation: Or, in matrix form:
􏰖x′􏰗 􏰖ax􏰗 y′ = by
􏰖x′􏰗 􏰔a 0􏰕 􏰖x􏰗
y′ = 0 b y 􏰆 􏰅􏰄 􏰇
scalingmatrix
6

2D Rotation
7

2D Rotation: proof
8

2D Rotation
2D Rotation matrix can be written as,
􏰖x′􏰗 􏰔cos θ − sin θ􏰕 􏰖x􏰗
y′ = sinθ cosθ y even though sin θ and cos θ are nonlinear functions of θ
x’ is a linear combination of x and y y’ is a linear combination of x and y
9

Shear
Shear along x-axis
push points to right in proportion to height
􏰖x′􏰗 􏰔1 −shx􏰕􏰖x􏰗 􏰖0􏰗 y′ = 0 1 y + 0
10

Reflection
Reflect across x-axis (mirror):
􏰖x′􏰗 􏰔1 0􏰕􏰖x􏰗 􏰖0􏰗
y′ = 0 −1 y + 0
11

2D Translation
12

Transformation Matrix
Finding the Matrix for a Transformation:
→− T →− T
Consider e1 = (1, 0) and e2 = (0, 1) , two unit vectors along the axes
of the coordinate system. If we know where the transformation must send these two vectors, then we can find the transformation matrix.
Suppose we want to reflect an object about the vertical axis, then what is the transformation matrix?
We know that the transformation matrix has the form:
􏰔 a b 􏰕 →− M=cdx
Now let’s transform e1 & e2
→− →−
13

Transformation Matrix
We know that the transformation matrix has the form:
􏰔a b􏰕􏰖1􏰗 􏰖a􏰗 M(e1)= c d 0 = c
→−
􏰔a b􏰕􏰖0􏰗 􏰖b􏰗 M(e2)= c d 1 = d
Now, to reflect the object around the vertical axis, we observe that
→− →−
M(e1) = −e1, & thus we can form the following system of equations:
􏰔a b􏰕􏰖1􏰗 􏰖−1􏰗 cd0=0
→−
14

Transformation Matrix
We obtain a = −1 and c = 0. Performing the same operations with →− →−
M(e2) = e2, we get b = 0 and d = 1, & the transformation matrix is,
􏰔−1 0􏰕 M=01
15

Transformation Matrix
Transformations and Coordinate Systems:
Suppose two coordinate systems sharing their origin but oriented differently. How can we transform points from one system to the other?
→− 􏰖1􏰗 →− 􏰖0􏰗 →− 􏰖3/5􏰗 →− 􏰖−4/5􏰗 Lete1= 0,e2= 1nandu1= 4/5,u2= 3/5 bethe
orthogonal unit vectors representing the two coordinate systems. →− 􏰖 4 􏰗 →− →−
Let v = 2 be a vector expressed in the (e1 , e2 ) coordinate system. 􏰙−→􏰚
u1T →− →− →− Then the matrix −→ transforms the point v into the u1 , u2
u2T coordinate system:
􏰔 3/5 4/5􏰕􏰖4􏰗 􏰖 4 􏰗 −4/5 3/5 2 = −2
16

Reflection
Reflect a vector about a line that goes through the origin:
(Householder transformation)
y
→− 􏰖vx􏰗
be a vector in the direction of the line. The matrix
Let v = v
performing this reflection is:
M= 1 􏰔vx2−vy2 2vxvy 􏰕
→− 22 ||v|| 2vxvy vy −vx
17

Orthogonal Projections
Project a vector orthogonally onto a line that goes through the origin:
→− 􏰖vx􏰗
y
Let v = v required matrix is:
be a vector in the direction of the line. Then the
M=1􏰔vx2 vxvy􏰕
→− vv v2 ||v||xy y
18

Homogeneous Coordinates
Represent 2D coordinates (x,y) with 3-vector (x,y,1) use 3×3 matrices for 2D transformations
cosθ −sinθ 0 Rotation =  sin θ cos θ 0
001
a 0 0 Scale = 0 b 0
001
1 0 Tx Translation = 0 1 Ty 
001
19

Homogeneous Coordinates
Geometric interpretation:
20

Homogeneous Coordinates
Problem: Two parallel lines can intersect
In Euclidean space, two parallel lines can’t intersect, which is NOT true in projective space.
Euclidean space (or Cartesian space) describe our 2D/3D geometry so well, but they are not sufficient to handle the projective space
If a point goes far away to infinity, it becomes meaningless in Euclidean space
21

Homogeneous Coordinates
Solution: Homogeneous Coordinates: way of representing N-dimensional coordinates with N+1 numbers.
simply add an additional variable w, into existing coordinates Cartesian (1, 2) becomes (1, 2, 1) in Homogeneous
If (1, 2) moves toward infinity, it becomes (∞, ∞) in Cartesian coordinates, & becomes (1, 2, 0) in Homogeneous coordinates (as (1/0, 2/0) = (∞, ∞))
22

3D Transformations
3D rotation around z-axis:
23

3D Transformations
3D rotation around x,y axes:
24

3D Transformations
3D Scaling
25

3D Transformations
3D Translation
26

3D Transformations
3D Shear
27

3D Transformations
Summary
28

Composing Transformations
TaTb = TbTa, but RaRb! = RbRa and TaRb! = RbTa translations commute
rotations around same axis commute
rotations around different axes do not commute rotations and translations do not commute
29

Composing Transformations
p′′ = T(2,3,0)R(z,90)p = TRp
30

Normal Transformations
How to transform a surface normal?
Surface normal N = (P2 − P1) × (P3 − P1)
used for lighting
31

Normal Transformations
If points transformed by matrix M, can we just transform normal vector by
M too?
x′ m11 m12 m13 Tx  x y′ = m21 m22 m23 Ty  y
  z′ m31 m32 m33 Tzz
0 00010
translations OK: w=0 means unaffected rotations OK
uniform scaling OK
These all maintain direction
32

Normal Transformations
Non-uniform scaling: does not work
x − y = 0 plane: Line x = y , normal [1,-1,0] (direction of the line x=-y)
stretch along x by 2: new plane x = 2y
2 2 0 0 01
Transformed normal: −1 = 0 1 0 0 −1  0   0 0 1 0   0 
000011
33

Normal Transformations
normal is direction of line x = −2y or x + 2y = 0
not perpendicular to plane! should be direction of 2x = −y
34

Correct Normal Transformations
Transform a plane: P′ = MP Transform a normal: N′ = QN
N′.P′ = 0 =⇒ N ′ T P ′ = 0
=⇒ (QN)T(MP)=0 =⇒ NTQTMP=0
NTP = 0 if QTM = I, which yields
Q = (M−1)T
35