1. Gyanastra
  2. Computer Graphics
  3. 2D Transformations and Viewing
  4. Basic 2D Transformations and Matrices
Free lesson, no account needed 12 min read 23 practice questions after it
Asked in past papers8 times
  • UGC NET20232022202120202019201720162013

Computer Graphics · 2D Transformations and Viewing

Basic 2D Transformations and Matrices

Overview

A 2D transformation is a rule that maps every point (x,y)(x,y) of a planar object to a new point (x′,y′)(x',y'), and a matrix is the compact way of storing that rule so that many transformations can be multiplied into a single operation.
This lesson sits at the head of the "2D Transformations and Viewing" area of the syllabus: window-to-viewport mapping, clipping, animation and 3D viewing all reuse exactly these matrices.
Before starting you must be comfortable with 2×2 and 3×3 matrix multiplication, with coordinate geometry of the plane, and with the trigonometric values of 0∘,30∘,45∘,60∘,90∘, 180∘0^\circ, 30^\circ, 45^\circ, 60^\circ, 90^\circ,\ 180^\circ.
Convention used throughout these notes (the standard one in graphics texts and in the exam): points are column vectors, a positive angle means counterclockwise rotation, and the composite matrix acts as p′=M pp' = M\,p.

Key concepts

  • Geometric transformation: a mapping (x,y)↦(x′,y′)(x,y)\mapsto(x',y') applied to every vertex of an object; the object is redrawn from the transformed vertices.
  • Linear transformation: representable by a 2×22\times2 matrix, i.e. the origin always stays fixed. Rotation, scaling, reflection and shear are linear.
  • Affine transformation: a linear transformation followed by a translation; written as a 3×33\times3 homogeneous matrix whose last row is (0 0 1)(0\ 0\ 1). It keeps straight lines straight and preserves parallelism.
  • Homogeneous coordinates: an ordinary point (x,y)(x,y) is written as (x,y,1)(x,y,1). In general the triple (x,y,w)(x,y,w) with w≠0w\neq 0 means the point (x/w, y/w)(x/w,\ y/w), and w=0w=0 represents a point at infinity (a direction).
    This extra coordinate is needed because translation is not linear and cannot be written with a 2×22\times2 matrix.
  • Translation: moves by (tx,ty)(t_x,t_y); x′=x+tx, y′=y+tyx'=x+t_x,\ y'=y+t_y. Two parameters, no fixed point, determinant 11, orientation and size unchanged.
  • Rotation: turns the object by θ\theta about the origin. One parameter, the only fixed point is the origin, lengths and angles preserved, determinant +1+1.
  • Scaling: multiplies distances from the origin; x′=sxx, y′=syyx'=s_x x,\ y'=s_y y. If sx=sys_x=s_y it is uniform (isotropic) scaling and shape is preserved; otherwise it is non-uniform (differential) scaling and shape is distorted.
    Determinant =sxsy=s_x s_y, so the area is multiplied by ∣sxsy∣|s_x s_y|. Negative factors combine scaling with a flip.
  • Reflection (mirror): flips the object about a line. Determinant −1-1, so orientation is reversed. Standard mirrors: about the x-axis, the y-axis, the line y=xy=x, the line y=−xy=-x, and about the origin (a half-turn).
  • Shear (skewing): shifts one coordinate in proportion to the other; xx-shear uses x′=x+shx yx'=x+sh_x\,y, yy-shear uses y′=y+shy xy'=y+sh_y\,x. Determinant 11, so area is preserved, but angles and lengths are not.
  • Composite transformation: two or more transformations applied in sequence. With column vectors the matrix of the composite is the product, and the transformation applied last is written leftmost: p′′=M2M1pp''=M_2M_1p.
  • Rigid-body transformation: translation plus rotation only (shape and size preserved).
  • Projective transformation / homography: a general 3×33\times3 (in 3D, 4×44\times4) homogeneous matrix whose last row is not (0 0 1)(0\ 0\ 1).
    The result must be divided by the new ww; straight lines stay straight but parallelism is not preserved — this is how perspective is produced.
  • Orthogonal matrix: a 2×22\times2 matrix with MTM=IM^{T}M=I. It has determinant +1+1 (a rotation) or −1-1 (a reflection, possibly combined with a rotation).

Standard homogeneous matrices (column-vector convention, c=cos⁡θ, s=sin⁡θc=\cos\theta,\ s=\sin\theta):

