2D Transformations and Algorithms Interview Questions with Worked Answers
Build a convention-first answer to 2D transformation questions, then test it through composite matrices, pivot rotation, polygon code and inverse checks.
KnowledgeGate Team
Exam prep & CS education

Memorising translation, rotation, scaling, reflection and shearing is not enough when an interviewer changes the order, adds a pivot or asks for code that transforms every vertex. You need a fixed convention and a way to check the result. Work through two matrix examples, an implementation trace and common follow-up checks, using explicit coordinates and matrix checks for every step.
What is a 2D transformation? Give the 30-second interview answer
A 2D geometric transformation maps a point (x,y) to a new point (x',y'). An affine transformation can be represented by one 3 x 3 homogeneous matrix acting on the column vector [x,y,1]^T. A transformation algorithm applies the same mapping consistently to every point or vertex in an object.
State the convention before calculating: positive x points right, positive y points up, vectors are columns and positive angles turn counter-clockwise. Screen coordinates often place positive y downward, so copying a rotation sign without stating the coordinate system can reverse the answer.
Homogeneous coordinates matter because a 2 x 2 matrix can express linear operations but not translation. The third coordinate makes translation a matrix multiplication and allows several affine operations to become one composite matrix. A point uses w=1; a direction vector uses w=0, so translation does not move the direction.
What are the standard 2D transformation matrices?
Under that convention, these are the core matrices:
Operation | Homogeneous matrix | Effect and quick check for |
|---|---|---|
Translation |
| Adds an offset and preserves lengths and angles. With |
Scaling |
| Changes size; non-uniform scaling does not generally preserve angles. With |
Rotation |
| Preserves distances. At |
x-shear |
| Preserves parallelism but changes angles. With |
x-axis reflection |
| Keeps |
Reflection in |
| Swaps the coordinates and reverses orientation, giving |
The formula is only half the answer. Say what the operation preserves and test it on one simple point.
Why does transformation order matter? Work one composite matrix completely
Start with P=(2,1). Scale by S_x=2, S_y=3, rotate 90 degrees counter-clockwise about the origin, then translate by (4,-2):
S = [[2,0,0],[0,3,0],[0,0,1]]R = [[0,-1,0],[1,0,0],[0,0,1]]T = [[1,0,4],[0,1,-2],[0,0,1]]
With column vectors, the rightmost matrix acts first. Multiply without skipping the intermediate product:
RS = [[0,-3,0],[2,0,0],[0,0,1]]M = TRS = [[0,-3,4],[2,0,-2],[0,0,1]]
The stage-by-stage route is (2,1) -> (4,3) -> (-3,4) -> (1,2). Direct multiplication gives
M[2,1,1]^T=[0(2)-3(1)+4, 2(2)+0(1)-2, 1]^T=[1,2,1]^T, confirming the same result.
Order matters because changing it changes which coordinates each later operation receives. If the sequence is reversed to translate, rotate, then scale, the trace becomes (2,1) -> (6,-1) -> (1,6) -> (2,18). Thus TRS != SRT, and the same inputs produce (1,2) in one order and (2,18) in the other.

How do you rotate around a pivot instead of the origin?
Rotate A=(5,3) by 90 degrees counter-clockwise around C=(2,1). First move the pivot to the origin, then rotate, then move it back. In matrix form, the algorithm is T(2,1) R(90 degrees) T(-2,-1), with the rightmost translation acting first.
Coordinate by coordinate, A-C=(5-2,3-1)=(3,2). A 90-degree counter-clockwise rotation maps (3,2) to (-2,3). Add the pivot back: A'=(-2+2,3+1)=(0,4).
Multiplying the three matrices gives M_C=[[0,-1,3],[1,0,-1],[0,0,1]]. It verifies the answer because M_C[5,3,1]^T=[0,4,1]^T. It also keeps the pivot fixed: M_C[2,1,1]^T=[2,1,1]^T. Finally, squared distance from the pivot is 3^2+2^2=13 before rotation and (-2)^2+3^2=13 after it. All three checks agree.

