3D Transformations in Computer Graphics-

We have discussed-

• Transformation is a process of modifying and re-positioning the existing graphics.
• 3D Transformations take place in a three dimensional plane.

In computer graphics, various transformation techniques are-

3D Rotation in Computer Graphics-

 In Computer graphics, 3D Rotation is a process of rotating an object with respect to an angle in a three dimensional plane.

Consider a point object O has to be rotated from one angle to another in a 3D plane.

Let-

• Initial coordinates of the object O = (Xold, Yold, Zold)
• Initial angle of the object O with respect to origin = Φ
• Rotation angle = θ
• New coordinates of the object O after rotation = (Xnew, Ynew, Znew)

In 3 dimensions, there are 3 possible types of rotation-

• X-axis Rotation
• Y-axis Rotation
• Z-axis Rotation

For X-Axis Rotation-

This rotation is achieved by using the following rotation equations-

• Xnew = Xold
• Ynew = Yold x cosθ – Zold x sinθ
• Znew = Yold x sinθ + Zold x cosθ

In Matrix form, the above rotation equations may be represented as-

For Y-Axis Rotation-

This rotation is achieved by using the following rotation equations-

• Xnew = Zold x sinθ + Xold x cosθ
• Ynew = Yold
• Znew = Yold x cosθ – Xold x sinθ

In Matrix form, the above rotation equations may be represented as-

For Z-Axis Rotation-

This rotation is achieved by using the following rotation equations-

• Xnew = Xold x cosθ – Yold x sinθ
• Ynew = Xold x sinθ + Yold x cosθ
• Znew = Zold

In Matrix form, the above rotation equations may be represented as-

Problem-01:

Given a homogeneous point (1, 2, 3). Apply rotation 90 degree towards X, Y and Z axis and find out the new coordinate points.

Solution-

Given-

• Old coordinates = (Xold, Yold, Zold) = (1, 2, 3)
• Rotation angle = θ = 90º

For X-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-

• Xnew = Xold = 1
• Ynew = Yold x cosθ – Zold x sinθ = 2 x cos90° – 3 x sin90° = 2 x 0 – 3 x 1 = -3
• Znew = Yold x sinθ + Zold x cosθ = 2 x sin90° + 3 x cos90° = 2 x 1 + 3 x 0 = 2

Thus, New coordinates after rotation = (1, -3, 2).

For Y-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-

• Xnew = Zold x sinθ + Xold x cosθ = 3 x sin90° + 1 x cos90° = 3 x 1 + 1 x 0 = 3
• Ynew = Yold = 2
• Znew = Yold x cosθ – Xold x sinθ = 2 x cos90° – 1 x sin90° = 2 x 0 – 1 x 1 = -1

Thus, New coordinates after rotation = (3, 2, -1).

For Z-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-

• Xnew = Xold x cosθ – Yold x sinθ = 1 x cos90° – 2 x sin90° = 1 x 0 – 2 x 1 = -2
• Ynew = Xold x sinθ + Yold x cosθ = 1 x sin90° + 2 x cos90° = 1 x 1 + 2 x 0 = 1
• Znew = Zold = 3

Thus, New coordinates after rotation = (-2, 1, 3).

To gain better understanding about 3D Rotation in Computer Graphics,

Watch this Video Lecture

Next Article- 3D Scaling in Computer Graphics

Get more notes and other study material of Computer Graphics.

Watch video lectures by visiting our YouTube channel LearnVidFun.

2D Transformations in Computer Graphics-

We have discussed-

• Transformation is a process of modifying and re-positioning the existing graphics.
• 2D Transformations take place in a two dimensional plane.

In computer graphics, various transformation techniques are-

2D Rotation in Computer Graphics-

 In Computer graphics, 2D Rotation is a process of rotating an object with respect to an angle in a two dimensional plane.

Consider a point object O has to be rotated from one angle to another in a 2D plane.

Let-

• Initial coordinates of the object O = (Xold, Yold)
• Initial angle of the object O with respect to origin = Φ
• Rotation angle = θ
• New coordinates of the object O after rotation = (Xnew, Ynew)

This rotation is achieved by using the following rotation equations-

• Xnew = Xold x cosθ – Yold x sinθ
• Ynew = Xold x sinθ + Yold x cosθ

In Matrix form, the above rotation equations may be represented as-

For homogeneous coordinates, the above rotation matrix may be represented as a 3 x 3 matrix as-

Problem-01:

Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 30 degree rotation anticlockwise direction on the line segment and find out the new coordinates of the line.

Solution-

We rotate a straight line by its end points with the same angle. Then, we re-draw a line between the new end points.

Given-

• Old ending coordinates of the line = (Xold, Yold) = (4, 4)
• Rotation angle = θ = 30º

Let new ending coordinates of the line after rotation = (Xnew, Ynew).

Applying the rotation equations, we have-

Xnew

= Xold x cosθ – Yold x sinθ

= 4 x cos30º – 4 x sin30º

= 4 x (√3 / 2) – 4 x (1 / 2)

= 2√3 – 2

= 2(√3 – 1)

= 2(1.73 – 1)

= 1.46

Ynew

= Xold x sinθ + Yold x cosθ

= 4 x sin30º + 4 x cos30º

= 4 x (1 / 2) + 4 x (√3 / 2)

= 2 + 2√3

= 2(1 + √3)

= 2(1 + 1.73)

= 5.46

Thus, New ending coordinates of the line after rotation = (1.46, 5.46).

Alternatively,

In matrix form, the new ending coordinates of the line after rotation may be obtained as-

Thus, New ending coordinates of the line after rotation = (1.46, 5.46).

Problem-02:

Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1). Rotate the triangle by 90 degree anticlockwise direction and find out the new coordinates.

Solution-

We rotate a polygon by rotating each vertex of it with the same rotation angle.

Given-

• Old corner coordinates of the triangle = A (0, 0), B(1, 0), C(1, 1)
• Rotation angle = θ = 90º

For Coordinates A(0, 0)

Let the new coordinates of corner A after rotation = (Xnew, Ynew).

Applying the rotation equations, we have-

Xnew

= Xold x cosθ – Yold x sinθ

= 0 x cos90º – 0 x sin90º

= 0

Ynew

= Xold x sinθ + Yold x cosθ

= 0 x sin90º + 0 x cos90º

= 0

Thus, New coordinates of corner A after rotation = (0, 0).

For Coordinates B(1, 0)

Let the new coordinates of corner B after rotation = (Xnew, Ynew).

Xnew

= Xold x cosθ – Yold x sinθ

= 1 x cos90º – 0 x sin90º

= 0

Ynew

= Xold x sinθ + Yold x cosθ

= 1 x sin90º + 0 x cos90º

= 1 + 0

= 1

Thus, New coordinates of corner B after rotation = (0, 1).

For Coordinates C(1, 1)

Let the new coordinates of corner C after rotation = (Xnew, Ynew).

Xnew

= Xold x cosθ – Yold x sinθ

= 1 x cos90º – 1 x sin90º

= 0 – 1

= -1

Ynew

= Xold x sinθ + Yold x cosθ

= 1 x sin90º + 1 x cos90º

= 1 + 0

= 1

Thus, New coordinates of corner C after rotation = (-1, 1).

Thus, New coordinates of the triangle after rotation = A (0, 0), B(0, 1), C(-1, 1).

To gain better understanding about 2D Rotation in Computer Graphics,

Watch this Video Lecture

Next Article- 2D Scaling in Computer Graphics

Get more notes and other study material of Computer Graphics.

Watch video lectures by visiting our YouTube channel LearnVidFun.