Transformation3×33\times3 homogeneous matrix
Translation by (tx,ty)(t_x,t_y)[10tx01ty001]\begin{bmatrix}1&0&t_x\\0&1&t_y\\0&0&1\end{bmatrix}
Rotation θ\theta counterclockwise[c−s0sc0001]\begin{bmatrix}c&-s&0\\s&c&0\\0&0&1\end{bmatrix}
Rotation θ\theta clockwise[cs0−sc0001]\begin{bmatrix}c&s&0\\-s&c&0\\0&0&1\end{bmatrix}
Scaling about origin[sx000sy0001]\begin{bmatrix}s_x&0&0\\0&s_y&0\\0&0&1\end{bmatrix}
Reflection about x-axis[1000−10001]\begin{bmatrix}1&0&0\\0&-1&0\\0&0&1\end{bmatrix}
Reflection about y-axis[−100010001]\begin{bmatrix}-1&0&0\\0&1&0\\0&0&1\end{bmatrix}
Reflection about y=xy=x[010100001]\begin{bmatrix}0&1&0\\1&0&0\\0&0&1\end{bmatrix}
Reflection about y=−xy=-x[0−10−100001]\begin{bmatrix}0&-1&0\\-1&0&0\\0&0&1\end{bmatrix}
Reflection about origin[−1000−10001]\begin{bmatrix}-1&0&0\\0&-1&0\\0&0&1\end{bmatrix}
xx-shear (shear along x)[1shx0010001]\begin{bmatrix}1&sh_x&0\\0&1&0\\0&0&1\end{bmatrix}
yy-shear (shear along y)[100shy10001]\begin{bmatrix}1&0&0\\sh_y&1&0\\0&0&1\end{bmatrix}

How it works

  1. Why homogeneous coordinates. Translation is x′=x+txx'=x+t_x, which is not a linear function of (x,y)(x,y) — the origin moves.
    Append a third coordinate fixed at 11; then the constant txt_x can sit in the third column and a single 3×33\times3 multiplication does the job.

  2. Building the rotation matrix. The columns of a linear matrix are the images of the unit vectors: (1,0)↦(cos⁡θ,sin⁡θ)(1,0)\mapsto(\cos\theta,\sin\theta) and (0,1)↦(−sin⁡θ,cos⁡θ)(0,1)\mapsto(-\sin\theta,\cos\theta). Putting these as the two columns gives R(θ)R(\theta) in the table above.
    Swapping the signs of the sin⁡\sin terms gives the clockwise matrix.

  3. Composition order. If p′=M1pp'=M_1p and p′′=M2p′p''=M_2p', then p′′=(M2M1)pp''=(M_2M_1)p. So the first operation is applied first but appears nearest the point, and the last operation appears leftmost.
    Matrix multiplication is associative (the whole chain can be pre-multiplied into one matrix) but not commutative, so order changes the result.

  4. Rotation about an arbitrary pivot PP. a. Translate so that PP goes to the origin: T(−px,−py)T(-p_x,-p_y). b. Rotate by θ\theta about the origin: R(θ)R(\theta). c. Translate back: T(px,py)T(p_x,p_y). The combined matrix is M=T(px,py) R(θ) T(−px,−py)M=T(p_x,p_y)\,R(\theta)\,T(-p_x,-p_y).

  5. Scaling about a fixed point follows exactly the same recipe: M=T(px,py) S(sx,sy) T(−px,−py)M=T(p_x,p_y)\,S(s_x,s_y)\,T(-p_x,-p_y).

  6. Shear about a reference line. To shear in the y-direction keeping the line x=xrefx=x_{ref} fixed, replace xx by x−xrefx-x_{ref}, shear, then add it back: y′=y+shy(x−xref), x′=xy'=y+sh_y(x-x_{ref}),\ x'=x. Similarly an x-shear about y=yrefy=y_{ref} gives x′=x+shx(y−yref), y′=yx'=x+sh_x(y-y_{ref}),\ y'=y.

  7. Reading a given matrix. For M=[abcdef001]M=\begin{bmatrix}a&b&c\\d&e&f\\0&0&1\end{bmatrix} the point maps to (ax+by+c, dx+ey+f)(ax+by+c,\ dx+ey+f). The third column (c,f)(c,f) is the translation part and the upper-left 2×22\times2 block [abde]\begin{bmatrix}a&b\\d&e\end{bmatrix} is the linear part (scale, rotation, shear or reflection).
    If the translation column equals (tx,ty)(t_x,t_y) the translation was applied last; if it equals (sxtx, syty)(s_x t_x,\ s_y t_y) the translation was applied first and then scaled.

  8. Determining an unknown matrix from correspondences. Put x′=ax+by+cx'=ax+by+c and y′=dx+ey+fy'=dx+ey+f, substitute three non-collinear point pairs, solve the two independent 3×33\times3 systems, then verify on the fourth pair.

  9. Inverse and coordinate transformations. The inverse matrix undoes a transformation (T−1=T(−tx,−ty)T^{-1}=T(-t_x,-t_y), R−1=R(−θ)R^{-1}=R(-\theta), S−1=S(1/sx,1/sy)S^{-1}=S(1/s_x,1/s_y), and (M1M2)−1=M2−1M1−1(M_1M_2)^{-1}=M_2^{-1}M_1^{-1}).
    Moving the coordinate system is the inverse of moving the object: if the new coordinate values are obtained by multiplying the old ones by sx,sys_x,s_y, substitute x=x′/sx, y=y′/syx=x'/s_x,\ y=y'/s_y into the old equation to get the equation in the new frame.

