0% found this document useful (0 votes)
38 views94 pages

3.2d Transformation

Uploaded by

Prachit Yelamkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views94 pages

3.2d Transformation

Uploaded by

Prachit Yelamkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 94

Module 3

2D TRANSFORMATION

TEXT BOOK :
■ COMPUTER GRAPHICS
■ DONALD HEARN & M.PAULINE
BAKER
Transformations

• What is a transformation?

• What kind of transformations are there?

• How can we compute them?


• In many applications, changes in orientations,
size, and shape are accomplished with geometric
transformations that alter the coordinate
descriptions of objects.
• Basic geometric transformations are:
⮚ Translation
⮚ Rotation
⮚ Scaling
• Other transformations:
⮚ Reflection
⮚ Shear
• Transformations play an important role in
computer graphics to reposition the graphics
on the screen and change their size or
orientation.
• Transformation means changing some
graphics into something else by applying rules.
• We can have various types of transformations
such as translation, scaling up or down,
rotation, shearing, etc. When a transformation
takes place on a 2D plane, it is called 2D
transformation.
Homogenous Coordinates
• To perform a sequence of transformation such
as translation followed by rotation and
scaling, we need to follow a sequential process:
• 1. Translate the coordinates,
• 2. Rotate the translated coordinates, and then
• 3. Scale the rotated coordinates to complete
the composite transformation
• To shorten this process, we have to use 3×3
transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to
3×3 matrix, we have to add an extra dummy
coordinate W.
• In this way, we can represent the point by 3
numbers instead of 2 numbers, which is
called Homogenous Coordinate system.
In this system, we can represent all the
transformation equations in matrix multiplication.
Any Cartesian point P(X, Y) can be converted to
homogenous coordinates by P’ (Xh, Yh, h).
Translation
• We translate a 2D point by adding translation
distances, tx and ty, to the original coordinate
position (x,y)
• A translation moves an object to a different
position on the screen. You can translate
a point in 2D by adding translation coordinate
(tx, ty) to the original coordinate (X, Y)
to get the new coordinate (X’, Y’).
• From the above figure, you can write that:
X’ = X + tx
Y’ = Y + ty
• The pair (tx, ty) is called the translation vector
or shift vector. The above equations can also
be represented using the column vectors.

We can write it as: P’ = P + T


Rotation
• In rotation, we rotate the object at particular
angle θ (theta) from its origin. From the figure,
we can see that the point P(X, Y) is located at
angle Φ from the horizontal X coordinate with
distance r from the origin.
Let us suppose you want to rotate it at the angle
θ. After rotating it to a new location,
you will get a new point P’ (X’, Y’).
• Using standard trigonometric the original
coordinate of point P(X, Y) can be represented as:
X = r cos Φ …….. (1)
Y = r sin Φ ……… (2)
Same way we can represent the point P’ (X’, Y’) as:
X’ = r cos (Φ + θ) = r cos Φ cos θ – r sin Φ sin θ …… (3)
Y’ = r sin (Φ + θ) = r cos Φ sin θ + r sin Φ cos θ …… (4)
Substituting equation (1) & (2) in (3) & (4)
respectively, we will get
X’ = X cos θ – Y sin θ
Y’ = X sin θ + Y cos θ
• Representing the above equation in matrix
form,
• For positive rotation angle, we can use the
above rotation matrix. However, for negative
angle rotation, the matrix will change as
shown below:
Scaling
• To change the size of an object, scaling
transformation is used. In the scaling process, you
either expand or compress the dimensions of the
object. Scaling can be achieved by multiplying the
original coordinates of the object with the scaling
factor to get the desired result.
• Let us assume that the original coordinates are
(X, Y), the scaling factors are (SX, SY),and the
produced coordinates are (X’, Y’). This can be
mathematically represented as shown below:
X’ = X ∙ sx and Y’ = Y ∙ sy
• The scaling factor SX, SY scales the object in X and Y
direction respectively. The above equations can also
be represented in matrix form as below:
If we provide values less than 1 to the scaling factor
S, then we can reduce the size of the object. If we
provide values greater than 1, then we can increase
the size of the object.
Scaling With Respect to the Origin
Reflection
• Reflection is the mirror image of original
object. In other words, we can say that it is a
rotation operation with 180˚. In reflection
transformation, the size of the object does not
change.
• The following figures show reflections with
respect to X and Y axes, and about the origin
respectively.
Shear
• A transformation that slants the shape of an
object is called the shear transformation.
• There are two shear transformations X-Shear
and Y-Shear.
• One shifts X coordinates
values and other shifts Y coordinate values.
However, in both the cases, only one
coordinate changes its coordinates and other
preserves its values. Shearing is also termed as
Skewing.
X-Shear
• The X-Shear preserves the Y coordinate and
changes are made to X coordinates, which
causes the vertical lines to tilt right or left as
shown in below figure
• The transformation matrix for X-Shear can be
represented as:
Y-Shear

