Linear Algebra • Affine Transformations Flagship

2D Scaling Matrix Generator

Generate standard $2\times 2$ diagonal scaling matrices and $3\times 3$ affine transformation matrices in real time. Visualize uniform and differential scaling on an interactive Cartesian coordinate canvas, scale about custom center pivots $(c_x, c_y)$, inspect area magnification factors, and export code directly to CSS, SVG, Python, and JavaScript.

Reviewed by Sanjay Samanta & Academic Review Board Last updated: September 2026 Area-Scaling & Affine Invariants Verified
2D Scaling Matrix Generator S(s_x, s_y) Diagonal Affine Group GL(2, ℝ) Uniform Scaling
Scale Factors (s_x, s_y)
-4.0 (Inverted) 0.0 (Singular) +4.0 (Expanded)
-4.0 (Inverted) 0.0 (Singular) +4.0 (Expanded)
Point to Transform: v = (x, y) Original Coordinates
Center of Scaling: C = (c_x, c_y)

Scale shapes relative to a custom center point rather than the origin. Points move outward or inward relative to C.

Cartesian Plane & Transformation Visualizer
Original (Area=1) Scaled
+X +Y
Area Scale 4.00×
Orientation Preserved (+)
Invertibility Invertible
Calculated 2D Scaling Matrix S
Standard Euclidean Matrix (2×2)
[
2.0 0 0 2.0
]
Affine Homogeneous Matrix (3×3)
[
2.0 0 0.0 0 2.0 0.0 0 0 1
]
Coordinate Mapping Formula
x' = s_x · x = 2.0 · x,   y' = s_y · y = 2.0 · y
v' = (4.00, 6.00)
Determinant det(S) 4.00
Trace tr(S) 4.00
Eigenvalues λ λ₁=2, λ₂=2
Inverse S⁻¹ diag(0.5, 0.5)
Developer Code Exports
transform: scale(2, 2);
Direct Answer & Overview
Verified Educational Guide

How to Calculate 2D Scaling Transformation Matrices

A 2D scaling matrix expands, contracts, or reflects coordinates along the Cartesian axes. For horizontal scale factor s_x and vertical scale factor s_y, the 2x2 matrix has s_x and s_y on the main diagonal with 0s elsewhere. Coordinates map as x' = s_x · x and y' = s_y · y. The determinant det(S) = s_x · s_y represents the exact geometric area scale factor.

Primary Mathematical Formula Standard Mathematical Model
Standard Equation
ƒ(x)
Q.E.D.
S(s_x, s_y) = [[s_x, 0], [0, s_y]], quad x' = s_x(x - c_x) + c_x, quad y' = s_y(y - c_y) + c_y
Evaluated with exact mathematical formulation • Rigorously verified
Exact Formula
Input Parameters
Required
1
Horizontal Scale Factor (s_x)
2
Vertical Scale Factor (s_y)
3
Center of Scaling Pivot C = (c_x, c_y)
4
Input Vector Point v = (x, y)
Expected Outputs
Calculated
2×2 Diagonal Scaling Matrix S
3×3 Affine Homogeneous Coordinate Matrix
Transformed Coordinates (x', y')
Determinant det(S) = s_x · s_y (Area Scale Factor)
Inverse Matrix S⁻¹ and CSS / SVG / NumPy Code Snippets
Worked Numerical Example
Instant Verification
Scale coordinate point (4, -2) by horizontal factor s_x = 2.5 and vertical factor s_y = 0.5.
→ x' = 2.5 × 4 = 10, y' = 0.5 × (-2) = -1.0; det(S) = 2.5 × 0.5 = 1.25
v' = (10, -1) with 1.25× surface area scaling
Geometric Foundations

What is 2D Scaling in Linear Algebra?

In linear algebra and Euclidean geometry, a 2D scaling transformation is a linear mapping that multiplies the coordinates of every point in the plane by independent scale factors along each orthogonal basis direction. Depending on the values of the scale factors $s_x$ and $s_y$, the geometry undergoes expansion, contraction, reflection, or dimension collapse.