Figure. Notice the order: translate by minus P, rotate by theta, then translate back by plus P; these steps combine into T(P) R(theta) T(-P).

Formulas

  • Translation: x′=x+tx,y′=y+tyx'=x+t_x,\qquad y'=y+t_y
  • Rotation counterclockwise about origin: x′=xcos⁡θ−ysin⁡θ,y′=xsin⁡θ+ycos⁡θx'=x\cos\theta-y\sin\theta,\qquad y'=x\sin\theta+y\cos\theta
  • Scaling about origin: x′=sxx,y′=syyx'=s_x x,\qquad y'=s_y y
  • xx-shear: x′=x+shxy, y′=yx'=x+sh_x y,\ y'=y; yy-shear: x′=x, y′=y+shyxx'=x,\ y'=y+sh_y x
  • Shears about reference lines: x′=x+shx(y−yref), y′=yx'=x+sh_x(y-y_{ref}),\ y'=y; y′=y+shy(x−xref), x′=x\quad y'=y+sh_y(x-x_{ref}),\ x'=x
  • Rotation about pivot (px,py)(p_x,p_y): x′=px+(x−px)cos⁡θ−(y−py)sin⁡θ,y′=py+(x−px)sin⁡θ+(y−py)cos⁡θx'=p_x+(x-p_x)\cos\theta-(y-p_y)\sin\theta,\qquad y'=p_y+(x-p_x)\sin\theta+(y-p_y)\cos\theta
  • Composite rotation about a pivot: M=T(px,py) R(θ) T(−px,−py)=[c−spx−pxc+pysscpy−pxs−pyc001]M=T(p_x,p_y)\,R(\theta)\,T(-p_x,-p_y)=\begin{bmatrix}c&-s&p_x-p_xc+p_ys\\ s&c&p_y-p_xs-p_yc\\ 0&0&1\end{bmatrix}
  • Composite scaling about a fixed point: M=T(px,py) S(sx,sy) T(−px,−py)M=T(p_x,p_y)\,S(s_x,s_y)\,T(-p_x,-p_y)
  • Area change: new area =∣sxsy∣×=|s_x s_y|\times old area; in general the factor is ∣det⁡M2×2∣|\det M_{2\times2}|
  • Homogeneous division: (x,y,w)≡(x/w, y/w)(x,y,w)\equiv(x/w,\ y/w) for w≠0w\neq0; w=0w=0 gives a point at infinity

Worked examples

Example 1 (easy, composite order). Rotate (2,0)(2,0) by 90∘90^\circ counterclockwise about the origin, then translate by (3,4)(3,4).

  1. rotation: x′=2cos⁡90∘−0=0x'=2\cos90^\circ-0=0, y′=2sin⁡90∘+0=2y'=2\sin90^\circ+0=2, giving (0,2)(0,2).
  2. translation: (0+3, 2+4)=(3,6)(0+3,\ 2+4)=(3,6).
    Composite matrix (translation applied last, so it is leftmost): [0−13104001]\begin{bmatrix}0&-1&3\\1&0&4\\0&0&1\end{bmatrix}, and indeed (2,0,1)(2,0,1) maps to (0−0+3, 2+0+4)=(3,6)(0-0+3,\ 2+0+4)=(3,6). Answer: (3,6)(3,6).

Example 2 (medium, scaling about a fixed point). Scale the point (2,1)(2,1) by sx=2, sy=3s_x=2,\ s_y=3 about the fixed point (1,1)(1,1).

  1. shift the fixed point to the origin: (2−1, 1−1)=(1,0)(2-1,\ 1-1)=(1,0).
  2. scale: (2⋅1, 3⋅0)=(2,0)(2\cdot1,\ 3\cdot0)=(2,0).
  3. shift back: (2+1, 0+1)=(3,1)(2+1,\ 0+1)=(3,1).
    Direct check with the closed form: x′=1+2(2−1)+0=3x'=1+2(2-1)+0=3, y′=1+0+3(1−1)=1y'=1+0+3(1-1)=1. Answer: (3,1)(3,1).

Example 3 (hard, rotation about an arbitrary point). Rotate the triangle A(0,0)A(0,0), B(1,1)B(1,1), C(5,2)C(5,2) by 45∘45^\circ counterclockwise about P(−1,−1)P(-1,-1). Use cos⁡45∘=sin⁡45∘=22\cos45^\circ=\sin45^\circ=\tfrac{\sqrt2}{2}.
A−P=(1,1)A-P=(1,1): rotated =(22−22, 22+22)=(0,2)=\left(\tfrac{\sqrt2}{2}-\tfrac{\sqrt2}{2},\ \tfrac{\sqrt2}{2}+\tfrac{\sqrt2}{2}\right)=(0,\sqrt2), so A′=(−1, 2−1)A'=(-1,\ \sqrt2-1).
B−P=(2,2)B-P=(2,2): rotated =(0, 22)=(0,\ 2\sqrt2), so B′=(−1, 22−1)B'=(-1,\ 2\sqrt2-1).
C−P=(6,3)C-P=(6,3): rotated =(6−32, 6+32)=(322, 922)=\left(\tfrac{6-3}{\sqrt2},\ \tfrac{6+3}{\sqrt2}\right)=\left(\tfrac{3\sqrt2}{2},\ \tfrac{9\sqrt2}{2}\right), so C′=(322−1, 922−1)C'=\left(\tfrac{3\sqrt2}{2}-1,\ \tfrac{9\sqrt2}{2}-1\right).
Answer: A′(−1,2−1)A'(-1,\sqrt2-1), B′(−1,22−1)B'(-1,2\sqrt2-1), C′(322−1,922−1)C'\left(\tfrac{3\sqrt2}{2}-1,\tfrac{9\sqrt2}{2}-1\right).

Example 4 (medium, matrix from correspondences). Find the homogeneous matrix that maps the unit square (0,0),(1,0),(0,1),(1,1)(0,0),(1,0),(0,1),(1,1) onto the parallelogram (0,0),(1,2),(2,1),(3,3)(0,0),(1,2),(2,1),(3,3).
Write x′=ax+by+cx'=ax+by+c, y′=dx+ey+fy'=dx+ey+f. From (0,0)↦(0,0)(0,0)\mapsto(0,0) we get c=f=0c=f=0. From (1,0)↦(1,2)(1,0)\mapsto(1,2): a=1, d=2a=1,\ d=2. From (0,1)↦(2,1)(0,1)\mapsto(2,1): b=2, e=1b=2,\ e=1. Check the fourth vertex: (1+2, 2+1)=(3,3)(1+2,\ 2+1)=(3,3) ✔.
Answer: M=[120210001]M=\begin{bmatrix}1&2&0\\2&1&0\\0&0&1\end{bmatrix}.

Example 5 (statement type). Statement I: A 2×22\times2 matrix with determinant 00 squeezes the whole plane onto a line or a single point. Statement II: Every orthogonal 2×22\times2 matrix represents a rotation.
Statement I is true — a singular matrix has linearly dependent columns, so all image points lie on one line through the origin (or on the origin itself). Statement II is false — orthogonality gives determinant +1+1 or −1-1; determinant −1-1 gives a reflection. Answer: I true, II false.

Comparison

TransformationParametersFixed elementsDeterminantPreserves
Translationtx,tyt_x,t_ynone11shape, size, orientation, angles
Rotationθ\thetathe pivot11shape, size, angles, orientation
Uniform scalingssthe fixed points2s^2shape, angles, orientation
Non-uniform scalingsx,sys_x,s_ythe fixed pointsxsys_xs_yparallelism only
Reflectionmirror lineevery point of the line−1-1shape, size, angles; reverses orientation
Shearshxsh_x or shysh_ypoints on the reference line11area, parallelism
ClassMatrix formPreserves
Linearany 2×22\times2origin fixed, lines and parallelism
Affine3×33\times3 with last row (0 0 1)(0\ 0\ 1)lines, parallelism, ratios along a line
Projective (homography)general 3×33\times3straight lines only; needs division by ww
Orthogonal matrix, det⁡=+1\det=+1Orthogonal matrix, det⁡=−1\det=-1
Rotation about the originReflection about a line through the origin
Object transformationCoordinate transformation
Moves the object, keeps the frameMoves the frame, keeps the object
Uses MM on the coordinatesUses M−1M^{-1} on the coordinates
Point (x,y)(x,y) goes to M(x,y)M(x,y)Same point has new coordinates M−1(x,y)M^{-1}(x,y)

