Open In App

Computer Graphics Rotation

Last Updated : 04 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Rotation is one of the part of computer graphic’s transformation, Transformation means to change some graphics into something else with the help of rules. There are various types of transformations like translation, scaling, rotation, shearing, reflection etc. it helps to change the object’s position, size, orientation, shape, etc. When a transformation takes place on a 2D plane, it is called 2D transformation.

Transformation in Computer Graphics

 

2D Rotation in Computer Graphics:

Rotation is another useful transformation technique in computer graphics in this, the rotation of an object is about specified pivot point. In rotation, the object is rotated θ about the origin. In rotation the given point or figure is just rotated along with some angle theta by keeping the r same it means it is rotating in a circular manner.

Now here, from the following figure, let point P X,Y is located at angle φ from the horizontal X coordinate with distance r from the origin. and we want to rotate it at the angle θ. so After rotating it to a coordinates, the new points will be P’ X′,Y′.

 

Now to get the new rotated coordinates we will use some trigonometric identities, coordinate of point P X,Y can be represented as :

X=rcosϕ  ------eq(1)  Y=rsinϕ   ------eq(2)

in similar fashion we can represent P’ X’,Y’

x′=rcos(Ï•+θ)=rcosÏ•cosθ−rsinÏ•sinθ ----eq(3)  y′=rsin(Ï•+θ)=rcosÏ•sinθ+rsinÏ•cosθ ----eq(4)

now put the equations 1,2 in 3, 4 we will get our coordinates x’ and y’

x′=xcosθ−ysinθ      y′=xsinθ+ycosθ

We can represent the above equations in matrix form also, like

[X′Y′]=[XY][cosθ−sinθsinθcosθ]

OR

P’ = P . R

Here R is the rotation matrix

R=[cosθ−sinθsinθcosθ]

There are various figures we can rotate like point rotation, line rotation, polygon rotation etc.

Now, let’s consider an example of point rotation:

 we have a line segment with point as (0, 0) and ending point as (5, 5). and we want to rotate it 30 degree anticlockwise direction on the line segment and find out the new coordinates of the line.

Let new ending coordinates of the line after rotation = (X’, Y’). and X=5, Y=5

By using the rotation equations, we have-

X':
= X * cosθ – Y * sinθ
= 5 * cos30º – 5 * sin30º
= 5 * (√3 / 2) – 5 * (1 / 2)
= 5(√3/2 – 1/2)
= 5(0.866 – 0.5)
= 1.83
Y':
= X * sinθ + Y * cosθ
= 5 * sin30º + 5 * cos30º
= 5 * (1 / 2) + 5 * (√3 / 2)
= 5(1/2 + √3/2)
= 5(0.5 + 0.866)
= 6.83

Thus, New ending coordinates of the line after rotation = (1.83, 6.83).

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads