Computer Graphicscs314/Vsep2004/lec_pdf/… · · 2004-09-21Computer Graphics Copyright 2004, A...
-
Upload
truonghanh -
Category
Documents
-
view
246 -
download
1
Transcript of Computer Graphicscs314/Vsep2004/lec_pdf/… · · 2004-09-21Computer Graphics Copyright 2004, A...
1
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Chapter 3
Transformations
transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Geometric Transformations
Transformation τ is one-to-oneand onto mapping of nD to itself
Affine transformation – τ(V) = AV+bA – matrixb – scalar
In CG Geometric Transformations are affine transformations with geometric meaningNote: transformation has meaning only for vectors ⇒ for point P τ(P) is transformation of vector from (0,0) to P
University ofUniversity ofBritish ColumbiaBritish Columbia
Transformations
Transforming an object = transforming all its points
Transforming a polygon = transforming its vertices
Why?
2
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Applications
Viewing
Modeling
Articulation
University ofUniversity ofBritish ColumbiaBritish Columbia
Scaling
V = (vx,vy) – vector in XY plane
Scaling operator S with parameters (sx,sy):S(sx,sy)(V) = (vxsx, vysy)
University ofUniversity ofBritish ColumbiaBritish Columbia
Scaling
Matrix form:
Independent in x and y
S(sx,sy)(V) = (vx, vy)sx 00 sy
ò ó= (vxsx, vysy)
3
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotation
Polar form:
Rotating V counterclockwise by θ to W:
)cossinsincos,sinsincoscos(
))sin(),cos((
),(
θαθαθαθα
θαθα
rrrr
rrywxwW
+−=
++=
=
WyV
x
θ α
r
V = (vx, vy) = (rcosë, r sinë)
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotation
Matrix form:
Rotation operator R with parameter θ at the origin:
−=
θθθθ
θcossinsincos
R
W r r
V
=−
=−
( cos , sin )cos sinsin cos
cos sinsin cos
α αθ θθ θ
θ θθ θ
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotation Properties
Rθ is orthogonal
R-θ - rotation by -θ is
( ) ( )TRR θθ =−1
( ) 1
cossinsincos
),()( −− =
−= θθ
θθθθ
RvvVR yx
4
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Translation
Translation operator T with parameters (tx,ty):
T(tx,ty)(V) = (vx+ tx, vy+ ty)
University ofUniversity ofBritish ColumbiaBritish Columbia
To represent T in matrix form – introduce homogeneous coordinates:
Conversion (projection) from homogeneous space to Euclidean:
In homogeneous coordinates:
Translation - Homogeneous Coordinates
(2,2,1)=(4,4,2)=(1,1,0.5)
V v v v v vhxh
yh
wh
x y= =( , , ) ( , , )1
V v vvv
vvx y
xh
wh
yh
wh= =
( , ) ,
University ofUniversity ofBritish ColumbiaBritish Columbia
Translation
Using homogeneous coordinates, translationoperator may be expressed as:
( , ) ( ) ( , , )
( , , )
t t hx y
x y
x x y y
x yT V v vt t
v t v t
=
= + +
11 0 00 1 0
1
1
5
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Transformation Composition
What operation rotates XY by θ around P = (px,py) ?Answer:
Translate P to originRotate around origin by θTranslate back
University ofUniversity ofBritish ColumbiaBritish Columbia
Transformation Composition
T R T
p p p p
p p p p
x y x y
x y x y( , ) ( , )
cos sin-sin cos
− − =
− −
θ
θ θθ θ
1 0 00 1 0
1
00
0 0 1
1 0 00 1 0
1
University ofUniversity ofBritish ColumbiaBritish Columbia
Transformations Quiz
What do these transformations do?
And these homogeneous ones?
How to mirror through arbitrary line in XY?
What transformation achieves this?
−
−
101
1101
1001
1001
1001
a
5.000010001
1-00010001
6
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotate by Shear
Shear
Rotation by composition of 3 shears
.1
1
101
11
101
101
101
cossin-sincos
++++
=
+=
=
yzyxxyzzxy
zy
xxy
zy
xθθθθ
0 ô ò ô 2ù ñ
101
,10
1,
1011
,1101
aa
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotate by Shear (cont.)
Solve for x, y,z :
Result
cosò =1+xy= yz+1, sinò =ày= z+xyz+x
y =à sinò,x = z =à tan2ò
University ofUniversity ofBritish ColumbiaBritish Columbia
What does composition of following two scaled shears do?
Why use it?Is it convenient?What happens when ?
Rotate by Shear (cont.)
10
01
sincos
sectan
cos sinsin cos
θθ
θθ
θ θθ θ
−
=
−
2θ π→
7
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotation Approximation
For small angles can approximate:
as(Taylor expansion of sin/cos)
Example:
y0=x sin ò+y cos ò'xò+yx0=x cos òày sin ò'xàyò
cosò→ 1, sin ò→ ò ò→ 0
25° 10° 2° 0.5°
University ofUniversity ofBritish ColumbiaBritish Columbia
Rotation Approximation
App. rotation matrix
Matrix has to be orthogonal & normalizedARθ is orthogonalARθ not normalizedNormalize
ARò = c1
cò
càò
c1
!, c = (1+ ò2)
p
ARò =1 òà ò 1
ò ó
University ofUniversity ofBritish ColumbiaBritish Columbia
3D Transformations
All 2D transformations extend to 3D In homogeneous coordinates:
−
=
=
=
1000010000cossin00sincos
1010000100001
1000000000000
axis z thearoundRotation n Translatio Scaling
),,(),,( θθθθ
θz
zyx
ttt
z
y
x
sss R
ttt
Ts
ss
S zyxzyx
transformations
8
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
3D Transformations
Questions:Is S1S2 = S2S1?
Is T1T2 = T2T1?
Is R1R2 = R2R1?
Is S1R2 = R2S1?
…..
University ofUniversity ofBritish ColumbiaBritish Columbia
Example: Arbitrary Rotation
Problem: Given two orthonormal coordinate systems XYZand UVW Find transformation from one to the other
Answer: Transformation matrix R whose rows are U,V,W:
=
zyx
zyx
zyx
wwwvvvuuu
R
Y Z
X
W
V
U
University ofUniversity ofBritish ColumbiaBritish Columbia
Arbitrary Rotation
Proof:
Similarly R(Y) = V & R(Z) = W
R Xu u uv v vw w w
u u u
U
x y z
x y z
x y z
x y z
( ) ( , , )
( , , )
=
=
=
1 0 0
9
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Inverse (=transpose) transformation R-1
provides mapping from UVW to XYZE.g.
Comment: Used for mapping between XY and arbitrary plane
Arbitrary Rotation (cont.)
X
uuu
wvuwvuwvu
uuuUR
zyx
zzz
yyy
xxx
zyx
==
++=
=−
)0,0,1(
)0,0,(
),,()(
222
1
University ofUniversity ofBritish ColumbiaBritish Columbia
Lemma: Affine image of line segment is line segment between image of its end pointsProof:
Given affine transformation A & line segment
Conclusion: polyhedron(polygon) is affinelytransformed by transforming its vertices (Why?)
Transformation of Objects
)1()( 21 tPtPtS −+=
)()1()())1(()(
))1(())((
21
21
21
PAtPtAtPAtPA
tPtPAtSA
−+=−+=
−+=
University ofUniversity ofBritish ColumbiaBritish Columbia
Viewing Transformations
Question: How to view (draw) 3D object on 2D screen?Answer:
Project transformed object along Z axis onto XY plane -and from there to screen (space)Canonical projection:
1000000000100001
z
y
x
In practice “ignore” z axis – use x and ycoordinates for screen coordinates
10
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Parallel Projection
Projectors are all parallel
Orthographic: Projectors perpendicular to projection plane
Oblique: Projectors not necessarily perpendicular to projection plane
ObliqueOrhtographic
University ofUniversity ofBritish ColumbiaBritish Columbia
Perspective Projection
Viewing is from point at finite distanceWithout loss of generality:
Viewpoint at originViewing plane is z=d
Given P=(x,y,z) triangle similarity gives:
dzyy
dzxx
dy
zy
dx
zx
pppp
/ and
/ and ==⇒==
center of projection
3P
Z
projectors
projectionplane
),,( 1111 zyxP =
2P
31pp xx =
2px
dz=
X
University ofUniversity ofBritish ColumbiaBritish Columbia
In matrix notation with homogeneous coordinates:
In Euclidean coordinates:
P singular: det(P)=0
Perspective Projection (cont’d)
P x y z x y zd
x y z zd
( , , , ) ( , , , )/
( , , , ).1 1
1 0 0 00 1 0 00 0 1 10 0 0 0
=
=
xz d
yz d
zz d
xz d
yz d
d x y dp p/,
/,
/ /,
/, ( , , ).
=
=
transformations
11
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Perspective Projection (cont’d)
What is (if any) is the difference between:Moving projection planeMoving viewpoint (center of projection)?
camtrans
Z
x
Z
x
Z
x
University ofUniversity ofBritish ColumbiaBritish Columbia
Perspective Warp
P not invertible – can’t get depth (order) backIdea:
Warp viewing frustum (world)Then use parallel projection
Z
x
z=α z=d
Z
x
z=0 z=d
University ofUniversity ofBritish ColumbiaBritish Columbia
Perspective Warp
Matrix formulation
Preserves relative depth (third coordinate)What does mean?
( , , , ) , ,( ) ,x y z dd d
dd
x y z dd
zd
1
1 0 0 00 1 0 00 0 1
0 0 0−−−
=−−
α
αα
αα
( , , )/
,/
,x y z xz d
yz d
dd zp p p =−
−
2
1α
α
0=α
12
Computer GraphicsComputer Graphics
Copyright 2004, A. Sheffer, UBC
Transformations
University ofUniversity ofBritish ColumbiaBritish Columbia
Perspective Warp
Warp modifies planes
warped to:
What does warp do to other objects? Spheres?
Aëdxp +Bëdyp +D(ëà d)zp +Cëd2 +Dd2 = 0
Ax+By+Cz+D= 0
University ofUniversity ofBritish ColumbiaBritish Columbia
Another Transformations Quiz
What does each transformation preserve?
lines parallellines
distance angles normals convexity conics
scaling
rotation
translation
shear
perspective