Revision summary

  • Translation is the only primitive that a 2×22\times2 matrix cannot express — that is the entire reason for homogeneous coordinates.
  • Counterclockwise is positive; R=[c−ssc]R=\begin{bmatrix}c&-s\\ s&c\end{bmatrix}; clockwise flips the signs of the two sin⁡\sin terms.
  • The operation applied last is the leftmost matrix in a product.
  • Rotation or scaling about a pivot: T(pivot)⋅(operation)⋅T(−pivot)T(\text{pivot})\cdot(\text{operation})\cdot T(-\text{pivot}).
  • det⁡=+1\det=+1 means rotation; det⁡=−1\det=-1 means reflection; det⁡=0\det=0 means the object is flattened.
  • ∣det⁡∣|\det| is the area magnification factor.
  • Shear changes angles but not area (det⁡=1\det=1).
  • Inverse of a composite: reverse the order and invert each factor.
  • Uniform scaling keeps an object similar; non-uniform scaling does not.
  • In (x,y,w)(x,y,w), divide by ww; w=0w=0 is a point at infinity.
  • A 3×33\times3 affine matrix always has the last row (0 0 1)(0\ 0\ 1); a 4×44\times4 rotation about the z-axis keeps the zz row and column of the identity.
  • 45∘45^\circ values are 22\tfrac{\sqrt2}{2}; a 90∘90^\circ counterclockwise rotation sends (x,y)(x,y) to (−y,x)(-y,x).

Previous-year exam insights

  • Direct concept questions are common: "which transformation resizes an object" → scaling; "which changes only position" → translation; "which needs homogeneous coordinates" → translation.
  • Matrix-identification questions give a 3×33\times3 or 4×44\times4 matrix and ask for the operation or the axis.
    Check the diagonal, the off-diagonal ±sin⁡\pm\sin pair, the translation column and the last row first.
    A 4×44\times4 matrix whose upper-left 2×22\times2 block is a rotation block with 11 in the third diagonal position and 00 elsewhere rotates about the z-axis.
  • Order-of-application questions ("translated by … and rotated by …") are the biggest trap.
    Compute one point under both orders, or read which order produces the given translation column, before choosing.
  • Matrix-decomposition questions give a matrix such as [202011001]\begin{bmatrix}2&0&2\\0&1&1\\0&0&1\end{bmatrix} and ask which sequence it represents.
    Remember: translation first gives a translation column equal to the scaled translation; translation last gives it unchanged.
  • Rotation about a non-origin point requires the translate–rotate–translate recipe; wrong options swap the coordinates or use the wrong sign for sin⁡\sin, so verify one vertex completely.
  • Statement I/II questions test determinant-based classification (rotation vs reflection, singular vs invertible) and the fact that a sequence of reflections can equal a rotation.
  • Matrix-from-correspondence questions are solved by writing the six linear equations and checking the unused vertex.
  • Homogeneous-coordinate questions test w=0w=0 (point at infinity) and the general 4×44\times4 product, which is a projective transformation (homography).

Practice at PARIKSHA

You are ready for the PARIKSHA tests of this sub-topic when you can:

  1. State why translation cannot be written as a 2×22\times2 matrix and write its 3×33\times3 homogeneous form from memory.
  2. Write the counterclockwise and clockwise rotation matrices and use them on a point without sign errors.
  3. Decide in one glance whether a given 3×33\times3 matrix is translation, scaling, rotation, reflection or shear.
  4. Rotate and scale a point about an arbitrary pivot in three steps and quote the composite matrix.
  5. Expand a given homogeneous matrix into "first … then …" and justify the order.
  6. Build the matrix that maps three given points onto three given image points.
  7. Classify any 2×22\times2 matrix as rotation, reflection or singular using its determinant and orthogonality.
  8. State the area factor of any linear transformation and explain uniform versus non-uniform scaling.
  9. Write the shear formula relative to a reference line in both directions.
  10. Explain the meaning of w=0w=0 and of dividing by ww in homogeneous coordinates.

Attempt the sub-topic test on 2D transformations first; once you score comfortably, move to the full subject test.

Pages 1–2 of 2