2D Transfrmn Translation ND Rotation
2D Transfrmn Translation ND Rotation
Computer Graphics
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.
(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 𝜃
(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
(x’,y’) (x,y)
(xp , yp)
Pivot Point
(x1, y1)
(xp , yp)
x1 = x − x p
y1 = y − y p
Rotation About a Pivot Point … Contd.
(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