You are on page 1of 38

Computer Graphics

Three dimensional transformations
contents
 Introduction
 Translation
 Scaling
 scaling in 3D relative to the coordinate origin
 Scaling relative to fixed point
 Rotation
 Rotation about the X-Axis
 Rotation about the Y-Axis
 Rotation about the Z-Axis
 Rotation about an arbitrary axis
 Rotation axis is parallel to one of the coordinate axes
 Rotation axis is not parallel to one of the coordinate axes
 Shearing
 X-Shearing
 Y-Shearing
 Z-Shearing
introduction
Transformations are very useful in computer graphics in a number of
situations:
 A scene can be fashioned by placing a number of instances of an
object at different places and with different sizes using proper
transformation.
 Helps a designer to view an object from different points and make a
picture from each one.
 In a computer animation, several objects must move relative to one
another from frame to frame.
 Sometimes we need to reduce the size of an object or To place it
into a larger displays .
• these various manipulations are carried out by applying appropriate
geometric transformation
Translation

• In 3d Homogeneous Coordinate
representation,a point is translated from
position (x,y,z) to position (x’,y’,z’)with the
translation matrix :
1 0 0 Tx 
0 
1 0 Ty 
T
0 0 1 Tz 
 
0 0 0 1
Translation

Parameter Tx,Ty,Tz,specifying translation


distances for the coordinate, are assigned any
real value .
The next matrix is equivalent to the
Three equations:
X’ = x + Tx
Y’ = y + Ty
Z’ = z + Tz
Translation
 x 1 0 0 tx   x 
 y  0 1 0 ty  y
   
 z   0 0 1 tz   z 
    
 1  0 0 0 1 1
An object is translated in three dimensions by
transforming each defining point of the object .
Translation of an object represented as a set of polygon
surfaces is carried out by translating the coordinate
values for each vertex of each surface .
The set of translated coordinate positions for the
vertices then defines the new position of the object.
Translation

y
(x’,y’,z’) y

(x,y,z) T=(Tx,Ty ,Tz ) (x’,y’,z’)

T=(Tx,Ty ,Tz )
(x,y,z)

z x

z x
Translating a point with translation vector T=(Tx,Ty ,Tz )

Translating an object with translation vector T


scaling

The scaling matrix is


 Sx 0 0 0
 0 Sy 0 0
S
 0 0 Sz 0
 
0 0 0 1

Where scaling parameters Sx,Sy and Sz are assigned any


positive values
The matrix operation for scaling in 3D relative to the
coordinate origin is

 x   Sx 0 0 0  x 
 y  0 Sy 0 0  y 
   
 z    0 0 Sz 0  z 
    
 1   0 0 0 1  1 
This matrix is equivalent to the
Three equations:

X’ = x . Sx
Y’ = y . Sy
Z’ = z . Sz
scaling

when transformation is applied to defining points in an


object , the object is scaled and moved relative to
coordinate origin.
y

z x
scaling

If transformation parameters are not all equal


then the object are also changed

Uniform scaling (Sx = Sy =Sz)


preserves the original shape of an
object .
Scaling relative to fixed point

1. Translate the fixed point to the origin


with
 1 0 0 0
 0 1 0 0
T 
 0 0 1 0
 
  Tx  Ty  Tz 1
2. Scale with
 Sx 0 0 0
0 Sy 0 0
S 
0 0 Sz 0
 
0 0 0 1
scaling

3 -Translate the fixed point back to its the


original position with 1 0 0 0
0 1 0 0
T 
0 0 1 0
 
Tx Ty Tz 1
To produce
 Sx 0 0 0
 0 Sy 0 0
S  
 0 0 Sz 0
 
(1  Sx ) Xf (1  Sy )Yf (1  Sz ) Zf 1
Rotation

Must designate an axis of rotation (about which


the object is to be rotate).
The amount of angular rotation.
Positive values for the angle indicate a
Z
counterclockwise rotation.
Negative values for the angle rotate

objects in clockwise direction. 


 Y

X
Rotation about the X-Axis

Rx ;
Rotation about the Y-Axis

Ry ;
Rotation about the Z-Axis

Rz ;
Rotation about an arbitrary
axis

when the selected rotation axis is parallel to


one of the coordinate axes
1. Translate the object so that the rotation axis coincides with the
parallel coordinate axis.
2. Perform the specified rotation.
3. Translate the object so that the rotation axis is moved back to
its original position .
Rotation about an arbitrary
axis
y
y

Rotation axis

z x
x
z
A - Original position of object B - Translate rotation axis onto x axis
Rotation about an arbitrary
axis
y
y

Rotation axis
z x
x
z

C- Rotation object through angle D - Translate rotation axis to original position


Rotation about an arbitrary
axis
•when the selected rotation axis is not parallel to
one of the coordinate axes.
•We can determine the form of the transformation matrices using
standard vector operation .
•A Vector can be defined as a directed line between two point .
•An axes of rotation can be defined by specifying any vector along
the axis.
•It is convenient to deal with vectors specified relative to the
coordinate origin .
Vector addition

V1 +V2 =( x1+x2 , y1+y2 , z1+z2 )


Y Y
V2+V1
V2= (x2,y2,z2) V2

V1= (x1,y1,z1) V1

X X
Z Z
vectors specified relative
Vector addition
to the coordinate origin .
Vector multiplication