How would you implement a 2D transformation algorithm for a polygon?
Precompute the composite matrix once, then run one pass over the vertices:
for each vertex (x, y):
(xNew, yNew, wNew) = M * (x, y, 1)
if wNew == 0:
handle a point at infinity
else if wNew != 1:
store (xNew / wNew, yNew / wNew)
else:
store (xNew, yNew)
recompute derived data such as the bounding boxFor an affine matrix, wNew=1. The division supports a more general projective matrix.
Trace the previous M=[[0,-3,4],[2,0,-2],[0,0,1]] over triangle A=(1,1), B=(4,1), C=(2,3). The rule is x'=-3y+4, y'=2x-2, so A'=(1,0), B'=(1,6) and C'=(-5,2). The new axis-aligned bounding box is x in [-5,1], y in [0,6].
After M is ready, transforming n vertices takes O(n) time. An out-of-place result uses O(n) output space; in-place replacement needs O(1) auxiliary space. For another example of comparing time, space and behaviour, see Sorting Algorithms: Comparison and Complexity, while keeping in mind that sorting and geometric transformation solve different problems.
What follow-ups test whether you really understand the matrix?
For the inverse, undo both the operations and their order. Since M=TRS, M^-1=S^-1 R^-1 T^-1, not T^-1 R^-1 S^-1. For this example,
M^-1=[[0,1/2,1],[-1/3,0,4/3],[0,0,1]]. Applying it to (1,2) gives x=0(1)+(1/2)(2)+1=2 and y=(-1/3)(1)+0(2)+4/3=1, so it returns (2,1).
The linear block of M is [[0,-3],[2,0]]. Its determinant is 0(0)-(-3)(2)=6, so the transformation is invertible. If either scale factor is zero, the determinant becomes zero, information is lost and no two-sided inverse exists.
Three short oral checks complete the answer:
Matrix multiplication is associative but not commutative.
Rotation about the origin is linear; translation is affine.
Row-vector notation is valid only when the matrices and multiplication order are transposed consistently.
Never mix row and column conventions within one calculation.
Which mistakes turn a correct definition into a wrong interview answer?
Pair each common trap with a repair:
Under a column-vector convention, write the verbal operation order first, then build the product so the first operation is rightmost.
Test a
90-degreecounter-clockwise matrix on(1,0). It must produce(0,1), not(0,-1).For pivot rotation, verify that
Cmaps to itself.Give a direction vector
w=0, so translation does not affect it.Keep exact fractions or radicals through intermediate steps and round only the final result if needed.
A realistic practice ladder is: define homogeneous coordinates, transform one point, compose three operations, rotate around a pivot, derive or apply the inverse, then write the O(n) vertex loop and discuss edge cases. The DSA interview question patterns for placements are useful preparation. Actual rounds vary by role and employer.
The short answer and the next practice step
The recall line has four parts: state the coordinate convention, write points as [x,y,1]^T, compose matrices in the order required by that convention, and validate with a known point, a fixed pivot, a distance check or the inverse. Next, use the Algorithms course to strengthen analysis and problem solving, the Interview & Resume Preparation course to practise concise spoken answers, and the CS Fundamentals for Placements course for a broader learning path.
Keep learning
2D Transformations in Computer Graphics: Matrices, Algorithms and Worked Examples
Build 2D transformation fluency with one matrix convention, a step-by-step composite transform, and a complete window-to-viewport calculation.
2-D Transformations and Algorithms MCQs: 12 Solved Questions with Explanations
Attempt 12 solved 2-D transformation MCQs on scaling, reflection, rotation, shearing and viewing, with a formula sheet and the trap behind each wrong option.
1D and 2D Array Addressing: Formulas, Worked Examples and Exam Traps
Build array-address formulas by counting the elements before a target. Then solve bounded 1D and 2D examples without mixing up offsets, widths or layouts.
1D and 2D Array Addressing MCQs: 12 Solved Questions
Solve 12 array-address questions step by step, from negative lower bounds and 1D offsets to row-major, column-major, triangular and tri-diagonal storage.





