You are on page 1of 55

Three - Dimensional

Graphics

Three-Dimensional
ee
e s o a Graphics
G ap cs

Use of a right-handed coordinate


(consistent with math)

Left-handed suitable to screens.


screens

system

To transform from right


g
to left, negate
g
the
z values.

Right
g
Handed Space
p

Left Handed Space


p

Homogeneous representation of a
point in 3D space:
po
p

P | x y z w |

(w 1, for a 3D point)
Transformations will thus be
represented by 4x4 matrices:
P = A.P

Transformation Matrix in 3D:

a b
d e
A
g i

l m

a b

d e
g i

c
f
j
n

where,

c produces linear transformations:

li
shearing,
h
i
reflection
fl ti
f scaling,
and rotation.
j
K = [p q r]T, produces translation

= [l m n]T, yields perspective transformation


while,
hil

s, is
=
i responsible
ibl for
f
uniform
if
scaling
li

1
0
0
0

0
1
0
0

0 t x Sx
0 ty 0
1 tz 0

0 1 0

Translation

1
0

Sh x

Sh y

Sh z

0
Sy
0
0

0
0
Sz
0

0
0
0
1

Scale

0
Shear

0
0
Origin is unaffected

by scale and shear


1

3D Reflection:
3
e ect o
The following matrices:

1
0
TXY
0

0 0 0
1

1 0 0
0

TYZ
0
0 1 0

0 0 1
0

0 0 0
1

1 0 0
0

TZX
0
0 1 0

0 0 1
0

0 0 0

1 0 0
0 1 0

0 0 1

produce reflection about:


XY
plane

YZ
plane
respectively.
p
y

ZX
plane

Rotation Matrices along


g an axis:

0
0
1
0 cos( ) sin( )
0 sin( ) cos( )
0
0
0

0
0
0
1

