3D Tranformation
3D Tranformation
Gr aphi c s Gr aphi c s
Thr ee-Di mensi onal Gr aphi c s
- Use of a right-handed coordinate system
ee e s o a G ap c s
(consistent with math)
- Left-handed suitable to screens - Left-handed suitable to screens.
- To transform from right to left, negate the g g
z values.
Right Handed Space Left Handed Space g p p
Homogeneous representation of a
point in 3D space: po p
| | | w z y x |
T
P
point) 3D a for 1, w (
Transformations will thus be Transformations will thus be
represented by 4x4 matrices:
P = A.P
Tr ansf or mat i on Mat r i x i n 3D:
(
K T
(
(
(
q f e d
p c b a
(
O I
K T
=
(
(
(
=
r j i g
q f e d
A
(
s n m l
j g
where,
(
(
T f d
c b a
produces linear transformations:
li h i fl ti
(
(
(
= T
j i g
f e d
scaling, shearing, reflection
and rotation.
(
j i g
K = [p q r]
T
, produces translation
I = [l m n]
T
, yields perspective transformation
hil O i ibl f if li while, O = s, is responsible for uniform scaling
(
0 0 0 S
(
0 0 1 t
(
(
0 0 0
0 0 0
y
x
S
S
(
(
(
0 1 0
0 0 1
y
x
t
t
(
(
(
0 0 0
0 0 0
z
y
S
S
(
(
(
1 0 0
z
y
t
(
1 0 0 0
(
1 0 0 0
(
Scale Translation
(
(
(
0 1 0
0 0 1
x
Sh
Sh
Shear
(
(
(
0 1 0
0 1 0
z
y
Sh
Sh
Origin is unaffected
(
1 0 0 0
Origin is unaffected
by scale and shear
3D Ref l ec t i on: 3 e ec t o
The following matrices:
(
(
(
0 0 1 0
0 0 0 1
(
(
(
0 0 1 0
0 0 0 1
(
(
(
0 0 1 0
0 0 0 1
(
(
(
=
0 1 0 0
0 0 1 0
XY
T
(
(
(
=
0 1 0 0
0 0 1 0
YZ
T
(
(
(
=
0 1 0 0
0 0 1 0
ZX
T
(
1 0 0 0
(
1 0 0 0
(
1 0 0 0
produce reflection about:
XY YZ ZX XY
plane
YZ
plane
ZX
plane
respectively. p y
Rotation Matrices along an axis:
(
0 ) sin( 0 ) cos(
(
0 0 0 1
g
(
(
(
0 ) cos( 0 ) sin(
0 0 1 0
) ( ) (
(
(
(
0 ) cos( ) sin( 0
0 ) sin( ) cos( 0
0 0 0 1
(
(
1 0 0 0
0 ) cos( 0 ) sin(
(
(
1 0 0 0
0 ) cos( ) sin( 0
X-axis Y-axis
( ) ( )
( ) ( )
(
(
0 0
0 0
i
sin cos
( ) ( )
(
(
(
1 0 0 0
0 1 0 0
0 0 cos sin
Z-axis
(
1 0 0 0
Why is the sign reversed in one case ?
Y
Around
Z-axis
X
Around
Y-axis
Z
Around
X-axis Z axis Y axis X axis
X Z Y
Z
Around
(
0 0 0 1
X
Around
X-axis
(
(
(
0 ) cos( ) sin( 0
0 ) sin( ) cos( 0
Z
Y
Y
(
(
1 0 0 0
0 ) cos( ) sin( 0
Z
Y
Around
( ) ( )
( ) ( )
(
(
0 0 sin cos
Y
X
Around
Z-axis
( ) ( )
(
(
(
0 1 0 0
0 0 cos sin
Z
Y
X
(
1 0 0 0
X
Around
Y i
(
(
0 0 1 0
0 ) sin( 0 ) cos(
Y
X
Y-axis
(
(
(
1 0 0 0
0 ) cos( 0 ) sin(
0 0 1 0
Z
Y
Z
(
1 0 0 0
Rotation About an Arbitrary Axis in Space
Assume, we want to perform a rotation by
u d b t i i i u degrees, about an axis in space passing
through the point (x
0
, y
0
, z
0
) with direction
i ( ) cosines (c
x
, c
y
, c
z
).
1 First of all translate by: 1. First of all, translate by:
|T| = - (x
0
, y
0
, z
0
)
T
2 Next we rotate the axis into one of the 2. Next, we rotate the axis into one of the
principle axes, let's pick, Z (|R
x
|, |R
y
|).
3 We rotate next by u degrees in Z (|R (u)|) 3. We rotate next by u degrees in Z (|R
z
(u)|).
4. Then we undo the rotations to align the
axis axis.
5. We undo the translation: translate by
( x y z )
T
(-x
0
, -y
0
, -z
0
)
T
The tricky part of the algorithm is The tricky part of the algorithm is
in step (2), as given before.
This is going to take 2 rotations:
i) About x-axis )
(to place the axis in the xz plane)
and
ii) About y-axis
( l h l i id i h h (to place the result coincident with the
z-axis).
z
First step of Rotation:
c
y
p
d
PP
c
z
o
y
0
x
y
c
x
R t ti b t b Rotation about x by o:
How do we determine o? How do we determine o?
Project the unit vector, along OP, into j , g ,
the yz plane.
The y and z components, c
y
and c
z
, are
the direction cosines of the unit vector
l th bit i along the arbitrary axis.
It can be seen from the diagram, that : o g ,
C C + sqrt d
2 2
C
C C
z
z y
+ = sqrt d
] [ i
1
y
c
C
d
z
= cos ] [ sin
2 2
1
z y
y
c c +
=
d
C
y
= sin
z y
z
z
Af t er f i r st st ep
of Rot at i on
c
y of Rot at i on
d
y
c
x
P
c
z
o
|
P(c 0 d)
x
y
0
0
P(c
x
, 0, d)
x
y
c
y
0
d
c
x
x
Rotation by | about y: y | y
How do we determine |?
Steps are similar to that done for o: Steps are similar to that done for o:
Determine the angle | to rotate the
The x component is c
x
and the z
g |
result into the Z axis:
p
x
component is d.
cos(|)= d = d/(length of the unit vector) cos(|)= d = d/(length of the unit vector)
sin(|)= c
x
= c
x
/(length of the unit vector).
Final Transformation for 3D rotation, about an
bit i arbitrary axis:
M = |T| |R
x
| |R
y
| |R
z
| |R
y
|
-1
|R
x
|
-1
|T|
-1
| | |
x
| |
y
| |
z
| |
y
| |
x
| | |
Final Transformation matrix for 3D rotation,
b t bit i about an arbitrary axis:
M = |T| |R
x
| |R
y
| |R
z
| |R
y
|
-1
|R
x
|
-1
|T|
-1
x y z y x
0 0 1
(
x
where:
0 0 0 1
(
(
C
C
;
0 1 0
0 0 1
0
0
(
(
(
(
=
y
x
T
;
0 0
(
(
(
=
C
C
d
C
d
C
R
y
z
x
;
1 0 0 0
1 0 0
0
(
(
(
=
z
T
1 0 0 0
0 0
(
(
(
d
C
d
C
z
y
1 0 0 0
1 0 0 0
0 0
(
C d 0 0 sin cos
(
u u
;
0 0 1 0
0 0
(
(
(
=
C d
R
x
;
0 0 cos sin
0 0 sin cos
(
(
(
=
u u
u u
R
;
1 0 0 0
0 0
(
(
(
=
d C
R
x
y
;
1 0 0 0
0 1 0 0
(
(
(
=
z
R
1 0 0 0
(
1 0 0 0
M |T| |R | |R | |R | |R |
1
|R |
1
|T|
1
M = |T| |R
x
| |R
y
| |R
z
| |R
y
|
-1
|R
x
|
-1
|T|
-1
= [T R R ] [R ] [T R R ]
-1
= [T R
x
R
y
] [R
z
] [T R
x
R
y
]
1
= C [R
z
] C
-1
C [R
z
] C
A spec i al c ase of 3D r ot at i on:
R t ti b t i ll l t Rotation about an axis parallel to a
coordinate axis (say, parallel to X-axis):
M
X
= |T| |R
X
| |T|
-1
M
X
|T| |R
X
| |T|
Rotation About an Arbitrary Axis in Space
Assume, we want to perform a rotation by
u d b t i i i u degrees, about an axis in space passing
through the point (x
0
, y
0
, z
0
) with direction
i ( ) cosines (c
x
, c
y
, c
z
).
1 First of all translate by: 1. First of all, translate by:
|T| = - (x
0
, y
0
, z
0
)
T
2 Next we rotate the axis into one of the 2. Next, we rotate the axis into one of the
principle axes, let's pick, Z (|R
x
|, |R
y
|).
3 We rotate next by u degrees in Z (|R (u)|) 3. We rotate next by u degrees in Z (|R
z
(u)|).
4. Then we undo the rotations to align the
axis axis.
5. We undo the translation: translate by
( x y z )
T
(-x
0
, -y
0
, -z
0
)
T
z
z
Af t er f i r st st ep
of Rot at i on
c
y of Rot at i on
d
y
c
x
P
c
z
o
|
P(c 0 d)
x
y
0
0
P(c
x
, 0, d)
x
y
c
y
0
d
c
x
x
Final Transformation matrix for 3D rotation,
b t bit i about an arbitrary axis:
M = |T| |R
x
| |R
y
| |R
z
| |R
y
|
-1
|R
x
|
-1
|T|
-1
x y z y x
0 0 1
(
x
where:
0 0 0 1
(
(
C
C
;
0 1 0
0 0 1
0
0
(
(
(
(
=
y
x
T
;
0 0
(
(
(
=
C
C
d
C
d
C
R
y
z
x
;
1 0 0 0
1 0 0
0
(
(
(
=
z
T
1 0 0 0
0 0
(
(
(
d
C
d
C
z
y
1 0 0 0
1 0 0 0
0 0
(
C d 0 0 sin cos
(
u u
;
0 0 1 0
0 0
(
(
(
=
C d
R
x
;
0 0 cos sin
0 0 sin cos
(
(
(
=
u u
u u
R
;
1 0 0 0
0 0
(
(
(
=
d C
R
x
y
;
1 0 0 0
0 1 0 0
(
(
(
=
z
R
1 0 0 0
(
1 0 0 0
If i 2 i t i t d ( th If you are given 2 points instead (on the
axis of rotation), you can calculate the direction
i f th i f ll cosines of the axis as follows:
z z y y x x V
T
0
1
0 1
0 1
=
V | | /
0 0 1
V y y
V x x
c
c
x
| | /
| | /
0 1
0 1
=
=
V z z
V y y
c
c
y
|, | /
| | /
0 1
0 1
=
V. vector the of lenght the is V where
V z z
c
z
| |
|, | /
0 1
f g | |
Ref l ec t i on t hr ough an ar bi t r ar y pl ane g y p
Method is similar to that of rotation Method is similar to that of rotation
about an arbitrary axis.
M = |T| |R
x
| |R
y
| |R
fl
| |R
y
|
-1
|R
x
|
-1
|T|
-1
T does the job of translating the origin to
the plane. p
R
x
and R
y
will rotate the vector normal to
h fl i l ( h i i ) il i i the reflection plane (at the origin), until it is
coincident with the +Z axis.
R
fl
is the reflection matrix about X-Y
plane or Z=0 plane plane or Z=0 plane.
Spaces Spaces
Obj ect Space: Obj ect Space:
definition of objects. Also called
M d li Modeling space.
W ld S World Space:
where the scene and viewing g
specification is made
Eyespace (Normalized Viewing Space):
where eye point (COP) is at the origin where eye point (COP) is at the origin
looking down the Z axis.
3D I mage Space: 3D I mage Space:
A 3D Projective space. j p
Dimensions: [ -1:1] in X & Y, [ 0:1] in Z.
This is where image space hidden
surface algorithms work surface algorithms work.
Screen Space ( 2D) :
Range of Coordinates -
[0 : width] [0 : height] [0 : width], [0 : height]
Projections Projections
We will look at several planar geometric We will look at several planar geometric
3D to 2D projection:
Parallel Projections - Parallel Projections
Orthographic
Oblique Oblique
- Perspective
Projection of a 3D object is defined by Projection of a 3D object is defined by
straight projection rays (projectors)
emanating from the center of projection emanating from the center of projection
(COP) passing through each point of the
object and intersecting the projection plane. j g p j p
Cl assi f i c at i on of Geomet r i c Pr oj ec t i ons j
Planar geometric
projections
Parallel Perspective
Orthographic
Oblique
One-point
Two-
point
Top
(plan)
Cabinet
Other
Three-
(plan)
Front
l ti
Side
l ti
Axonometric
Cavalier point
elevation elevation
Isometric Other
Perspective Projections Perspective Projections
Distance from COP to projection
plane is finite. The projectors are not plane is finite. The projectors are not
parallel & we specify a center of
projection (COP) projection (COP).
Center of Projection is also called
the Perspective Reference Point the Perspective Reference Point
COP = PRP COP = PRP
Perspective foreshortening: Perspective foreshortening:
The size of the perspective
projection of the object varies inversely
with the distance of the object from the j
center of projection.
Vanishing Point: Vanishing Point:
The perspective projections of any
set of parallel lines that are not parallel set of parallel lines that are not parallel
to the projection plane converge to a
vanishing point.
Z-axis vanishing point g p
y
y
Z-axis
vanishing point
x
z
z
x
z
Projection
plane
Center of
projection
Projection Projection
Plane normal
Projection plane
x-axis
varnishing point
z-axis
varnishing point varnishing point varnishing point
C t f P j ti Center of Projection
Per spec t i ve Geomet r y and Camer a Model s Per spec t i ve Geomet r y and Camer a Model s
X or Y P(X,Y,Z)
PP
Z
x
p
or y
p
O (COP)
Z
ff
Per spec t i ve Geomet r y and Camer a Model s p y
F
P(X,Y,Z) X or Y
ZZ
( )
IP
X or Y
P(X,Y,Z)
PP
x
p
or y
p
(COP)
Z
O
Per spec t i ve Geomet r y and Camer a Model s
X or Y
P(X,Y,Z)
PP
Z
x
p
or y
p
PP
X or Y
P(X,Y,Z)
O (COP)
Z
f
PP
f
(COP)
x
p
or y
p
Z
O
( )
f
Equations of Perspective geometry, next ->
Y
y
X
x
Equations of
= = ;
Z
Y
f
y
;
Z
X
f
x
p p
Equations of
Perspective geometry
(
0 0 0 1
(
(
(
0 0 1 0
0 0 0 1
+
=
+
= ;
f Z
Y
f
y
;
f Z
X
f
x
p p
(
(
=
0 1 0 0
0 0 1 0
M
per
+ + f Z f f Z f
(
(
0 f 1 0 0
0 1 0 0
(
(
0 0 0 1
(
(
(
=
0 1 0 0
0 0 1 0
M
per
P = M
per
.P;
(
(
1 f 1 0 0
0 1 0 0
per
P M
per
.P;
where P = [X Y Z 1]
T
1 f 1 0 0
where, P = [X Y Z 1]
Generalized formulation of
perspective projection:
(COP) X or Y
PP
L
P(x
p
, y
p,
Z
p
)
Q
L
Z O
P(X,Y,Z)
(d
x
, d
y
, d
z
)
Z O
(0, 0, Z
p
)
Parametric eqn. of the line L between
COP d P COP and P:
COP + t(P-COP); 0 < t < 1.
Let the direction vector from (0, 0, Z
p
) to
p
COP be (d
x
, d
y
, d
z
),
and Q be the distance from (0, 0, Z
p
) to COP.
p
Then COP = (0, 0, Z
p
) + Q(d
x
, d
y
, d
z
).
The coordinates of any point on line L is:
X = Qd + (X- Qd )t; X = Qd
x
+ (X- Qd
x
)t;
Y = Qd
y
+ (Y- Qd
y
)t;
U i th diti Z Z t th i t ti
Z = (Z
p
+ Qd
z
) + (Z - (Z
p
+ Qd
z
))t;
Using the condition Z = Z
p
, at the intersection
of line L and plane PP:
) Qd (Z Z
Qd
t
z
+
=
Now subsitute to
obtain x and y
) Qd (Z Z
z p
+
obtain, x
p
and y
p
.
d
Z
d
Z X
x
p
x
+
Z Z
d d
x
z
p
z
p
=
1
Qd
Z Z
p
p
+
Qd
z
d d
d
d
Z
d
d
Z Y
y
p
y
+
Z Z
d d
y
p
z z
p
=
1
Qd
Z Z
z
p
+
Q
z
Generalized formula of perspective
projection matrix:
(
d d
projection matrix:
(
(
(
d
d
z
d
d
0 1
z
x
p
z
x
(
(
(
d
z
d
1 0
d d
y y
z z
(
(
=
d
z
d
1 0
M
2
z
p
z
(
(
(
+
=
Z
Z Z
0 0
M
p
2
p p
gen
(
(
(
Z
1
Qd Qd
p
z z
(
(
+ 1
Qd
Z
Qd
1
0 0
p
(
Qd Qd
z z
Special cases from the generalized formulation
of the perspective projection matrix
M t i Matrix
Type
Z
p
Q [d
x
, d
y
, d
z
]
M
orth
0 Infinity [0, 0, -1]
M d d [0 0 1] M
per
d d [0, 0, -1]
M
per
0 d [0, 0, -1]
If Q is finite, M
gen
defines a one-point
perspective projection in the above two cases perspective projection in the above two cases.
P ll l P j ti Parallel Projection
Distance from COP to projection
plane is infinite. p
Therefore, the projectors are parallel lines
& we need to specify a:
direction of projection (DOP)
Orthographic:
th di ti f j ti d th the direction of projection and the
normal to the projection plane are the same.
(direction of projection is normal to the (direction of projection is normal to the
projection plane).
Cl assi f i c at i on of Geomet r i c Pr oj ec t i ons j
Planar geometric
projections
Parallel Perspective
Orthographic
Oblique
One-point
Two-
point
Top
(plan)
Cabinet
Other
Three-
(plan)
Front
l ti
Side
l ti
Axonometric
Cavalier point
elevation elevation
Isometric Other
Projection
Projectors
j
Plane
(top view)
Projectors for
t i
for
side view
( )
top view
Projection
P j t f
Projection
Plane
(side view)
Projection
Plane
Projectors for
front view
( )
E l f O th hi P j ti
(front view)
Example of Orthographic Projection
Example of Isometric Projection:
Projection
plane
P j t Projector
P j ti Projection-
plane normal
Axonometric orthographic projections Axonometric orthographic projections
use planes of projection that are not
normal to a principal axis (they normal to a principal axis (they
therefore show multiple face of an
object.)
I t i j ti j ti l Isometric projection: projection plane
normal makes equal angles with each
principle axis. DOP Vector: [1 1 1].
All 3 axis are equally foreshortened
allowing measurements along the allowing measurements along the
axes to be made with the same scale.
Oblique projections : Oblique projections :
projection plane normal and the projection plane normal and the
direction of projection differ.
Plane of projection is normal to a Plane of projection is normal to a
Principle axis
Projectors are not normal to the
projection plane p j p
Example Oblique Projection Example Oblique Projection
Projection Projection
plane
y
Pr oj ec t or
z
x
Projection-plane normal
General oblique projection of a point/line: General oblique projection of a point/line:
y
P
|
l
o
x z
P(0, 0, 1) ( , , )
General oblique projection of a point/line: q p j p
Projection Plane: x-y plane; P is the
j i f (0 0 ) l projection of P(0, 0, 1) onto x-y plane.
`l is the projection of the z-axis unit l is the projection of the z-axis unit
vector onto x-y plane and o is the angle
th j ti k ith th i the projection makes with the x-axis.
When DOP varies both `l and o will When DOP varies, both l and o will
vary.
Coordinates of P: (l cos o, l sin o, 0).
As given in the figure: DOP is:
(d
x
, d
y
, -1) or (l cos o, l sin o, -1).
General oblique projection of a point/line:
Wh t i | ?
General oblique projection of a point/line:
What is | ?
y
P
|
l
o
x z
P(0, 0, 1) ( , , )
View Specifications: View Specifications:
VP, VRP, VUP, VPN, PRP, DOP, CW, VRC
v
VUP VUP
(u
max
, v
max
)
VP
VRP
CW
VP
u
VRP
u
VPN
(u
min
, v
min
)
nn
v
VRP
CW VP
VRP
CW VP
u
VPN
n
COP/PRP /
Semi-infinite pyramid view volume Semi infinite pyramid view volume
for perspective projection
BCP
VP
DOP
VRP
DOP
FCP
Finite pyramid
view volume for VPN
perspective projection
VP VP
CW
DOP
VRP
DOP
VPN PRP
n
Infinite parallelopiped view volume
for parallel projection
Finite parallelopiped
view volume for
parallel projection
BCP
VP
DOP
VRP
FCP
VPN