Você está na página 1de 73

Chapter 8

3-D Transformations

3D Viewing Pipeline
Primitives

Object space
Modeling Transformation

World space
Viewing Transformation

Camera space

Hidden Surface Removal

Lighting & Shading

3D-Clipping

Projection

Normalized view space


Scan conversion, Hiding
March 24, 2015

Computer Graphics

Image

Image space,
Device coordinates

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Composite transformations

March 24, 2015

Computer Graphics

3D Coordinate System
3D coordinate system consists of a reference point called
origin and three mutually perpendicular passing through
origin.
y axis
y

z
x
March 24, 2015
z axis

Computer Graphics
x axis

Right-Hand
Reference System

3D Coordinate System
y axis

A point P(x,y,z) specifies that point


is
At a distance of x units from YZ-plane
At a distance of y units from XZ-plane
At a distance of z units from XY-plane

z
x
z axis
March 24, 2015

Computer Graphics

x axis
5

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Composite transformations

March 24, 2015

Computer Graphics

Vector Fundamentals
In 3D there are 3 natural coordinate vectors I, J and K having
unit along X, Y and Z axis respectively.
y axis

Any vector V = aI+bJ+cJ can be


resolved into three components
(a,b,c) that represent corresponding
point when the tail of V is placed at
the origin.

V=aI+bJ+cK

P(a,b,c)
z
x

z axis
March 24, 2015

Computer Graphics

x axis
7

Vector Fundamentals
If P(x0,y0,z0) and Q(x1,y1,z1) are two points in space then
PQ = (x1 xo)I+ (y1 yo)J+ (z1 zo)K

y axis

Vector has two attributes:

length- a scalar denoted by |v|


direction in 3D space

P(a,b,c)

Equality: Two vectors are equal if


they have same length and direction
z axis
March 24, 2015

V=aI+bJ+cK

Computer Graphics

z
x
x axis
8

Vector Fundamentals
1.

Vector Addition: perform addition by the head-to-tail rule.


Note u+v = v+u

u
v

u+v

v+u

March 24, 2015

Computer Graphics

Vector Fundamentals
2.

Vector Subtraction: To perform subtraction, given u and v,


we define u - v to be u + (-v):
Note u - v v u

-v

u-v

March 24, 2015

Computer Graphics

10

Vector Fundamentals
3.
4.

Zero Vector: i.e. vector with zero length and no direction.


v + (-v) = 0
Magnitude of Vector of a vector u = aI+bJ+cK is a scalar
quantity defined as:

u a b c
2

5.

Unit vector for any vector u is a vector having direction of u


and unit magnitude. It can be found as

u
uv
u

March 24, 2015

-v
Computer Graphics

11

Vector Fundamentals
Scalar Multiplication: (Scalar times a vector ) Let be a
scalar and u a vector we define u to be the vector with
length | ||u| with

6.

the direction of u if > 0


the opposite of u if < 0

if = 0, the vector is the zero vector or a point.


u

March 24, 2015

2u

Computer Graphics

-3u

12

Vector Fundamentals
7.

Dot Product: Given two vectors u = a1I+b1J+c1K and v =


a2I+b2J+c2K the dot product of the vectors is defined to be
the scalar as follows
u.v = a1.a2+b1. b2+c1.c2
or u.v = |u| |v| cos , 0
where is the angle between u and v

Also
cos = u.v /|u| |v|
Or = cos-1(u.v /|u| |v|)

March 24, 2015

Computer Graphics

13

Vector Fundamentals
The dot product is a scalar value that tells us something
about the relationship between two vectors
If uv > 0 then 0< < 90
Vectors point in the same general direction
If uv < 0 then > 90
Vectors point in opposite direction
If uv = 0 then = 90
Vectors are perpendicular
(or one or both of the vectors is degenerate (0,0,0))

March 24, 2015

Computer Graphics

14

Vector Fundamentals
8.

Cross Product: Given two vectors u = a1I+b1J+c1K and v =


