Tải bản đầy đủ (.pdf) (48 trang)

Lecture computer graphics and virtual reality slides lesson 5 modeling transformation

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.15 MB, 48 trang )

Lesson 5

Modeling
Transformation

Trinh Thanh Trung School of ICT, HUST

Content

1. Transformation
2. 2D modeling transformation
3. Homogenous transformation
4. 3D modeling transformation

1.
Transformation

Transformation Definition

■ What is a transformation?

□ P′=T(P)
□ Transform the coordinates / normal vectors of

objects

■ Uses

□ Moving the objects to the desired location in the
environment


□ Multiple instances of a prototype shape
□ Kinematics of linkages/skeletons – character

animation
□ Viewing
□ Virtual camera: parallel and perspective projections

Types of transformation

■ Object Transformation alters the coordinates of
each point according to some rule, leaving the
underlying coordinate system unchanged

■ Coordinate Transformation produces a
different coordinate system, and then represents all
original points in this new system

Stages of transformation

Model MODELING World VIEW Display

Coordinate TRANSFORMS Coordinate TRANSFORMS Coordinate
System System System

PROJECTION Projection
Coordinate
TRANSFORMS
System

Modeling

Transformation

View
Transformation

Projection
Transformation

Affine transformation

■ Whole collections of points may be transformed
by the same transformation T, e.g. lines or circles
■ The image of a line, L, under T, is the set of all
images of the individual points of L.
■ For most mappings of interest, this image is still
a connected curve of some shape
■ For some mappings, the result of transforming a
line may no longer be a line
■ Affine Transformations, however, do preserve
lines, and are the most commonly-used
transformations in computer graphics

Affine transformation properties

■ Preservation of lines:

□ They preserve lines, so the image of a straight line is
another straight line.

□ This vastly simplifies drawing transformed line

segments.

□ We need only compute the image of the two
endpoints of the original line and then draw a
straight line between them

Affine transformation properties

■ Preservation of co-linearity

□ Guarantees that polygons will transform into
polygons

■ Preservation of parallelism

□ Guarantees that parallelograms will transform into
parallelograms

■ Preservation of proportional distances

□ Mid-points of lines remain mid-points

Affine transformation

■ Any Affine transformation can be decomposed
into elementary transformations
1. Translation
2. Scaling
3. Rotation
4. Shearing


2.
2D transformations

Matrix representation

■ All affine transformations in 2D can be
generically described in terms of a generic equation
as follows:

Qx  a b Px  tx 
  =   +  
Qy  c
d Py  t y 

■ or

Q = MP + t

Translation

■ A translation moves an object into a different
position in a scene

xnew = xold + tx ynew = yold + ty

y 1 2 3 4 5 6 7 8 9 10 x

6 Note: House shifts position relative to origin
5

4
3
2
1

0

Translation

■ Translation is achieved by adding an offset/

translation vector  tx 

t= 
 ty 

■ In Vector notations

Q  x   P  =  x  t  +  x 
Qy  Py  t y 

P’ = P + T / x/  tx  Transformation
x P =  / T =  matrix

P=   y  ty 
y

Scaling

■ Scaling multiplies all coordinates


□ Alters the size of an object

xnew = Sx × xold ynew = Sy × yold

y

6

5

4

3 6 9

3 3
 
2

1 2 3

1 1
 

0

1 2 3 4 5 6 7 8 9 10 x

Note: House shifts position relative to origin


Scaling

■ A scaling changes the size of an object with two
scale factors, Sx and Sy

□ if Sx != Sy, then we have a non-uniform scale

Qx   Px  Sx 
  = 
Qy  Py  S y 

P’ = S.P x / x/ 
P =   P = /
y  y 

sx 0 
□ Transformation matrix S= 
0 sy 

Rotation

■ To generate a rotation, a rotation angle θ and
the position (xr, yr ) of the rotation point is needed

x = r cos , y = r sin 

y x’ = r cos ( + ), y’ = r sin ( + )

6 x’ = r ( cos cos - sin sin )


5

4 = x cos - y sin

3 y’ = r ( sin cos + cos sin )

2 = x sin + y cos

1 

 x

0

1 2 3 4 5 6 7 8 9 10


×