Uniform (Isotropic) Scaling
s_x = s_y = s

When horizontal and vertical scale factors are identical, all distances from the origin change by the exact ratio $s$. The shape expands or shrinks uniformly, preserving all internal angles, aspect ratios, and geometric similarity.

Differential (Anisotropic) Scaling
s_x \neq s_y

When horizontal and vertical scale factors differ, the geometry is stretched along one axis relative to the other. Aspect ratios change, internal angles are altered, and circles distort into ellipses with semi-major axes governed by $s_x$ and $s_y$.

Mathematical Derivation

Derivation of the 2D Scaling Matrix

Every linear transformation T on the Cartesian plane ℝ² is completely determined by how it acts on the standard Euclidean basis vectors e₁ = [1, 0]ᵀ and e₂ = [0, 1]ᵀ.

Basis Vector Mapping:

T(e₁) = S · [1, 0]ᵀ = [s_x · 1, s_y · 0]ᵀ = [s_x, 0]ᵀ

T(e₂) = S · [0, 1]ᵀ = [s_x · 0, s_y · 1]ᵀ = [0, s_y]ᵀ

Constructing the transformation matrix S by placing T(e₁) and T(e₂) as column vectors yields the canonical 2×2 scaling matrix:

S(s_x, s_y) = [ [s_x, 0], [0, s_y] ]

Multiplying any arbitrary coordinate vector v = [x, y]ᵀ by S produces the scaled coordinates:

[x', y']ᵀ = [ [s_x, 0], [0, s_y] ] · [x, y]ᵀ = [s_x · x, s_y · y]ᵀ
Affine Geometry

Scaling About an Arbitrary Center Point C = (c_x, c_y)

The standard 2×2 scaling matrix scales all coordinates relative to the coordinate origin (0, 0). If an object is located away from the origin, scaling by S not only resizes it but also translates its center of mass away from or toward the origin.

The Three-Step Affine Composition:
  1. Translate Center to Origin: Shift all points by T(-c_x, -c_y) so that the pivot point (c_x, c_y) aligns with (0, 0).
  2. Scale at Origin: Apply the standard scaling matrix S(s_x, s_y).
  3. Translate Back: Reverse the initial shift by applying T(c_x, c_y) to restore the center position.

Algebraically, the resulting coordinates for any point (x, y) are given by:

x' = s_x(x - c_x) + c_x,      y' = s_y(y - c_y) + c_y

In computer graphics pipelines, this composite transformation is represented in 3×3 homogeneous coordinates as a single matrix multiplication:

[x', y', 1]ᵀ = [ [s_x, 0, c_x(1 - s_x)], [0, s_y, c_y(1 - s_y)], [0, 0, 1] ] · [x, y, 1]ᵀ
Area Scaling & Orientation

Determinant and Surface Area Magnification

The determinant of any linear transformation matrix measures how the transformation scales 2D surface area. For a diagonal scaling matrix, computing the determinant is instantaneous:

det(S) = (s_x · s_y) - (0 · 0) = s_x · s_y
det(S) > 0

Orientation is preserved. Vertex order (clockwise vs. counter-clockwise) remains identical.

det(S) < 0

Orientation is inverted (reflection). One coordinate axis is flipped, reversing vertex winding.

det(S) = 0

Degenerate/Singular projection. Geometry collapses into a 1D line or 0D point. Area is zero.

This aligns precisely with the Jacobian determinant in multivariable calculus: when substituting variables under x = s_x · u, y = s_y · v, the differential area element scales as dx dy = |det(J)| du dv = |s_x · s_y| du dv.

Spectral Analysis

Eigenvalues, Eigenvectors, and Matrix Inverses

Because a 2D scaling matrix is already diagonal in the standard Euclidean basis, its spectral properties are immediately readable:

Eigenvalues & Eigenvectors
  • • λ₁ = s_x with eigenvector v₁ = [1, 0]ᵀ (X-axis)
  • • λ₂ = s_y with eigenvector v₂ = [0, 1]ᵀ (Y-axis)

The coordinate axes themselves represent the invariant eigen-directions.

Inverse Scaling Matrix S⁻¹
S⁻¹ = [ [1/s_x, 0], [0, 1/s_y] ]   (s_x, s_y ≠ 0)

Multiplying S by S⁻¹ produces the identity matrix I₂, reversing the scale exactly.

Step-by-Step Solutions

Worked Numerical Examples

Example 1: Uniform Expansion (s = 3) Scale at Origin

Problem: Scale point P(2, -4) uniformly by factor s = 3. Find the new coordinates and area magnification factor.

1. Form matrix: S = [ [3, 0], [0, 3] ]

2. Multiply: [x', y']ᵀ = [ [3, 0], [0, 3] ] · [2, -4]ᵀ = [3(2), 3(-4)]ᵀ = [6, -12]ᵀ

3. Area factor: det(S) = 3 × 3 = 9.0

Answer: P' = (6, -12); surface area expands by 9×.

Example 2: Differential Scaling (s_x = 2, s_y = 0.5) Aspect Ratio Shift

Problem: A rectangle with vertices at (0,0), (3,0), (3,2), (0,2) has area 3 × 2 = 6. Scale with s_x = 2, s_y = 0.5.

1. Transformed vertices: (0·2, 0·0.5)=(0,0); (3·2, 0·0.5)=(6,0); (3·2, 2·0.5)=(6,1); (0·2, 2·0.5)=(0,1)

2. New dimensions: Width = 6, Height = 1

3. New Area: 6 × 1 = 6; det(S) = 2 × 0.5 = 1.0

Answer: Vertices are (0,0), (6,0), (6,1), (0,1). Area is unchanged because det(S) = 1.0.

Example 3: Scaling About Custom Center C(3, 4) with s = 2 Affine Pivot

Problem: Scale point P(5, 7) by uniform factor s = 2 using center of scaling C(3, 4).

1. Subtract center: Δx = 5 - 3 = 2,   Δy = 7 - 4 = 3

2. Scale displacements: Δx' = 2 × 2 = 4,   Δy' = 2 × 3 = 6

3. Add center back: x' = 4 + 3 = 7,   y' = 6 + 4 = 10

Answer: P' = (7, 10). Notice distance from C doubled from √13 to 2√13.

Real-World Engineering

Where 2D Scaling Matrices Are Used

1. Web Standards (CSS & SVG)

Modern web rendering engines execute hardware-accelerated matrix transforms. CSS properties like `transform: scale(sx, sy)` and SVG `transform="matrix(sx, 0, 0, sy, 0, 0)"` apply these exact linear transformations via the user's GPU compositor.

2. Computer Vision & AI Augmentation

In convolutional neural network (CNN) and vision transformer training, random scaling matrices augment dataset diversity. Bounding boxes in object detection (YOLO, Faster R-CNN) transform their vertex coordinates via $S(s_x, s_y)$.

3. CAD & Architectural Drafting

AutoCAD and architectural blueprint software use scaling matrices to project real-world millimeter dimensions onto scaled viewport layouts (e.g. 1:50 or 1:100 scale architectural plans).

4. Video Games & Canvas Rendering

2D game engines (Unity 2D, Godot, PixiJS) compute local-to-world model matrices by multiplying Translation $\times$ Rotation $\times$ Scale ($TRS$) for every sprite and hitbox in the game scene.

Common Mistakes

Common Pitfalls & How to Avoid Them

Pitfall 1: Confusing Origin Scaling with Center-of-Object Scaling

Applying $S$ directly to an object centered at $(100, 100)$ with $s = 2$ moves its center to $(200, 200)$, inadvertently flying it across the screen. Always use the affine formulation $x' = s(x - c_x) + c_x$ to scale an object in place around its own bounding box centroid.

Pitfall 2: Forgetting That Scale Factors Multiply for Area, Not Add

If an image is enlarged by $s = 2$, its surface area quadruples ($2^2 = 4$), not doubles. Similarly, perimeter scales linearly by $s$, but area scales quadratically by $s^2$.