a2I+b2J+c2K the cross product of the vectors is defined to be
the new vector whose length is |u||v| sin , 0 and
direction is given by the right hand rule.
u x v = (b1.c2 c1. b2)I+ (c1.a2 a1. c2)J+ (a1.b2 b1. a2)K

or |u x v| = |u| |v| sin , 0 where is the angle b/w u & v


u

sin = |u x v| /|u| |v|


Or = sin (|u x v| /|u| |v|)

-1

March 24, 2015

Computer Graphics

uXv
15

Vector Fundamentals
In a Right handed coordinate System
J

IxJ=K
JxK=I
I x K = -J
or K x I = J
K

I
Right-Hand
Reference System

March 24, 2015

Computer Graphics

16

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Composite transformations

March 24, 2015

Computer Graphics

17

3D Homogeneous Coordinates
Similar to the 2-D situation we can use homogeneous
coordinates for 3-D transformations - 4 coordinate
y axis
column vector
All transformations can
then be represented
as matrices x

P(x, y, z) =

y

z

z
x

March 24, 2015

z axisGraphics
Computer

x
18

axis

3D Homogeneous Coordinates
Transform a point:
px
mxx
p
m
y
yx
pz
mzx

1

0

mxy
myy
mzy
0

mxz
myz
mzz
0

dx
dy

dz

px mxx px mxy py mxz pz d x


p m p m p m p d
yy y
yz z
y
y yx x
pz mzx px mzy py mzz pz dz

1
0

px
r

M py d
pz

Top three rows are the affine transform!


Bottom row stays 1
March 24, 2015

Computer Graphics

19

3D Homogeneous Coordinates
Transform a vector:
vx
mxx
v
m
y
yx
vz
mzx

0
0

mxy
myy
mzy
0

mxz
myz
mzz
0

dx
dy

dz

vx mxx vx mxy vy mxz vz 0


v m v m v m v 0
yy y
yz z
y yx x

vz mzx vx mzy vy mzz vz 0


0000
0

vx

M vy
vz

Top three rows are the linear transform


Displacement d is properly ignored

Bottom row stays 0


March 24, 2015

Computer Graphics

20

3D Homogeneous Coordinates
In Homogeneous arithmetic Legal operations always end in
0 or 1!
M

vector+vector:

0
0

scalar*vector:s

point+vector:

1
0

vectorvector:

0
M

0
M

1
1
0
M

point+point:

1
1
2
M

scalar*point:s

1
s
pointpoint:

weightedaverage

affinecombination

March 24, 2015

ofpoints:

1 M

2 M

3 1
3 1
1

Computer Graphics

21

3D Homogeneous Coordinates
Rotation, Scale, and Translation of points and vectors unified
in a single matrix transformation:

p Mp

mxx
m
Where M = yx
mzx

Matrix has the form:


Last row always 0,0,0,1

mxy
myy
mzy
0

mxz
myz
mzz
0

dx
dy

dz

Transforms compose by matrix multiplication.


March 24, 2015

Computer Graphics

22

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Composite transformations

March 24, 2015

Computer Graphics

23

3D Geometric Transformations
Geometric Transformations: In Geometric transformation an
object itself is moved relative to a stationary coordinate system
or background. The mathematical statement of this view point is
described by geometric transformation applied to each point of
the object. Various Geometric transformations are:

Translation
Scaling
Rotation
Reflection
Shearing

March 24, 2015

Computer Graphics

25

3D Geometric Transformations
Once we have an object described, transformations are used to
move that object, scale it and rotate it

March 24, 2015

Computer Graphics

26

Geometric Transformations
Translation
Scaling
Rotation
Reflection
Shearing

3D Geometric Translation
Translation is defined as the displacement of any object by a
given distance and direction from its original position

March 24, 2015

Computer Graphics

28

3D Geometric Translation
To translate a point in three dimensions by tx, ty and tz simply
calculate the new points as follows:
x = x + tx
y = y + ty z = z + tz

