You are on page 1of 6

CS 430

Computer Graphics
Outline
• World window to viewport transformation
3D Transformations • 3D transformations
World Window to Viewport Transformation • Coordinate system transformation
Week 2, Lecture 3

David Breen, William Regli and Maxim Peysakhov


Department of Computer Science
Drexel University

1 2

1 2

The Window-to-Viewport Window-to-Viewport


Transformation Transformation
• Problem: Screen windows cannot display the whole • Given a window Three steps:
world (window management)
and a viewport, • Translate
• How to transform and clip:
Objects to Windows to Screen what is the • Scale
transformation from • Translate
WCS to VPCS?

3 4
P ic s /M a th c o u rte s y o f D a v e M o u n t @ U M D -C P 1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

3 4

Transforming World
Clipping to the Viewport
Coordinates to Viewports
• 3 steps • Viewport size may • Transform lines in world
1. Translate not be big enough • Then clip in world
for everything •Transform to image
2. Scale
• Then draw
3. Translate • Display only the • Do not transform pixels
pixels inside the
Overall Transformation: viewport

P'= M wv P 5 6
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G 1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

5 6

1
Representation of 3D
3D Transformations
Transformations
• Z axis represents depth
• Right-Handed System
– When looking “down” at the
origin, positive rotation is CCW

• Left-Handed System
– When looking “down”, positive
rotation is in CW
– More natural interpretation for
displays, big z means “far” (into screen)
9 10
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

9 10

3D Transformations:
3D Homogenous Coordinates
Scale & Translate
• Homogenous • Scale
coordinates for 2D – Parameters for each
space requires 3D axis direction
vectors & matrices
• Homogenous
coordinates for 3D • Translation
space requires 4D
vectors & matrices
• [x,y,z,w]
11 12

11 12

3D Transformations: Rotation Around an


Rotation Arbitrary Axis
• One rotation for • Rotate a point P
each world around axis n (x,y,z)
coordinate axis by angle q
# tx 2 + c txy + sz txz − sy 0&
% (
txy − sz ty 2 + c tyz + sx 0(
R =%
%txz + sy tyz − sx tz + c 0(
2

% (
$ 0 0 0 1'
• c = cos(q)
• s = sin(q)
€ • t = (1 - c)
13 Graphics Gems I, p. 466 & 498 14

13 14

2
Rotation Around an
Arbitrary Axis Improved Rotations
• Also can be expressed as the • Euler Angles have problems
Rodrigues Formula – How to interpolate keyframes?
– Angles aren’t independent
– Interpolation can create Gimble Lock, i.e.
loss of a degree of freedom when axes
Prot = P cos(ϑ ) + (n × P)sin(ϑ ) + n(n ⋅ P)(1− cos(ϑ )) align
• Solution: Quaternions!

€ 15 16

15 16

17 18

17 18


p = (0, x )

19 20

19 20

3
A & B are quaternions

slerp – Spherical linear interpolation


Need to take equals steps on the sphere
21 22

21 22

What about interpolating 3D Transformations:


multiple keyframes? Reflect & Shear
• Shoemake suggests using Bezier • Reflection:
curves on the sphere
• Offers a variation of the De Casteljau about x-y plane
algorithm using slerp and quaternion
control points
• See K. Shoemake, “Animating rotation • Shear:
with quaternion curves”, Proc. (function of z)
SIGGRAPH ’85
23 24

23 24

3D Transformations:
Shear Example
" X'% " 1 Shxy Shxz 0% " X %
$ ' $ x ' $ '
$ Y ' ' = $ Shy 1 Shyz 0' $ Y '

$ Z' ' $ Shzx Shzy 1 0' $ Z '
$ ' $ ' $ '
#1& # 0 0 0 1& # 1 &
X ' = X + ShxyY + Shxz Z
Y ' = Shyx X +Y + Shyz Z

Z ' = Shzx X + ShzyY + Z
25 26
Pics/Math courtesy of Dave Mount @ UMD-CP

25 26

4
Example: Composition of 3D
Example (Cont.)
Transformations
(1-2)
• Goal: Transform P1P2 and P1P3 • Process
1. Translate P 1 to (0,0,0)
2. Rotate about y D1

3. Rotate about x
4. Rotate about z
(3)

(4)

27 28
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G 1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

27 28

Example 2: Composition of 3D
Final Result
Transformations
• What we’ve really
done is transform • Airplane defined in x,y,z
the local coordinate • Problem: want to point
system Rx, Ry, Rz it in Dir of Flight (DOF)
to align with the centered at point P
origin x,y,z • Note: DOF is a vector
• Process:
– Rotate plane
– Move to P

29 30
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G 1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

29 30

Transformations to Change
Example 2 (cont.) Coordinate Systems
• Issue: the world has many different relative
• Zp axis to be DOF frames of reference
• Xp axis to be a horizontal • How do we transform among them?
vector perpendicular to • Example: CAD Assemblies & Animation Models
DOF
– y x DOF
• Yp, vector perpendicular to
both Zp and Xp (i.e.Zp x Xp)

31 32
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

31 32

5
Transformations to Change
Coordinate System Example (1)
Coordinate Systems
• 4 coordinate systems • Translate the House
1 point P to the origin

M 1←2 = T (4,2) M1←2 = T(x1, y1 )


−1
M 2←3 = T (2,3) • S (0.5,0.5) M 2←1 = ( M1←2 )

M 3←4 = T (6.7,1.8) • R(45 ) = T(−x1,−y1 ) P1

The matrix M ij that maps points from coordinate system j


€ to i is the inverse of the matrix M ji that maps points from
33 34
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G
coordinate system j to coordinate system i. 1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G

33 34

World Coordinates and


Coordinate System Example (2)
Local Coordinates
• Transformation
M 5←1 = M 5←4 • M 4←3 • M 3←2 • M 2←1 • To move the tricycle,
Composition:
we need to know how
all of its parts relate to
the WCS

• Example: front wheel
rotates on the ground
wrt the front wheel’s z
axis: P (wo) = T(αr,0,0) ⋅ Rz (α ) ⋅ P (wh )
Coordinates of P in
wheel coordinate
system: P'(wh ) = R (α ) ⋅ P (wh )
35 z 36
1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G 1 9 9 4 F o le y /V a n D a m /F in e r/H u g e s /P h illip s IC G


35 36

Questions about Homework 1?

• Go to web site

37

37

You might also like