Computer Graphics (rasterisation, ray tracing, WebGPU) Module 4
2D transformations, viewing and clipping interview questions
Interview questions on 2D transformations, viewing and clipping: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
How do you rotate a shape about a point that is not the origin?
Answered in the lesson 2D transformations and composite transforms
-
Fresher to mid
What does the window-to-viewport transformation do, and what is its formula?
Answered in the lesson Window-to-viewport mapping and coordinate systems
-
Fresher to mid
How do Cohen-Sutherland region codes accept or reject a segment without computing an intersection?
Answered in the lesson Line clipping: Cohen-Sutherland and Liang-Barsky
-
Fresher to mid
What are the four cases of Sutherland-Hodgman, and what does each output?
Answered in the lesson Polygon clipping: Sutherland-Hodgman and beyond
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
An animation tool moves a sprite from a start matrix to an end matrix by interpolating each matrix entry. A sprite that turns by 180° shrinks to a point halfway, and one that turns by 90° looks about 29 % smaller in the middle frame. Explain both and fix the animation.
- What it tests
- That blending matrix entries is not blending a motion, decomposing into parts that can be blended, and turning the short way round.
- First step
- Compute the middle frame of the 90° turn: the average of R(0°) and R(90°) has rows [0.5, −0.5] and [0.5, 0.5], which is R(45°) scaled by 0.707. For the 180° turn the ends are the identity and its negative, and their average is the zero matrix, which sends every point to the same place.
- Follow-ups
-
- The sprite turns from 170° to −170°. Which way should it go?
- What if the end matrix is mirrored and the start is not?
- Why does CSS decompose matrices before animating them?
From the lesson 2D transformations and composite transforms
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A vector drawing tool needs "mirror the selection across a guide line", where the guide can be drawn at any angle through any point. Build the transformation for a guide through (2, −1) and (5, 3), say what goes wrong if you build it from the line's slope, and describe the tests you would ship with it.
- What it tests
- Composing a mirror in an arbitrary line from translations, rotations and a reflection, handling vertical guides, and testing with invariants instead of pixels.
- First step
- Describe the guide by a point and a direction, not a slope: (2, −1) and (3, 4). Move the point to the origin, turn the direction onto the x axis, mirror, and undo both: T(2, −1) R(θ) F R(−θ) T(−2, 1), with θ the guide's angle, 53.130°. Multiplied out, its rows are [−0.28, 0.96, 3.52] and [0.96, 0.28, −2.64].
- Follow-ups
-
- Why is the slope-and-intercept form of the guide a trap?
- The user drags the guide and the preview redraws every frame. What do you compute per frame?
- How would you test the tool without comparing pixels?
From the lesson 2D transformations and composite transforms
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A chart canvas, 400 × 200 CSS pixels, was blurry on phones. A first fix set canvas.width to 400 times devicePixelRatio at page load and multiplied every tap's offsetX by devicePixelRatio. Now, after a user zooms the page, the chart blurs again and taps select the wrong bar. Explain both and fix them.
- What it tests
- That the bitmap must follow devicePixelRatio and the box whenever either changes, and that taps convert with the canvas's own bitmap-to-box ratio, not with devicePixelRatio.
- First step
- Write down the sizes after the zoom. On a ratio-2 phone at 200 % zoom the box is still 400 CSS pixels wide, the bitmap is still 800 pixels, sized at load, and devicePixelRatio is now 4. The bitmap is stretched again, and a tap at offsetX 100, times the new ratio, is read as bitmap pixel 400 instead of 200.
- Follow-ups
-
- How does the page notice that the ratio or the box has changed?
- What does a sharp bitmap cost in memory on a ratio-3 phone?
- Why convert taps with the bitmap-to-box ratio rather than devicePixelRatio?
From the lesson Window-to-viewport mapping and coordinate systems
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A map view shows a window of 4 by 2 km in a resizable panel. When the panel is made square, circles turn into ellipses. The product team wants no distortion and no empty bars, and the place under the pointer should stay put while the user zooms. Design the mapping.
- What it tests
- One scale for both axes, a visible window that follows the panel's shape instead of bars, and zooming about the pointer with the pivot sandwich.
- First step
- Keep one scale for both axes and let the window follow the panel. With the scale that still fits the whole 4 km width into a 300 px square, 75 px per km, the visible window becomes 4 by 4 km, centred where it was: more of the map shows above and below instead of bars.
- Follow-ups
-
- The panel becomes 200 by 400 px. What does the user see now?
- How do you keep the point under the pointer fixed while zooming?
- When is letterboxing still the better choice?
From the lesson Window-to-viewport mapping and coordinate systems
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
A plan viewer clips 2 million line segments against the screen rectangle every frame, and the team must choose between Cohen-Sutherland and Liang-Barsky. Users spend most of their time zoomed in on a small part of the plan. Make the choice with numbers, and say how you would confirm it.
- What it tests
- What each algorithm computes per segment, how the scene changes the cost, and deciding from measurements on recorded data instead of folklore.
- First step
- Count before timing. In a zoomed-in scene like the lesson's, the region codes rejected 63.1 % of segments with comparisons alone; Cohen-Sutherland made 0.707 cuts a segment and Liang-Barsky 2.799 divisions and 0.328 points. At 2 million segments that is about 1.4 million divisions against 5.6 million a frame.
- Follow-ups
-
- Can you get the strengths of both?
- What changes when the user zooms out to the whole plan?
- How would you make the measurement trustworthy?
From the lesson Line clipping: Cohen-Sutherland and Liang-Barsky
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A drawing app lets users turn the view by any angle, so the visible region is a rotated rectangle in world coordinates, but its clipper only handles axis-aligned windows. Give two ways to clip world-space segments correctly, compare their cost and accuracy, and choose one.
- What it tests
- Combining coordinate frames with clipping: moving segments into the window's frame against Cyrus-Beck with edge normals, their cost per segment, and where coordinates stay exact.
- First step
- Describe the window as a frame: its centre, its turned axes u and v, and its half-width and half-height. Either move each segment into that frame with the frame's inverse and clip there against an axis-aligned rectangle, or keep world coordinates and give Cyrus-Beck the four outward normals u, −u, v and −v.
- Follow-ups
-
- Which way leaves clipped endpoints exactly on the window's edges?
- What changes if the view also scales x and y differently?
- What do you hand to the renderer afterwards?
From the lesson Line clipping: Cohen-Sutherland and Liang-Barsky
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A web map clips building footprints to each tile with Sutherland-Hodgman before drawing them. Filled buildings look right, but outlined buildings that cross a tile's edge show thin lines across empty ground, and a click near the edge sometimes selects a building that is not there. Explain both and fix them.
- What it tests
- Recognising zero-area bridge edges on concave footprints, which uses of the result they break, and fixes that keep filling, outlining and hit testing each correct.
- First step
- Clip one affected footprint and list the output's edges that lie on the tile's edge. Where two of them cover the same stretch in opposite directions, the net count is 0: a bridge joining two separate pieces, like the stretches from y = 2 to 4 and 6 to 8 on x = 3 in the lesson's clipped E.
- Follow-ups
-
- Why do the filled buildings look right?
- How do you draw the outlines without the false walls?
- What would you use for the click test, and why?
From the lesson Polygon clipping: Sutherland-Hodgman and beyond
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A software renderer divides every vertex by w and then clips the projected triangles to the screen. When the camera moves close to a wall, huge triangles flash across the screen, some of them mirrored. Explain what happens, with a small example, and fix the pipeline.
- What it tests
- Clipping in clip space before the perspective divide, why a vertex with w at or below 0 breaks the divide, and Sutherland-Hodgman against the near plane.
- First step
- Take a triangle with one corner behind the camera, such as the clip positions (−1, 0, 1, 2), (1, 0, 1, 2) and (0, 1, −2, −1). Dividing by w sends the third corner to (0, −1), below the centre, although it lies above the camera's axis: the projected triangle is not part of the real one.
- Follow-ups
-
- Why do vertices with w close to 0 make triangles enormous?
- Which planes must be clipped before the divide, and which could wait?
- How do colours and texture coordinates get values at the new vertices?
From the lesson Polygon clipping: Sutherland-Hodgman and beyond
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
All Computer Graphics (rasterisation, ray tracing, WebGPU) interview questions · The Computer Graphics (rasterisation, ray tracing, WebGPU) track