(x, y, z)
(x, y, z)
Translated Position

March 24, 2015

Computer Graphics

29

3D Geometric Translation
The translation of a point P(x,y,z) by (tx, ty, tz) can be
written in matrix form as:
P Tv ( P) where v tx I ty J tz K
1 0 0 tx
0 1 0 ty

Tv
0 0 1 tz

0
0
0
1

March 24, 2015

x
y

z

'

Computer Graphics

x
y

30

Geometric Transformations
Translation
Scaling
Rotation
Reflection
Shearing

3D Geometric Scaling
Scaling is the process of expanding or compressing the
dimensions of an object determined by the scaling factor.

March 24, 2015

Computer Graphics

32

3D Geometric Scaling
To scale a point in three dimensions by sx, sy and sz simply
calculate the new points as follows:
x = sx*x
y = sy*y
z = sz*z

(x, y, z)

(x, y, z)

Scaled Position
March 24, 2015

Computer Graphics

33

3D Geometric Scaling
The scaling of a point P(x,y,z) by scaling factors Sx, Sy
and Sz about origin can be written in matrix form as:
P Ssx , sy , sz ( P ) where
sx 0 0
0 sy 0
Ssx , sy , sz
0 0 sz

0 0 0

such that

March 24, 2015

x
y
z

'

0
0
0

x
y

sx 0 0
0 sy 0

0 0 sz

0 0 0

'

x
y
P
z

1

1
0 x sx x
0 y sy y

0 z sz z

1 1 1

Computer Graphics

34

Geometric Transformations
Translation
Scaling
Rotation
Reflection
Shearing

3D Geometric Rotations
When we performed rotations in two dimensions we only
had the choice of rotating about the z axis
In the case of three dimensions we have more options
Rotate about x pitch
Rotate about y yaw
Rotate about z - roll

March 24, 2015

Computer Graphics

36

3D Geometric Rotations

Roll is known as the rising or dipping of the airplane's wing. The movement is done
about Longitudinal axis. The Ailerons controlling the roll are located on the
trailing edge of both wings.
Pitch refers to the movement of the airplane's nose either up or down. It movement
is done about Lateral axis. The elevator controls the pitch is also located on the
rear of the aircraft on the tail, along with the rudder.
Yaw allows the airplane to move towards the left or right while in flight. The
movement is done about a ventricle axis. The yaw is controlled by the rudder
located in the rear of the aircraft on the tail.

Roll
March 24, 2015

Pitch
Computer Graphics

Yaw
37

3D Geometric Rotations
Rotate about z axis: The picture shows a z-axis rotation
around the origin in a positive angle, (Anti-clockwise) as you
look down the z-axis towards the origin. The angle is
measured in the xy-plane from the x-axis, just as in 2D.

March 24, 2015

Computer Graphics

38

3D Geometric Rotations
Rotate about y axis: You are looking down the y-axis
which is not shown. A positive (counter-clockwise) angle is
shown.

March 24, 2015

Computer Graphics

39

3D Geometric Rotations
Rotate about x axis: You are looking down the x-axis
which is not shown. A positive (counter-clockwise) angle is
shown.

March 24, 2015

Computer Graphics

40

3D Geometric Rotations
The equations for the three kinds of rotations in 3-D are

x = xcos - ysin
y = xsin + ycos
z = z
March 24, 2015

x = x
y = ycos - zsin
z = ysin + zcos
Computer Graphics

x = zsin + xcos
y = y
z = zcos - xsin
41

3D Geometric Rotations
The scaling of a point P(x,y,z) by an angle of about
different axis about origin can be written in matrix form as:
P R , axis ( P)

where

cos
0

R , J

sin

March 24, 2015

x
y

'

cos
sin

R , K

0 cos
0

0
0

0
1
0 cos

R , I

Computer Graphics

sin
cos

0 sin
1
0
0

x
y

0 sin
0

0 0
0 0
1 0

