askvity

How to Apply a Transformation Matrix to a Vector?

Published in Linear Algebra Transformations 4 mins read

Applying a transformation matrix to a vector is a fundamental operation in linear algebra, computer graphics, and physics. It's the process used to change the position, orientation, scale, or shear of vectors in space.

The Core Concept: Matrix-Vector Multiplication

To transform a vector using a transformation matrix, you need to multiply the transformation matrix with that vector. This essential step directly incorporates the method described in the provided reference. The result of this multiplication is a new vector, often referred to as the transformed vector.

This transformed vector may have its length, direction, or both altered compared to the original vector.

Why Multiplication?

Matrix multiplication is the mathematical operation designed to combine the linear effects encoded in a matrix (like rotation, scaling, etc.) and apply them to a vector. Each element in the resulting vector is a weighted sum of the elements from the original vector, where the weights are provided by the rows of the transformation matrix.

The Process in Detail

Let's break down the steps and concepts involved:

  1. Identify the Vector: You start with an original vector, often represented as a column vector. For example, a 2D vector v = (x, y) can be written as:

    [ x ]
    [ y ]

    Or a 3D vector v = (x, y, z) as:

    [ x ]
    [ y ]
    [ z ]
  2. Identify the Transformation Matrix: You have a transformation matrix, typically denoted as M. The dimensions of this matrix depend on the dimension of the space the vector is in and the type of transformation. For an N-dimensional vector, the matrix is usually N x N (for transformations centered at the origin like rotation or scaling) or (N+1) x (N+1) if using homogeneous coordinates to include translation.

  3. Perform Matrix-Vector Multiplication: The transformed vector, let's call it v', is obtained by multiplying the matrix M by the vector v:

    v' = M * v

    It is crucial that the matrix is on the left and the vector is on the right. The number of columns in the matrix M must equal the number of rows in the vector v.

Example: 2D Scaling

Suppose you have a 2D vector v = (2, 1) that you want to scale by a factor of 2 in the x-direction and 3 in the y-direction.

The scaling matrix S for 2D is:

[ Sx  0 ]
[ 0  Sy ]

Where Sx = 2 and Sy = 3. So, S is:

[ 2  0 ]
[ 0  3 ]

The vector v is:

[ 2 ]
[ 1 ]

To find the transformed vector v', we perform the multiplication S * v:

v' = [ 2  0 ] * [ 2 ]
     [ 0  3 ]   [ 1 ]

The calculation is:

  • First element of v': (2 2) + (0 1) = 4 + 0 = 4
  • Second element of v': (0 2) + (3 1) = 0 + 3 = 3

So the transformed vector v' is:

[ 4 ]
[ 3 ]

Or v' = (4, 3). The original vector (2, 1) has been scaled as intended.

General Formula for Matrix-Vector Multiplication

For a 2x2 matrix M and a 2D vector v:

M = [[ a, b ], [ c, d ]]
v = [[ x ], [ y ]]

v' = M * v =

[ a  b ] * [ x ] = [ (a*x) + (b*y) ]
[ c  d ]   [ y ]   [ (c*x) + (d*y) ]

The resulting vector v' is [[ (a*x) + (b*y) ], [ (c*x) + (d*y) ]].

Table Summary

Component Description Representation
Original Vector The vector before transformation. v
Transformation The linear transformation (e.g., rotation, scale). M (Matrix)
Operation How the transformation is applied. Matrix-Vector Multiplication
Result The vector after transformation. v' (Transformed Vector)

Important Considerations

  • Order Matters: Matrix multiplication is not commutative. M * v is different from v * M (in fact, v * M is usually not even a valid operation because the dimensions don't match).
  • Homogeneous Coordinates: For transformations like translation (moving the vector), vectors are often represented using homogeneous coordinates, adding an extra dimension (e.g., a 2D vector (x, y) becomes (x, y, 1)). The transformation matrix is then also augmented (e.g., 3x3 for 2D transformations). This allows all basic affine transformations (translate, rotate, scale, shear) to be represented as matrix multiplications.
  • Composition of Transformations: Multiple transformations can be combined into a single transformation matrix by multiplying the individual matrices together. The order of matrix multiplication matters here as well.

By performing the matrix-vector multiplication, you effectively apply the geometric changes encoded within the transformation matrix to the vector, yielding its new state.

Related Articles