Example – 2 (from Exams)
Rotate a triangle placed at A(0,0), B(1,1) and C(5,2) by an angle 45 with respect to point P(-1,-1).
The calculations available for computer graphics can be performed only at origin. It is a case of composite transformation which means this can be performed when more than one transformation is performed.
The following composite transformation matrix would be performed as follows.
- First bring the Point P(-1,-1) to the origin => which means translation towards origin => towards origin will be negative translation. So tx and ty values would be negative. So tx =- (-1) = 1 and ty = – (-1) = 1.
- Perform the rotation of 45 degrees.
- Send the point P(-1,-1) back => which mean translation away from origin => Away from origin would be positive translation therefore tx and ty will be positive. So tx = -1 and ty = -1.
- The most important point: the composite matrix should be written from right to left , So the composite rotation matrix would be = T(x) * R(Theta) * T(-x) and NOT T(-x) * R(Theta) * T(x)
The composite rotation matrix would be = Positive translation * Rotation (45degree) * Negative translation.
Substitute of values of translation and rotation angle.
Multiply the resultant rotation matrix with the triangle matrix.
The final resultant matrix will be as follows.
Problem Statement
Example -2:
Rotate a triangle placed at A(0,0), B(1,1) and C(5,2) by an angle 45 with respect to origin.
In this case since one of the edges of the triangle (A) is already at origin so after performing the transformation the values of A should not change, which will act as a check. We will multiply the object matrix with the rotation matrix to get the solution.
Remember: If direction of the rotation is not given then always assume it be positive.
The more complex problem is handled in the example two where the rotation is happening with respect to a point other than origin.
S-1: The triangle coordinates should also be written in the matrix form, shown as follows. The rotation matrix is also given below.
S-2: Put the value of angle in the rotation matrix (Angle given in problem statement is 45 degrees. Also put the values of cos 45 and sin 45 degrees in the matrix. The value of sin and cos 45 degrees is 1/sqrt(2).
S-3: Multiply these matrices to get the resultant matrix, which would describe the new coordinates of the edges of the triangle after 45 degrees rotation.