0 1
0
0
sin 0
cos 0

0
1
42

Geometric Transformations
Translation
Scaling
Rotation
Reflection
Shearing

3D Geometric Reflections
We can perform reflections relative to a selected reflection axis
or with respect to a reflection plane.
Reflections relative to a given axis are equivalent to 180
rotations about that axis.
Reflections with respect to a plane are equivalent to 180
rotations in 4D space.
3 standard Reflections are
About z axis or with respect to xy plane
About y axis or with respect to zx plane
About x axis or with respect to yz plane

March 24, 2015

Computer Graphics

44

3D Geometric Reflections
Reflection about XY plane: Reflection relative to the xy
plane can be obtained from following set of equations:
x = x
y = y
z = z
In homogenous matrix form
P' = Mxy(P)

where

M xy

1 0
0 1

0
0

0
0

0 0 1 0

0 0

Reflections about other planes can also be obtained by


symmetry.
March 24, 2015

Computer Graphics

45

3D Geometric Reflections
Reflection about XY plane is a useful reflection as it
converts a right-handed coordinate system into a left-handed
coordinate system.
y
y
z
x
x

March 24, 2015

Computer Graphics

46

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Composite transformations

March 24, 2015

Computer Graphics

47

Inverse Transformations
Inverse Translation:
Inverse Scaling:

Tv Tv
1

S sx,sy ,sz S1/ sx,1/ sy ,1/ sz


1

Inverse Rotations:

R , p R , p

Inverse Reflections:

M plane M plane

March 24, 2015

Computer Graphics

48

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Combining transformations

March 24, 2015

Computer Graphics

49

3D Coordinate Transformations
Coordinate Transformation: The object is held
stationary while coordinate system is moved relative
to the object. These can easily be described in terms
of the opposite operation performed by Geometric
transformation.

March 24, 2015

Computer Graphics

50

3D Coordinate Transformations
Coordinate Translation:

T v Tv Tv
1

S sx ,sy ,sz S sx ,sy ,sz S1/ sx ,1/ sy ,1/ sz

Coordinate Scaling:
Coordinate Rotations:
Coordinate Reflections:

March 24, 2015

R , p R , p R , p
1

M plane M plane M plane

Computer Graphics

53

Contents
1.
2.
3.
4.
5.
6.
7.

3D Coordinate System
Vector Fundamentals
3D Homogeneous Coordinate
3D Geometric Transformations
3D Inverse Transformations
3D Coordinate Transformations
Composite transformations

March 24, 2015

Computer Graphics

54

Composite Transformation

Various composite transformations are


1.
2.
3.
4.
5.

Scaling about arbitrary point P


Tilting as rotation about x-axis followed by y-axis
Aligning vector V with K (Z axis)
Rotation about arbitrary axis L
Mirror Reflection about arbitrary plane (N, R0)

March 24, 2015

Computer Graphics

56

Exercise 1
Scaling about arbitrary point P

Imagine scaling an object around a point (a,b,c) other than the origin

March 24, 2015

Translate point (a,b,c) to origin


Scale around origin
Translate back to point

Computer Graphics

57

Exercise 1

March 24, 2015

Computer Graphics

58

Exercise 1
1.

Let P is the object point which is to be scaled by factors sx, sy and sz about
the fixed point (a,b,c). Then the composite transformation S sx,sy,sz,(a,b,c) can be
obtained by performing following sequence of transformations :
Translate (a,b,c) to origin and the new object point is found as
P1 = TV(P) where V= aI bJ cK

2.

Scale object about origin and the new object point is


P2 = Ssx,sy,sz(P1)

3.

Retranslate (a,b,c) back the final object point is


PF = T-1V(P2) = T-V (P2)

The composite transformation can be obtained by back substituting


PF = T-1V(P2)
= T-V Ssx,sy,sz(P1)
= T-V Ssx,sy.TV(P) where V= aI bJ cK

March 24, 2015

Computer Graphics

59