• The Y-Shear preserves the X coordinates and


changes the Y coordinates which causes the
horizontal lines to transform into lines which
slopes up or down as shown in the following
figure.
Composite Transformation Matrix
Problem : Give the sequence of transformation required to
reflect the object about the line y=mx+c.
Solution: Consider a line y=mx+c as shown in figure and is
inclined with an angle θ about X-axis .
y

Y=mx+c

53
The transformation matrix is:
Mc=T-v R-θ M x Rθ T v
1 0 0 cosθ -sinθ 0 1 0 0
0 1 -c . sinθ cosθ 0 . 0 -1 0
0 0 1 0 0 1 0 0 1

cosθ -sinθ 0 1 0 0
sinθ cosθ 0 0 -1 0
0 0 1 0 0 1

54
From trigonometric theorms.
tan(θ)=m
Where m is slope of line and θ is the inclination made the line with x-
axis
tan(θ)=m
sin(θ)/cos(θ)=m
sin(θ)=m cos(θ)…………………...[1]
From trigonometric theorems
Sin2(θ)+cos2(θ)=1
Substituting from eqn[1]
m2
cos2(θ)+cos2(θ)=1
cos2(θ)(m2+1)=1
cos2(θ)=1/m2+1
Cos(θ)=sqrt(1/m2+1)
Cos(θ)= 1/Sqrt(m2+1)……………[2]
From equation [1]&[2] we get
Sin(θ)=m/Sqrt (m2+1)…………....[3] 55
Substituting these values of sin(θ)and cos(θ) and after
matrix manipulation we get

1-m2/m2+1 2m/m2+1 0
Mc= 2m/m2+1 m2-1/m2+1 0
-2cm/m2+1 2c/m2+1 1

56
Problem: Rotate the polygon whose vertices are
A(0,0),B(1,2),C(2,2),D(2,1)about an origon by
rotation angle θ=45.
Solution:The vertices are represented in the form of
homogenous matric

0 0 1
V= 1 2 1
2 2 1
2 1 1
V’=V (Rθ)
57
0 0 1 cos45 -sin45 0
V= 1 2 1 . -sin45 cos45 0
2 2 1 0 0 1
2 1 1

0 1 1/ 2
V= 1 2 1.
2 2 1
2 1 1

58
• Show the sequence of transformation required to
change the position of object in fig 1 to fig 2
2 6

-1
🡺
2
-3
(0,2) 2
2

(-4,0)

59
• Soln: Sequence of transformation required…
• 1.Translate the line so that it passes through the
origin with Tx=0 and Ty=-2
• 2.Rotate the line by angle θ so that it coincides
with the X-axis
• 3.Translate the object so that it coincides with
origin with Tx=-2 and Ty=0
• 4. Reflect the object about the origin
• 5.Scale the object with Sx=2 and Sy=1
• 6.Translate the object so that it goes into its final
position with Tx=6 and Ty= -1
• Transformation matrix for step 1.

1 0 0
• T1= 0 1 0
0 -2 1

Transformation matrix for step 2.


tan(θ)=(2/4)=(1/2)
θ=tan-1(1/2)
cos(θ)=(4/( 42+22))=2/ 5
Sin(θ)=(2/( 42+22))=1/ 5
61
R(θ)= solve the complete problem

62
Projections

• Perspective Projection
• Parallel Projection
Planar Geometric Projections
• Standard projections project onto a plane
• Projectors are lines that either
– converge at a center of projection
– are parallel
• Such projections preserve lines
– but not necessarily angles
• Nonplanar projections are needed for applications such as map
construction
Perspective Projection
In a perspective projection the object positions are transformed to the
view plane along the line that converge to a point called the center of
projection.The projected view of an object is determined by calculating
intersection of the projected lines with the view plane.In the
perspective projection view distant object appears smaller than object
closer to the viewing position.
A perspective transformation is determined by a center of projection
and the view palne as specified by its view reference point Ro and view
plane normal N.
p2

P2’
Cp (center point)
P1’ (EYE)

p1
A perspective projection transformation produces realistic
views but does not preserve relative proportions.
In perspective projection , parallel lines in a scene that
are not parallel to the plane are projected into
converging lines and parallel lines that are parallel to
the planes are projected as parallel to the plane are
projected as parallel lines.
Perspective transformation of an object of an object onto
plane passing hrough the point Ro(xo,yo,zo) and having
the normal vector N=aI+bJ+cK with center of projection
at origin.
y P (x, y ,z)
N=aI+bJ+cK

P’(x’ y’ z’)

x
Cp

Consider point P located in WCS at (x,y,z)


