Unit - III 2D-Transformation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 48

Unit – III

2D- Transformation
Transformations
 What ? :
The geometrical changes of an object from a current state to modified state.

 Why ?
To manipulate the initially created object and to display the modified object
without having to redraw it.

Types of Transformation:
1. Basic Transformation
- Translation
- Scaling
- Rotation
2. Other Transformation
- Reflection
- - Shearing
Basic 2D Transformations

 Translation:
• A translation moves all points in
an object along the same
?
straight-line path to new
positions.
• The path is represented by a ty=4
vector, called the translation or
shift vector. (2, 2) tx = 6
• We can write the components:
p'x = px + tx
p'y = py + ty x’ x t
= + x
• or in matrix form: y’ y ty

P' = P + T
Basic Transformation

 To move a line segment, apply the transformation


equation to each of the two line endpoints and
redraw the line between new endpoints.

 To move a polygon, apply the transformation


equation to coordinates of each vertex and
regenerate the polygon using new set of vertex
coordinate
Basic 2D Transformations
 Scaling:
• Scaling changes the size of an
P’ object and involves two scale
factors, Sx and Sy for the x- and
y- coordinates respectively.
• Scales are about the origin.
P
• We can write the components:
• p'x = sx • px
• p'y = sy • py
• or in matrix form:
• P' = S • P
• Scale matrix as: S   s x 0 
0 s 
 y
Basic 2D Transformations
 If the scale factors are in between 0
and 1  the points will be moved
closer to the origin  the object will
be smaller.
P(2, 5)
Example : If P(2, 5), Sx = 0.5, Sy = 0.5
then Find P’ ?
 If the scale factors are larger than 1 P’

 the points will be moved away


from the origin  the object will be
larger.
Example : If P(2, 5), Sx = 2, Sy = 2 then
Find P’ ?
Basic 2D Transformations

 If the scale factors are the


P’
same, Sx = Sy  uniform
scaling  Only change in size

 If Sx  Sy  differential
scaling Change in size and
shape P(1, 2)

Example : square  rectangle


• P(1, 3), Sx = 2, Sy = 5 , P’ ?
Basic 2D Transformations

 Rotation:
• A rotation repositions
P’
all points in an object
along a circular path in

the plane centered at
the pivot point. P

• First, we’ll assume the


pivot is at the origin.
Basic 2D Transformations
=> cos  = x/r , sin = y/r
• x = r. cos , y = r.sin 

P’(x’, y’)
=> cos (+ ) = x’/r
• x’ = r. cos (+ ) 
• x’ = r.coscos -r.sinsin r
y’
• x’ = x.cos  – y.sin  P(x,y)
 r y
=>sin (+ ) = y’/r 
x
y’ = r. sin (+ ) x’
Identity of Trigonometry
• y’ = r.cossin + r.sincos
• y’ = x.sin  + y.cos 
Basic 2D Transformations

It can be written as:


p'x = px cos  – py sin 
p'y = px sin  + py cos  P’(x’, y’)
or in matrix form:
• P' = R • P 
 can be clockwise (-ve) or r
y’
counterclockwise (+ve as our P(x,y)
example).  r y
• Rotation matrix 
x’ x
cos   sin  
R
 sin  cos  
Matrix Representations and
Homogeneous Coordinates
 To produce a sequence of operations, such as scaling followed by
rotation then translation, we could calculate the transformed
coordinates one step at a time

 A more efficient approach is to combine transformations, without


calculating intermediate coordinate values

 Multiplicative and translational terms for a 2D geometric


transformation can be combined into a single matrix if we expand
the representations to 3 by 3 matrices.

 We can use the third column for translation terms, and all
transformation equations can be expressed as matrix multiplications
Homogeneous Coordinates
y y
w
x 
x

 Let’s move our problem into 3D.


 Let point (x, y) in 2D be represented by point (x, y, 1) in the
new space.
 Scaling our new point by any value a puts us somewhere
along a particular line: (ax, ay, a).
 A point in 2D can be represented in many ways in the new
space.
 (2, 4) ---------- (8, 16, 4) or (6, 12, 3) or (2, 4, 1) or etc.
Homogeneous Coordinates

 We can always map back to the original 2D point by


dividing by the last coordinate
 (15, 6, 3) --- (5, 2).

 The fact that all the points along each line can be
mapped back to the same point in 2D gives this
coordinate system its name – homogeneous
coordinates.
2D Transformations with Homogeneous
Coordinates
•2D  Translation Matrix is as follows

2D Scaling Matrix becomes as :

2D Rotation Matrix becomes as :


Rotation About an Arbitrary Point
• It
  performs following operations
a. Translate (pivot point to origin)
b. Rotation about origin
c. Retranslate (pivot point to original position)

.
Composite Transformation

 We can setup a sequence of transformations as a


composite transformation matrix by calculating the
product of the individual transformations
P’=M2·M1·P
P’=M·P
Scaling with respect to an arbitrary point
Scaling with respect to an arbitrary
point
•1.   Translation
2. Scaling
3. Retranslation

.
Reflection

1 0 0 
x-axis y-axis
0  1 0 
 
0 0 1

  1 0 0
 0 1 0
 
 0 0 1
Origin Line x = y
  1 0 0
 0  1 0
 
 0 0 1