Exercise 1
Thus we form the matrix to be Ssx,sy,sz(a,b,c)= T-VSsx,sy,szTV
And the composite scaling transformation matrix is

1 0 0 a sx 0 0 0 1
0 1 0 b 0 sy 0 0 0


S sx , sy , sz ( a ,b,c )
0 0 1 c 0 0 sz 0 0



0 0 0 1 0 0 0 1 0
sx 0 0 a.sx a
0 sy 0 b.sy b

0 0 sz c.sz c

1
0 0 0

March 24, 2015

Computer Graphics

0 0 a
1 0 b
0 1 c
0 0

60

Exercise 2
Define tilting as rotation about the x-axis followed by a
rotation about y-axis.
a)

Find the tilting matrix T = Ry,J x Rx,I

b)

Does order of rotation matters ?

March 24, 2015

Computer Graphics

61

Exercise 3
Z axis

Aligning vector V with Vector K


Let V = aI+bJ+cK then the alignment can be
performed by following sequence of
operations:
Rotate V about X-axis by an angle of 1, so
that V rotates into upper -half of the xz
plane. V= R1,I(V)
Rotate V about Y-axis by an angle of -2,
so that V rotates and align with Z axis.
V= R -2,J(V ).

P(a,b,c)
c
a

V
b

Y axis

X axis

How to get these two angles???

March 24, 2015

Computer Graphics

62

Exercise 3
Z axis

Step1: Rotate V about X-axis by an angle of


1, so that V rotates into upper -half of the xz
plane. V= R1,I(V)

P(0,b,c)