Let P’ ( x’ y’ z’) be the projection of P onto view plane.
Then the equation of a plane with normal vector N and passing through
P’ and Ro is given by
a (x’-xo) + b (y’- yo) + c(z’- zo) = 0
a x’+ b y’+ c z’ – (a xo + b yo + c zo)=0
Let a = (a xo + b yo + c zo)
a x’+ b y’+ c z’ = a …………………..[A]
The vectors Vp.P and Cp.p have same direction. Then there is a
number such that
Cp.p = α .Cp.p
Therefore x’ = α.x ………………………..[i]
y’ = α.y ……………………….[ii]
z’ = α.z ……………………….[iii]
Substiting [i][ii][iii] in [A] we get
a (α.x) + b (α.y) + c (α.z) = a
a ( ax + by + cz)=a
The projected co-ordinate of point P’ will be
x’ = x.a / ax + by + cz = x. α
y’ = y.a / ax + by + cz = y. α
z’ = z.a / ax + by + cz = z. α
where α = a / ax + by + cz = (a xo + b yo + c zo) / ax + by + cz
The projection transformation matrix is
α 0 0 0
Per = 0 α 0 0
0 0 α 0
0 0 0 1
Parallel Projection
Derive matrix for parallel projection
• In parallel projection object are transformed
to the view plane along the parallel lines.
• A parallel projection transformation is
determined by prescribing the direction of
projection vector Vp and view plane. The view
plane is specified by its view reference point
Ro.
Fig:1

p2
P2’

Vp
P1’

p1

A parallel projection preserve relative proportion of objects.


When the direction of projection is perpendicular to the view plane it is called
orthographic parallel projection.
When the direction of projection is not perpendicular to the view plane it is called
oblique projection.
Parallel transformation of an object onto XY plane in the direction of Vp=aI+bJ+cK
Consider a point P located at (x,y,z)
Let P’(x’,y’z’) be the projection of P onto XY plane.
The direction of projection is Vp=aI+bJ+cK.The vector Vp and P.P’ have the same direction. Then
there is number α such that
Therefore P.P’ = α.Vp
X’-x = α .a ……………..(i)
Y’-y = α.b ……………..(ii)
Z’-z = α.c ……………...(iii)
But Z’=0 (a paoint xy plane)
From from (iii)
-z = α.c
α=-z/c
X’ = x –(a/c).z here x is 1 ,y=0, z=-(a/c)
Y’= y-(b/c).z here x=0, y=1, z=(b/c)
The projection transformation matrix
1 0 -a/c 0
0 1 -b/c 0
Par = 0 0 0 0
0 0 0 2
Taxonomy of Planar Geometric
Projections

planar geometric projections

parallel perspective

1 point 2 point 3 point


multiview axonometric oblique
orthographic

isometric dimetric trimetric


Orthographic Projection
Projectors are orthogonal to projection plane
Multiview Orthographic Projection
• Projection plane parallel to principal face
• Usually form front, top, side views
isometric (not multiview
orthographic view)
fron
t

in CAD and architecture,


we often display three
multiviews plus isometric
side
top
Advantages and Disadvantages
• Preserves both distances and angles
–Shapes preserved
–Can be used for measurements
• Building plans
• Manuals
• Cannot see what object really looks like because many
surfaces hidden from view
–Often we add the isometric
Oblique Projection
Arbitrary relationship between projectors and
projection plane. When the direction of projection is
not perpendicular to the view plane it is called oblique
projection
Advantages and Disadvantages
• Can pick the angles to emphasize a particular face
–Architecture: plan oblique, elevation oblique
• Angles in faces parallel to projection plane are
preserved while we can still see “around” side

• In physical world, cannot create with simple camera;


possible with bellows camera or special lens
(architectural)
Perspective Projection

Projectors coverage at center of projection


Vanishing Points
• Parallel lines (not parallel to the projection plan) on
the object converge at a single point in the projection
(the vanishing point)
• Drawing simple perspectives by hand uses these
vanishing point(s)

vanishing point
One-Point Perspective
• One principal face parallel to projection plane
• One vanishing point for cube
Two-Point Perspective
• On principal direction parallel to projection plane
• Two vanishing points for cube
Advantages and Disadvantages
• Objects further from viewer are projected smaller than the
same sized objects closer to the viewer (diminution)
– Looks realistic
• Equal distances along a line are not projected into equal
distances (nonuniform foreshortening)
• Angles preserved only in planes parallel to the projection plane
• More difficult to construct by hand than parallel projections
(but not more difficult by computer)
3D Transformations.
• Use homogeneous coordinates, just as in 2D case.
• Transformations are now 4x4 matrices.
• We will use a right-handed (world) coordinate system - ( z out
of page ).

Note:
Convenient to think of display
as
Being left-handed !!
x ( z into the screen )
z (out of page)
Translation in 3D.
Simple extension to the 3D case:
Scale in 3D.
Simple extension to the 3D case:
Rotation in 3D
• Need to specify which axis the rotation is about.
• z-axis rotation is the same as the 2D case.
Rotation in 3D
• For rotation about the x and y axes:
Transformations of coordinate systems.
Transform Left-Right, Right-Left
Transforms between world coordinates and viewing
coordinates. That is: between a right-handed set and a left-
handed set.
END
Thank you for your attentions

You might also like