0 1 0 
1 0 0 
 
0 0 1
Shearing

• Shear : Transformation that distorts the shape of


an object such that the transformed shape appears
as the object was composed of internal layers that
had been caused to slide over each other
y y

(2,1) (3,1)
(0,1) (1,1)

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


x (0,0) x
shx=2
•  X-shear : An x-direction shear relative to the x axis

 Y-shear: An y-direction shear relative to the y axis


Unit – IV
Geometric Transformation
3D Transformation
• An additional z- co-ordinate is added in a 3rd dimension.

• One for height(y), one for width(x) and the third(z) for the
depth.

• These three axis can be arranged to be at right angled to


each other.

Two axis system :


1. Right handed system.
2. Left handed system.
3D Transformations

• 3D
2D coordinates

y
y

x
x
z
y
z
Right-handed coordinate system: x
Equation of A Line

• In 2D equation of a line is given by:

y-y1/ x-x1 = y2- y1/ x2- x1

• In 3D equation of line is given by:

y-y1/ x-x1 = y2- y1/ x2-x1 and z- z1/ x-x1 = z2-z1/ x2-x1
3D Transformation

• Translation in 3D

1 0 0 0 T=(tx, ty, tz)


0 1 0 
0

0 0 1 0
 
tx ty tz 1
3D Transformation

• Scaling in 3D:

 sx 0 0 0
 0 sy 0 0
 
 0 0 sz 0
 
 0 0 0 1
3D Transformation
3D Transformation

• z-axis rotation:  cos  sin  0 0


  sin  cos  0
x’=x cos θ - y sin θ  0 
 y’=x sin θ + y cos θ  0 0 1 0
 
 z’=z  0 0 0 1

Transformation equations for rotation about the other


axis can be obtained with a cyclic permutation of
coordinate parameters x, y and z . That is we use the
replacements:
x→ y→ z→ x
3D Transformation

 x-axis rotation 1 0 0 0
y’=y cos θ - z sin θ 0 cos  sin  0
z’=y sin θ + z cos θ  
0  sin  cos  0
x’=x  
0 0 0 1
 y-axis rotation
cos  0  sin  0
z’=z cos θ - x sin θ  0 1 0 
0
x’=z sin θ + x cos θ 
y’ = y  sin  0 cos  0
 
 0 0 0 1
3D Rotation about Arbitrary Axis

 When an object is to be rotated about an axis that is


parallel to one of the coordinate axes

1. Translate the object so that the rotation axis coincides


with parallel coordinate axis

2. Perform the specified rotation about the axis

3. Translate the object so that the rotation axis is moved


back to its original position
3D Rotation about Arbitrary Axis
 When an object is to rotated about an axis that is not parallel to one of the
coordinate axis

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 axes

3. Perform the specified rotation about the selected coordinate axis

4. Apply inverse rotations to bring the rotation axis back to its original position

5. Apply the inverse translation to bring the rotation axis back to its original
spatial position
Projections

• Conceptual Model of the 3D viewing process


Projections
(Rays converge on eye position) (Rays parallel to view plane)

Perspective Parallel

Orthographic Oblique

Elevations Axonometric Cavalier Cabinet

Isometric
Parallel Projection

• In parallel projection , Z co-ordinate is discarded and parallel lines from


each vertex on the object are extended until they intersect the view
plane.

• The point of intersection is called the projection of vertex.

• A parallel projection preserves relative proportions of objects but does


not produce the realistic view.
Parallel Projections

• 2 Types:
1. Orthographic projection
2. Oblique projection.

• Orthographic :
– direction of projection = normal to the projection plane.

• Oblique :
– direction of projection != normal to the projection plane.
Parallel Projections

• Orthographic (or orthogonal) projections:


– front view , top-view and side-view.
– all have projection plane perpendicular to a principle axes.

• Useful because angle and distance measurements can be


made...

• However, As only one face of an object is shown, it can be


hard to create a mental image of the object, even when
several views are available.
Parallel Projections
• Orthogonal projections:
Parallel Projections

• Oblique parallel projections

– Objects can be visualized better than with orthographic


projections

– Can measure distances, but not angles*


• Can only measure angles for faces of objects parallel to the plane

• 2 common oblique parallel projections:


– Cavalier and Cabinet
Parallel Projections
• Cavalier:
– The direction of the projection makes a 45 degree angle with the projection
plane.

– The projection of a line perpendicular to the view plane has the same length
as the line itself in Cavalier projection. In a cavalier projection, the
foreshortening factors for all three principal directions are equal.
Parallel Projections
• Cabinet:
– The direction of the projection makes a 63.4 degree angle with the projection
plane. This results in foreshortening of the z axis, and provides a more “realistic”
view.

– In Cabinet projection, lines perpendicular to the viewing surface are projected at ½


their actual length.
Perspective Projections

• Lines of projections are not parallel , instead they


converge at a single point called centre of projection
or projection reference point or vanishing point.

• Can categorize perspective projections by the


number of vanishing points, and the number
of axes the projection plane cuts
Perspective Projections
• 2 different examples of a one-point perspective
projection of a cube.
(note: x and y parallel lines do not converge)
Perspective Projections
• Two-point perspective projection:

You might also like