Loading problem...
In computer graphics, robotics, and geometric processing, spatial transformations are fundamental operations that manipulate the position, orientation, and scale of objects in space. Among these transformations, translation is one of the most essential—it allows objects to be repositioned without altering their shape, size, or orientation.
A translation transformation shifts every point of an object by a constant displacement vector. In 2D space, this displacement is defined by two values: dx (horizontal shift) and dy (vertical shift). When applied to a point (x, y), the resulting position becomes (x + dx, y + dy).
This operation can be elegantly represented using homogeneous coordinates and matrix multiplication. By extending 2D points to 3D homogeneous form [x, y, 1], the translation can be expressed as:
$$\begin{bmatrix} x' \ y' \ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & d_x \ 0 & 1 & d_y \ 0 & 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} x \ y \ 1 \end{bmatrix}$$
Where:
The translation matrix is particularly valuable because it can be composed with other transformation matrices (rotation, scaling, shearing) through simple matrix multiplication, enabling complex sequences of transformations to be applied efficiently as a single operation.
Your Task: Implement a function that applies a 2D translation transformation to a collection of points. Given a list of 2D coordinates and displacement values for both axes, compute the new positions of all points after the translation is applied.
Key Concepts:
points = [[0, 0], [1, 0], [0.5, 1]]
dx = 2
dy = 3[[2.0, 3.0], [3.0, 3.0], [2.5, 4.0]]We have a triangle defined by three vertices at the origin and nearby positions. Applying a translation of (dx=2, dy=3):
• Point (0, 0) → (0+2, 0+3) = (2.0, 3.0) • Point (1, 0) → (1+2, 0+3) = (3.0, 3.0) • Point (0.5, 1) → (0.5+2, 1+3) = (2.5, 4.0)
The entire triangle has been shifted 2 units to the right and 3 units upward, preserving its original shape and size.
points = [[0, 0], [2, 0], [1, 2]]
dx = 5
dy = 5[[5.0, 5.0], [7.0, 5.0], [6.0, 7.0]]This triangle with vertices at (0,0), (2,0), and (1,2) is translated by 5 units in both directions:
• Point (0, 0) → (0+5, 0+5) = (5.0, 5.0) • Point (2, 0) → (2+5, 0+5) = (7.0, 5.0) • Point (1, 2) → (1+5, 2+5) = (6.0, 7.0)
The transformation moves the shape diagonally toward the upper-right quadrant.
points = [[3, 4]]
dx = -1
dy = -2[[2.0, 2.0]]A single point at (3, 4) is translated using negative displacement values:
• Point (3, 4) → (3+(-1), 4+(-2)) = (2.0, 2.0)
Negative translation values move objects in the opposite direction—leftward for negative dx and downward for negative dy. This demonstrates bidirectional translation capability.
Constraints