📘
2D Scaling Matrix
EasyGeometry
Implement a 3×3 homogeneous transformation matrix for 2D scaling, a fundamental concept in 2D/3D Transformations. This transformation is crucial in Computer Vision as it allows images to be resized while maintaining their aspect ratio.
In 2D space, scaling is a linear transformation that enlarges or reduces objects by a certain factor. The scaling factors sx and sy determine how much an object is stretched or shrunk along the x and y axes. To represent this transformation mathematically, we use a matrix equation.
To create the scaling matrix, follow these steps:
- Define the scaling factors sx and sy.
- Construct a 3×3 matrix with sx and sy on the diagonal.
This technique is widely used in image processing applications.
Example:
Input:
scaling_matrix(2, 3)
Output:
[[2,0,0],[0,3,0],[0,0,1]]
Reasoning:
- The function is called with scaling factors sx=2 and sy=3:
scaling_matrix(2, 3). - For 2D homogeneous scaling, we place sx and sy on the main diagonal of a 3×3 matrix, with 1 in the bottom-right:
S=sx000sy0001. - Substituting sx=2, sy=3 gives
S=200030001,
which corresponds to[[2,0,0],[0,3,0],[0,0,1]].
Constraints:
- sx and sy are positive floating-point numbers
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.