Q(a,0, b2+c2

P(a,b,c)

Let P be projection of P(a,b,c) in YZ plane.


P(0,b,c). If 1 be the angle that OP

makes with +ve Z-axis, then from OPC


sin 1
cos 1

March 24, 2015

b2 c2
c
b2 c2

Y axis

X axis
Computer Graphics

63

Exercise 3
Rotate vector V about X-axis by an angle of 1
V= R1,I(V) or Q = R

1,I

Where

R1 , I

(P)

0
1
0 cos
1

0 sin 1

0
0

0
0

sin 1

cos 1

sin 1

cos 1 0
0

b
b2 c2
c
b2 c2

Does V have rotated into upper -half of the xz plane?


March 24, 2015

Computer Graphics

64

Exercise 3
1
0

cos 1

sin 1

sin 1

cos 1

Q R1 , I ( P )

0
c

b2 c2
b

b2 c2
0

0
0

b2 c2
c
b2 c2
0

b
c

cb bc

a
0
b
.
0 c
1

1

b2 c2
b2 c2
b2 c2

b c
2

March 24, 2015

0
b

0
0
0

1

Computer Graphics

65

Exercise 3
Z axis

Step2: Rotate V about Y-axis by an angle of


2 , so that V aligns with +ve Z axis. V=
R1,I(V)

R(0,0, a2+b2+c2)
Q(0,0, b2+c2)
V

Q(a,0, b2+c2)

Let Q be projection of Q(a,0,b2+c2) on Z


axis, Q(0,0, b2+c2 ). If 2 be the angle
that OQ makes with +ve Z-axis, then from
a
OQQ
sin 2
a2 b2 c2

cos 2
March 24, 2015

b2 c2
a 2 b2 c2

P(0,b,c)

a
C
V

2
O
A

P(a,b,c)

Y axis

X axis
Computer Graphics

66

Exercise 3
Rotate vector V about Y-axis by an angle of 2
V= R-2,J(V) or R = R-

2,J

Where

R 2 , J

cos 1
0

sin 2

(Q)

0 sin 2
1
0
0 cos 2
0
0

0
0
0

sin 2
cos 2

a
a2 b2 c2
b2 c2
a2 b2 c2

Does V have aligned Z axis?


March 24, 2015

Computer Graphics

67

Exercise 3
cos 2
0
R R 2 , J (Q )
sin 2

b2 c2

a b c
0
a

a b c
0

0
1
0

sin 2

1
0
0

0
cos 2
0
a b c
0
b2 c2
2

a2 b2 c2
0

a b c
0
2
a b2 c2

March 24, 2015

a 2 b2 c2

1 Computer Graphics

2
2
b c

a b2 c2 a b2 c2

0
0
0

1

0

0 .

0

1

2
2
b c
1

2
2
2
a b c

68

Exercise 3
Composite Matrix AV,K can be found as
R R 2 , J (Q) R 2 , J * R1 , I ( P )

b2 c2

a2 b2 c2
0
a

a2 b2 c2
0

V
0
a
V
0

0
1
0
0

V
0

V
0

March 24, 2015

1
0

a2 b2 c2
0
2
b c2
a2 b2 c2
0


0 .

0

1

1
0
0
0

0
c

0
b

1
0
0
0 .

0 0

1 0

V

V
0

0
c
b2 c2
b

b2 c2
0
ab
V
c

b
V
0

Computer Graphics

0
b
b2 c2
c
b2 c2
0

ac
V
b

c
V
0

b2 c2
where
V a2 b2 c2

1
69

Exercise 3
Corollary I: If both b = c =0

then 0, V a

AV , K a0

a
0

a
0
a
1
0
0

and 2 900

0 .
0

R 2 , J

March 24, 2015

Computer Graphics

70

Exercise 3
Corollary II: The inverse of AV,K can be found as

A1V , K ( R 2 , J . R1 , I ) 1
R

1
1 , I

1 , I

.R
.R

2 , J

2 , J

( R 2 , J . R1 , I )
( AV , K )
A

March 24, 2015

V ,K
Computer Graphics

71

Exercise 4
Find transformation AV,N that aligns vector V = 2I J K with
another N = I+J+K.

AV ,N

March 24, 2015

4
18
1
18
1
18
0

1
18
2
1

18 2
2
1

18 2
0

0
18

2
1

18 2

2
1

0
18 2

0
1

Computer Graphics

72

Exercise 5
Rotation by an angle about arbitrary axis L specified by a
direction vector V and fixed point P0.
The transformation can be found as:
1. Translate P0 to origin.
2. Align Vector V with K.
3. Rotate object about Z axis by angle .
4. Realign vector V back.
5. Retranslate P0 back.

March 24, 2015

Computer Graphics

73

Exercise 5
If P is the object point the sequence of transformations is:
1.
Translate P0 to origin
P1 = T-P0(P)
P2 = AV,K(P1)

2.

Align Vector V with K.

3.

Rotate object about Z axis by angle . P3 = R,K(P2)

4.

Realign vector V back.

5.

Retranslate P0 back. P5 = T-1-P0(P4)

P4 = A-1V,K(P3)

Thus P5 = T-1-P0(P4)
= T-1-P0.A-1V,K(P3)
= T-1-P0.A-1V,K. R,K(P2)
= T-1-P0.A-1V,K. R,K. AV,K(P1)
= T-1-P0.A-1V,K. R,K. AV,K. T-P0(P)

Thus we form the matrix to be R,L= T-1-P0 A-1V,K R,K AV,KT-P0


March 24, 2015

Computer Graphics

74

Exercise 5

March 24, 2015

Computer Graphics

75

Exercise 6
The pyramid is defined by A(0,0,0), B(1,0,0), C(0,1,0) and D(0,0,1) is
rotated by 450 about line L in the direction of V = J+K passing
through P(0,1,0). Find the coordinates of rotated figure.

R450 , L

2
2
1
2
1

2
0

1
2

2 2
4
2 2
4
0

March 24, 2015

1
2
2 2
4
2 2
4
0

2
2 2
4
2 2

4
1

A' B' C ' D'

Computer Graphics

1
2
2 2
4
2 2
4
1

1 2
2
4 2
4
2 4
4
1

0
1
0
1

2 2
2
2

2
1

76

Any Question !

Você também pode gostar