cos(( )
0
sin( )
0

X-axis

cos sin
sin
i cos
0
0
0
0

0 sin(( ) 0
1
0
0
0 cos( ) 0
0
0
1
Y-axis

0
0
1
0

0
0
0
1

Z-axis

Why is the sign reversed in one case ?

Around
Z-axis
Z
axis
X

Around
X-axis
X
axis
Y

Around
Y-axis
Y
axis
Z

Around
X-axis
Y

Around
Z-axis
X

Around
Y
Y-axis
i
Z

0
0
1
0 cos( ) sin( )
0 sin( ) cos( )
0
0
0

0 X
0 Y
0 Z
1

cos sin
sin cos
0
0
0
0

0 X
0 Y
0 Z
1

cos( )
0
sin( )
0

0
0
1
0

0 sin( ) 0 X
1
0
0 Y
0 cos( ) 0 Z
0
0
1

Rotation About an Arbitrary Axis in Space

Assume, we want to perform a rotation by

degrees, about
d
b t an axis
i in
i
space passing
i
through the point (x0, y0, z0) with direction
cosines
i
( x, cy, cz).
(c
)
1 First of all
1.
all, translate by:
|T| = - (x0, y0, z0)T
2 Next,
2.
Next we rotate the axis into one of the
principle axes, let's pick, Z (|Rx|, |Ry|).

3. We rotate next by degrees in Z (|Rz()|).


3
)|)
4. Then we undo the rotations to align the
axis.
axis
5. We undo the translation: translate by
( x0, -y
(-x
y0, -z
z0)T

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
( place
(to
l
the
h result
l coincident
i id
with
i h the
h
z-axis).

First step
p of Rotation:
cy
d

cz

0
y
x

cx
R t ti
Rotation
about
b t x by
b :
How do we determine ?

Project
j
the unit vector,, along
g OP,, into
the yz plane.
The y and z components, cy and cz, are
the direction cosines of the unit vector
along
l
th arbitrary
the
bit
axis.
i
o the diagram,
g
, that :
It can be seen from

d sqrt C C
Cz
cos
d
Cy
sin
d
2
y

2
z

sin
i [
1

cy
c c
2
y

2
z

After first step


of Rotation

cy
d

cx
0
P(cx, 0,
0 d)
x

cx

0
d

cz

Rotation by
y about y
y:
How do we determine ?
Steps are similar to that done for :
Determine the angle
g to rotate the
result into the Z axis:
The x component
p
is cx and the z
component is d.
cos()= d = d/(length of the unit vector)
sin()= cx = cx/(length of the unit vector).
Final Transformation for 3D rotation, about an
arbitrary
bit
axis:
i

M = ||T|| |R
| x| |R
| y| |R
| z| |R
| y|-1 ||Rx|-1 ||T||-1

Final Transformation matrix for 3D rotation,


about
b t an arbitrary
bit
axis:
i

M = |T| |Rx| |Ry| |Rz| |Ry|-1 |Rx|-1 |T|-1


where:

1
0
T
0

d
0
Ry
Cx

1
0

0
1

x0

y0
;
z0

0 C x 0

1 0 0
;
0 d 0

0 0 1

0
1
Cz
0
Rx C d
y
0

d
0
0

0
Cy

Cz

d
0

cos sin
sin cos
Rz
0
0

0
0

0
;
0
1

0 0

0 0
;
1 0

0 1

M = |T| |Rx| |Ry| |Rz| |Ry|-11 |Rx|-11 |T|-11


= [T Rx Ry] [Rz] [T Rx Ry]-11
=

C [Rz] C-1

A special case of 3D rotation:


Rotation
R
t ti
about
b t an axis
i parallel
ll l to
t a
coordinate axis (say, parallel to X-axis):

MX = |T| |RX| |T|-1

Rotation About an Arbitrary Axis in Space

Assume, we want to perform a rotation by

degrees, about
d
b t an axis
i in
i
space passing
i
through the point (x0, y0, z0) with direction
cosines
i
( x, cy, cz).
(c
)
1 First of all
1.
all, translate by:
|T| = - (x0, y0, z0)T
2 Next,
2.
Next we rotate the axis into one of the
principle axes, let's pick, Z (|Rx|, |Ry|).

3. We rotate next by degrees in Z (|Rz()|).


3
)|)
4. Then we undo the rotations to align the
axis.
axis
5. We undo the translation: translate by
( x0, -y
(-x
y0, -z
z0)T

After first step


of Rotation

cy
d

cx
0
P(cx, 0,
0 d)
x

cx

0
d

cz

Final Transformation matrix for 3D rotation,


about
b t an arbitrary
bit
axis:
i

M = |T| |Rx| |Ry| |Rz| |Ry|-1 |Rx|-1 |T|-1


where:

1
0
T
0

d
0
Ry
Cx

1
0

0
1

x0

y0
;
z0

0 C x 0

1 0 0
;
0 d 0

0 0 1

0
1
Cz
0
Rx C d
y
0

d
0
0

0
Cy

Cz

d
0

cos sin
sin cos
Rz
0
0

0
0

0
;
0
1

0 0

0 0
;
1 0

0 1

If you are given


i
2 points
i t instead
i t d (on
(
the
th
axis of rotation), you can calculate the direction
cosines
i
off th
the axis
i as follows:
f ll

V x1 x 0

z z
1

c x x / |V |
c y y / |V |
c z z / | V |,
x

where | V | is the lenght


g off the vector V.

Reflection through
g an arbitrary
y plane
p
Method is similar to that of rotation
about an arbitrary axis.

M = |T| |Rx| |Ry| |Rfl| |Ry|-1 |Rx|-1 |T|-1


T does the job of translating the origin to
the plane.
p
Rx and Ry will rotate the vector normal to
the
h reflection
fl
i
plane
l
(
(at the
h origin),
i i ) until
il iit iis
coincident with the +Z axis.
Rfl is the reflection matrix about X-Y
plane or Z=0 plane.
plane

Spaces
Object Space:
definition of objects. Also called
M d li
Modeling
space.
W ld S
World
Space:
g
where the scene and viewing
specification is made
Eyespace (Normalized Viewing Space):
where eye point (COP) is at the origin
looking down the Z axis.

3D Image Space:
A 3D Projective
j
space.
p
Dimensions: [-1:1] in X & Y, [0:1] in Z.
This is where image space hidden
surface algorithms work.
work
Screen Space (2D):
Range of Coordinates [0 : width],
width] [0 : height]

Projections
We will look at several planar geometric
3D to 2D projection:
- Parallel Projections
Orthographic
Oblique
- Perspective

Projection of a 3D object is defined by


straight
projection
rays
(projectors)
emanating from the center of projection
(COP) passing through each point of the
object
j
and intersecting
g the p
projection
j
plane.
p

Classification of Geometric Projections


j
Planar geometric
projections
Parallel

Perspective
Oblique

Orthographic

Cabinet

Top
(plan)
Front
elevation
l
ti

Side
elevation
l
ti

Axonometric

Isometric

Other

One-point

Twopoint

Other
Cavalier

Threepoint

Perspective Projections
Distance from COP to projection
plane is finite. The projectors are not
parallel & we specify a center of
projection (COP).
(COP)
Center of Projection is also called
the Perspective Reference Point

COP = PRP

Perspective foreshortening:
The
size
of
the
perspective
projection of the object varies inversely
j
from the
with the distance of the object
center of projection.
Vanishing Point:
The perspective projections of any
set of parallel lines that are not parallel
to the projection plane converge to a
vanishing point.

Z-axis vanishing
g point
p

Z-axis
vanishing point

x
z

x
z

Projection
plane

Center of
projection

Projection
Plane normal

Projection plane

x-axis
varnishing point

z-axis
varnishing point
C t off P
Center
Projection
j ti

Perspective Geometry and Camera Models

X or Y

P(X,Y,Z)
PP
xp or yp

O (COP)
f

Perspective
p
Geometry
y and Camera Models

X or Y

P(X,Y,Z)

IP

X or Y

P(X,Y,Z)
(
)

PP
xp or yp
(COP) O

Perspective Geometry and Camera Models


X or Y

P(X,Y,Z)

PP
xp or yp
O (COP)

X or Y
Z

P(X,Y,Z)

PP

xp or yp
O

(COP)
(
)

Equations of Perspective geometry, next ->

xp

X ;
f
Z

1
0
Mper
0

yp

Y ;
f
Z

0
0 1 0

0 1 f 0

0
1

0
0

P = Mper.P;
P
where P = [X Y Z 1]T
where,

Equations of
Perspective geometry

xp

X yp
Y

;
;
f Zf f Zf

Mper

1
0

0
0

0 1 f 1

0
1
0

0
0
1

Generalized formulation of
perspective projection:

X or Y

PP

(COP)
L
Q

P(xp, yp, Zp)


P(X,Y,Z)

(dx, dy, dz)


O

(0, 0, Zp)

Parametric eqn. of the line L between


COP and
dP
P:
COP + t(P-COP); 0 < t < 1.

Let the direction vector from (0, 0, Zp) to


COP be (dx, dy, dz),
and Q be the distance from (0, 0, Zp) to COP.
Then COP = (0, 0, Zp) + Q(dx, dy, dz).
The coordinates of any point on line L is:
X = Qdx + (X- Qdx)t;
X
Y = Qdy + (Y- Qdy)t;
Z = (Zp + Qdz) + (Z - (Zp + Qdz))t;
Using
U
i
the
th condition
diti
Z
Z = Zp, att the
th intersection
i t
ti
of line L and plane PP:

Qd z
t
Z (Z p Qd z )

Now subsitute to
obtain xp and yp.
obtain,

dx
dx
X Z Zp
dz
dz
xp
Zp Z
1
Qdz
dy
dy
Y Z
Zp
dz
dz
yp
Zp Z
1
Qd z
Q

Generalized formula of perspective


projection matrix:

M gen

0
1
0
0

dx

dz
dy

dz
Zp

Qd z
1

Qd z

dx
zp

dz

dy
zp
dz

2
Zp

Zp

Qd z

Zp
1

Qd z

Special cases from the generalized formulation


of the perspective projection matrix

Matrix
M
t i
Type

Zp

[dx, dy, dz]

Morth

Infinity

[0, 0, -1]

Mper

[0 0,
[0,
0 -1]
1]

Mper

[0, 0, -1]

If Q is finite, Mgen defines a one-point


perspective projection in the above two cases.
cases

P
Parallel
ll l Projection
P j ti
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 direction
the
di
ti
off projection
j ti
and
d the
th
normal to the projection plane are the same.
(direction of projection is normal to the
projection plane).

Classification of Geometric Projections


j
Planar geometric
projections
Parallel

Perspective
Oblique

Orthographic

Cabinet

Top
(plan)
Front
elevation
l
ti

Side
elevation
l
ti

Axonometric

Isometric

Other

One-point

Twopoint

Other
Cavalier

Threepoint

Projection
j
Plane
((top view))
Projectors for
top
t view
i

Projection
Plane
(front view)

Projectors
P
j t
for
f
front view

Projectors
for
side view

Projection
Plane
((side view))

Example
E
l off Orthographic
O th
hi Projection
P j ti

Example of Isometric Projection:


Projection
plane
P j t
Projector

ProjectionP
j ti
plane normal

Axonometric orthographic projections


use planes of projection that are not
normal to a principal axis (they
therefore show multiple face of an
object.)
Isometric
I
t i projection:
j ti
projection
j ti
plane
l
normal makes equal angles with each
principle axis. DOP Vector: [1 1 1].
All 3 axis are equally foreshortened
allowing measurements along the
axes to be made with the same scale.

Oblique projections :
projection plane normal and the
direction of projection differ.
Plane of projection is normal to a
Principle axis
Projectors are not normal to the
projection
p
j
p
plane

Example Oblique Projection

Projection
y
plane

Projector

Projection-plane normal

General oblique projection of a point/line:


y
P

( , 0,, 1))
P(0,

General oblique
q projection
p j
of a point/line:
p
Projection Plane: x-y plane; P is the
projection
j
i
off P(0,
(0 0
0, 1)
) onto x-y plane.
l
l is the projection of the z-axis unit
`l
vector onto x-y plane and is the angle
th projection
the
j ti
makes
k
with
ith the
th x-axis.
i
When DOP varies,
varies both `l
l
vary.

and

will

Coordinates of P: (l cos , l sin , 0).


As given in the figure: DOP is:
(dx, dy, -1) or (l cos , l sin , -1).

General oblique projection of a point/line:


Wh t is
What
i

y
P

( , 0,, 1))
P(0,

View Specifications:
VP, VRP, VUP, VPN, PRP, DOP, CW, VRC
v
VUP
(umax, vmax)

VP
CW

VRP
u

(umin, vmin)

VPN

VP

CW

VRP
u

VPN
n

COP/PRP
/

Semi infinite pyramid view volume


Semi-infinite
for perspective projection

BCP

VP
DOP

VRP

FCP
VPN

Finite pyramid
view volume for
perspective projection

VP
CW
DOP
PRP

VRP
VPN
n

Infinite parallelopiped view volume


for parallel projection

Finite parallelopiped
view volume for
parallel projection

BCP

VP
DOP

VRP

FCP
VPN

You might also like