Pitfall 3: Matrix Multiplication Order with Rotation & Shear

While two diagonal scaling matrices commute with each other ($S_1 S_2 = S_2 S_1$), scaling does not commute with rotation or shearing in general ($R \cdot S \neq S \cdot R$). Scaling first then rotating stretches along the local object axes; rotating first then scaling stretches along the world axes!

Frequently Asked Questions

What is a 2D scaling matrix and how does it work?
A 2D scaling matrix is a 2×2 diagonal linear transformation matrix in Euclidean space that expands, compresses, or reflects geometric coordinates along the Cartesian axes. For horizontal scale factor s_x and vertical scale factor s_y, the standard matrix is S = [[s_x, 0], [0, s_y]]. Multiplying a column coordinate vector [x, y]ᵀ by S produces the scaled coordinates x' = s_x · x and y' = s_y · y.
What is the difference between uniform and non-uniform (differential) scaling?
Uniform (isotropic) scaling occurs when both scale factors are identical (s_x = s_y = s). It enlarges or shrinks an object uniformly, strictly preserving all internal angles, aspect ratios, and geometric similarity. Non-uniform (anisotropic or differential) scaling occurs when s_x ≠ s_y, stretching or squishing the object along one axis and altering aspect ratios, angles, and eccentricities (e.g., transforming a circle into an ellipse).
How do you scale a 2D shape about an arbitrary center point (c_x, c_y) instead of the origin?
To scale about a custom pivot point C = (c_x, c_y), you execute a composite affine sequence: (1) Translate the pivot point to the coordinate origin: T(-c_x, -c_y); (2) Apply the standard 2D scaling matrix: S(s_x, s_y); (3) Translate back to the original position: T(c_x, c_y). Algebraically, each point transforms as x' = s_x(x - c_x) + c_x and y' = s_y(y - c_y) + c_y. In 3×3 homogeneous coordinates, this corresponds to a single affine matrix with translation column [c_x(1 - s_x), c_y(1 - s_y), 1]ᵀ.
How does a 2D scaling matrix affect the surface area of a shape?
The surface area of any 2D polygon or bounded region transforms by the absolute value of the matrix determinant: Area' = |det(S)| · Area = |s_x · s_y| · Area. For example, doubling both dimensions (s_x = s_y = 2) expands the surface area by a factor of 2 × 2 = 4. If det(S) is negative, the area expands by |det(S)| while spatial orientation (vertex winding order) is inverted.
What happens geometrically when a scale factor is negative?
A negative scale factor produces a reflection across a coordinate axis combined with scaling. If s_x < 0 and s_y > 0, the shape is reflected horizontally across the vertical Y-axis. If s_y < 0 and s_x > 0, it is reflected vertically across the horizontal X-axis. If both are negative (s_x < 0, s_y < 0), the transformation is equivalent to a point inversion through the origin (a 180° rotation when |s_x| = |s_y|).
When is a 2D scaling matrix non-invertible (singular)?
A 2D scaling matrix is non-invertible (singular) whenever either scale factor equals zero (s_x = 0 or s_y = 0). When a scale factor is zero, det(S) = s_x · s_y = 0, causing all points to collapse into a flat one-dimensional line or a single zero-dimensional point. Because dimensional information is permanently lost, no inverse matrix exists. When both s_x ≠ 0 and s_y ≠ 0, the inverse is simply S⁻¹ = [[1/s_x, 0], [0, 1/s_y]].
How are 2D scaling transformations implemented in CSS, SVG, and graphics engines?
In web stylesheets, 2D scaling is declared via CSS `transform: scale(sx, sy)` or affine matrix `transform: matrix(sx, 0, 0, sy, 0, 0)`. In SVG, it is specified as `<g transform="scale(sx, sy)">`. In 2D canvas graphics (HTML5 Canvas or WebGL), developers use `ctx.scale(sx, sy)` or construct 3×3 homogeneous projection matrices in GLSL shader pipelines.