There are to ways :


1 – multiply two vectors to produce a single numeric value
(called the scalar product or dot product).
2- we can produce another vector
(called the vector product or cross product).

the scalar product of two vectors:


V1 .V2 =x1. x2 +y1. y2 +z1. Z2

The length of scalar product vector

v =(v.v)**.5 = ( x . x + y. y+ z . z) **.5

V1 .V2 = V1 V2 cos(ө)
Vector multiplication

the vector product of two vectors:

V1* V2 =u v1 v2 sinө

 ux uy uz 
 x1 y1 z1 
 
V1* V2 =  x2 
y2 z2
 
 
the Vector product produces a Vector with components :
(y1z2 – z1y2 , z1x2 - x1z2 , x1y2 – y1x2 )
Transformation matrices

1. Translate the object so that the rotation axis passes through the
coordinate origin.
2. Rotate the object so that the axis of rotation coincides with one of the
coordinate axis .
3. Perform the specified rotation .
4. Apply inverse rotations to bring the rotation axis back to its original
orientation .
5. Apply the inverse translation to bring the rotation axis back to its
original position.
Rotation about an arbitrary
axis
We can transform the rotation axis onto any of the three coordinate axes
For getting the rotation axis onto the z axis.
assume that the rotation axis is defined by two points as following :

V =(x2- x1 , y2 – y1 , z2 – z1 )
y
(x2,y2,z2)

U= v = (a, b,c)
v
u
(x1,y1,z1)
A= xv
B= yv
z x
C = zv
Rotation about an arbitrary
axis
1. Translate the object so that the rotation axis passes through the coordinate origin
Is accomplished with the translation matrix
 1 0 0 0
 0 1 0 0
T 
 0 0 1 0
 
 X 1  Y1  Z1 1

Next we need the transformations that will put the rotation axis on the z axis.
In two steps :
a- rotate about the x axis so that vector u is in the xz plane .
b- rotate about the y axis to bring u onto the z axis
Rotation about an arbitrary
axis
y
y

z x
z u x

A - Unit vector u is rotated B – then the rotate about


abut the x axis to bring it into the y axis to align it with
the xz plane the z axis
Rotation about an arbitrary
axis
To determine the angle of the rotation about x axis :
The rotation angle is the angle between the projection of u in the yz plane
( u’) And the positive z axis (u’ = (0,b,c)) then

u '.u z c y
cos( )  
u' uz d
U’ = (0,b,c) U = (a ,b,c)
d  (b.b  c.c) 1/ 2


u 'u z  u x u ' u z sin( )
b z u z= (0 ,0,c) x
sin( ) 
d
Rotation about an arbitrary
axis
Now after determine sin( ) and cos( ) we Can evaluate the rotation
Matrix about the x axis as

1 0 0 0
 c b 
0 d d
0
RX ( )   b c 
0  0
 d d 
0 0 0 1
Rotation about an arbitrary
axis
To determine the angle of the rotation about y axis

u ' '.u z
cos( )  d y
u' ' uz
u ' 'u z  u y u ' ' u z sin( ) 
u ' 'u z  u y .( a ) u z =(0,0,c)

sin(  ) = - a z x
U’’ =(a,0,d)
Rotation about an arbitrary
axis
The transformation matrix for rotation about the y axis is
d 0 a 0
0 1 0 0
R y ( )  
 a 0 d 0
 
0 0 0 1
Now can be applied rotation about the z axis

cos( )  sin( ) 0 0
 sin( ) cos( ) 0 0
Rz ( )  
 0 0 1 0
 
 0 0 0 1
Rotation about an arbitrary
axis

The transformation matrix for rotation about an arbitrary axisCan be


expressed as the composition of these seven individiual transformation

R ( )  T RX ( ) R y ( ) Rz ( ) R y 1 ( ) RX 1 ( ) 1
T
Shearing
A shear transformation consists of shearing in each of the
three coordinate planes: the XY, XZ, and YZ planes.
A shear in the XY plane translates every plane parallel to
the XY plane by an amount in x and y proportional to the
z value of that plane.
X-Shearing

• X-shearing a
point

• The X-shear transformation matrix can be defined by

Parameters a and b can be


assigned any real value
Y-Shearing

• Y-shearing a point

• The Y-shear transformation matrix can be defined by


Z-Shearing

• Z-shearing a point

• The Z-shear transformation matrix can be defined by


References

1 - Donald Hearn – M.Pauline Baker -Computer graphics


http://www.mtsu.edu/~csjudy/4250/3DTransformations.ppt#7
http://www.spacegear.org/reference/3DGraphics.pdf
http://www.cse.iitd.ernet.in/~pkalra/cs474/slides/3D-transform.PDF
http://www.cs.berkeley.edu/~ug/slide/pipeline/assignments/as5/transforms3d.
shtml#xforms
http://www.cs.toronto.edu/~faisal/teaching/notes/csc418/faisal/topics04.html
http://www-lehre.informatik.uni-
osnabrueck.de/~mm/skript/7_3_3D_Transformation.html
http://www.ruthless.zathras.de/facts/apps/polygonesia/3d-transformation-
matrix.php
http://www.cse.ohio-state.edu/~hwshen/581/3d_transform.ppt#1
http://www.iro.umontreal.ca/~paquetse/knoweb/linear_3d_transformation.htm
l

You might also like