0% found this document useful (0 votes)
8 views19 pages

2D Transfrmn Translation ND Rotation

The document discusses 2D transformations in computer graphics, focusing on translation and rotation. Translation involves repositioning an object along a straight line by adding translation distances to its coordinates, while rotation involves repositioning an object along a circular path around a pivot point defined by an angle. Both transformations maintain the object's shape and are represented mathematically using matrix equations.

Uploaded by

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

2D Transfrmn Translation ND Rotation

The document discusses 2D transformations in computer graphics, focusing on translation and rotation. Translation involves repositioning an object along a straight line by adding translation distances to its coordinates, while rotation involves repositioning an object along a circular path around a pivot point defined by an angle. Both transformations maintain the object's shape and are represented mathematically using matrix equations.

Uploaded by

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

CSE411

Computer Graphics

2D Transformations – Translation & Rotation

Dr. Sushitha Susan Joseph


Asst. Professor
Dept. of CSE
IIIT Kottayam
4. Translation
• A translation is applied to an object by repositioning it along a straight-line
path from one coordinate location to another.
• We translate a two-dimensional point by adding translation distances, 𝑡𝑥 , and
𝑡𝑦 , to the original coordinate position (x, y) to move the point to a new
position (x', y') as shown in below figure.

P'

Figure. Translating a point from position P to position P' with translation vector T .
• 𝑥 ′ = 𝑥 + 𝑡𝑥 ,
• 𝑦 ′ = 𝑦 + 𝑡𝑦
• The translation distance pair (𝑡𝑥 , 𝑡𝑦 ) is called a translation vector or
shift vector.
• We can express the translation equations as a single matrix equation
as follows
 x  x' t x 
P =  , P ' =  , T =  
 y  y ' t y 

𝑷′ = 𝑷 + 𝑻
• Translation moves the object without deformation (rigid-body
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 the new set of vertex
coordinates
Translation (55,60)

(20,35)

(45,30)
(65,30)

x = x + tx
(10,5) (30,5)
y = y + t y
The vector (tx, ty) is called the offset vector.
5. Rotation
• A two-dimensional rotation is applied to an object by repositioning it
along a circular path in the xy plane.
• To generate a rotation, we specify a rotation angle 𝜃 and the position
(𝑥𝑟 , 𝑦𝑟 ) of the rotation point (or pivot point) about which the object is to
be rotated (Fig. 5-3).

Figure 5-3 Rotation of an object through angle 𝜃 about the pivot point (𝑥𝑟 , 𝑦𝑟 ).
5. Rotation
• Positive values for the rotation angle define counterclockwise rotations
about the pivot point, as in Fig. 5-3, and negative values rotate objects in
the clockwise direction.

Determining the transformation equations for rotation of a point position P


when the pivot point is at the coordinate origin.

• The angular and coordinate relationships of the original and transformed


point positions are shown in Fig. 5-4.
• In this figure, r is the constant distance of the point from the origin, angle
𝜙 is the original angular position of the point from the horizontal, and 𝜃
is the rotation angle.
5. Rotation

(x’,y’)

θ
r
(x,y)
r

Figure 5-4. Rotation of a point from position (x, y) to position (x', y ') through an angle 𝜃 relative to the
coordinate origin.
• we can express the transformed coordinates in terms of angles 𝜃 and
𝜙 as
𝑥
• Considering the right angled triangle, cos 𝜙 = adj/ hypotenuse=
𝑟
𝑥 = 𝑟 𝑐𝑜𝑠 𝜙
𝑦
sin 𝜙 = opposite/ hypotenuse=
𝑟
y = 𝑟 𝑠𝑖𝑛 𝜙
• Considering the next triangle,
𝑥′
cos (𝜃 + 𝜙) = adj/ hypotenuse=
𝑟
𝑥 ′ = 𝑟 𝑐𝑜𝑠 (θ + 𝜙)
= 𝑟 (𝑐𝑜𝑠 θ cos 𝜙 − sin θ 𝑠𝑖𝑛𝜙)
𝑥 ′ = 𝑥 cos 𝜃 − 𝑦 sin 𝜃
𝑦′
Similarly, sin (𝜃 + 𝜙) = opp/ hypotenuse=
𝑟
𝑦 ′ = 𝑟 𝑠𝑖𝑛 (θ + 𝜙)
= 𝑟 (𝑠𝑖𝑛 θ cos 𝜙 + cos θ 𝑠𝑖𝑛𝜙)
𝑦 ′ = 𝑥 sin 𝜃 + 𝑦 cos 𝜃

With column vector representations for coordinate points, we can write


the rotation equations in the matrix form.
𝑃′ = 𝑅. 𝑃
Where the rotation matrix is
cos  − sin  
R= 
 sin  cos  
Rotation About the Origin
y
(x’,y’)

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

o x
x  = x cos − y sin 
y  = x sin  + y cos
The above 2D rotation is actually a rotation about the
z-axis (0,0,1) by an angle .
• Rotation About a Pivot Point

Figure 5-5. Rotating a point from (𝑥, 𝑦) to position (𝑥 ′ , 𝑦 ′ ) through an angle 𝜃 , about
the rotation point (𝑥𝑟 , 𝑦𝑟 ) .
Rotation About a Pivot Point

The transformation equations for rotation of a point about any


specified rotation position (𝑥𝑟 , 𝑦𝑟 )
x’= xr+(x - xr) cos θ – (y - yr) sin θ
y’= yr+(x - xr) sin θ + (y - yr) cos θ
• Rotations move objects without deformation
• A line is rotated by applying the rotation formula to each of the
endpoints and redrawing the line between the new end points
• A polygon is rotated by applying the rotation formula to each of the
vertices and redrawing the polygon using new vertex coordinates
Rotation About a Pivot Point

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

(xp , yp)
Pivot Point

•Pivot point is the point of rotation


•Pivot point need not necessarily be on the object
Rotation About a Pivot Point … Contd.

STEP-1: Translate the pivot point to the origin


(x,y)

(x1, y1)

(xp , yp)

x1 = x − x p

y1 = y − y p
Rotation About a Pivot Point … Contd.

STEP-2: Rotate about the origin


Counter clock wise or Anti clock Clock wise

(x2, y2) (x1, y1) (x2, y2) (x1, y1)

x 2 = x1cos − y1sin x 2 = x1 cos + y1sin 


y 2 = x1 sin + y1cos y 2 = − x1 sin  + y1 cos
Rotation About a Pivot Point … Contd.
STEP-3: Translate the pivot point to original position
(x’, y’)

(x2, y2)

(xp, yp)

x = x 2 + x p

y = y 2 + y p
Rotation About a Pivot Point … Contd.
x  = ( x − x p ) cos − ( y − y p ) sin  + x p
y  = ( x − x p ) sin  + ( y − y p ) cos + y p

Specifying a 2D-Rotation about a pivot point (xp,yp):

glTranslatef(xp, yp, 0);


glRotatef(theta, 0, 0, 1.0);
glTranslatef(-xp, -yp, 0);

Note the OpenGL specification of the sequence of transformations in the


reverse order !
Example of rotation

For rotations, |𝑅|= 1 and 𝑅𝑇 = 𝑅 −1


From the above two properties, we can say that the
Rotation matrices are orthogonal

You might also like