askvity

How to Rotate a Vector with a Matrix?

Published in Linear Algebra 3 mins read

You rotate a vector using a matrix by multiplying the rotation matrix with the vector's coordinates. This transformation effectively changes the vector's orientation in a coordinate system.

Understanding Rotation Matrices

A rotation matrix is a transformation matrix that rotates a vector about an axis by a specific angle. The specific form of the matrix depends on the dimension of the space (2D, 3D, etc.) and the axis of rotation.

2D Rotation

In a 2D space, the rotation matrix for rotating a vector counter-clockwise by an angle θ is:

[ cos(θ)  -sin(θ) ]
[ sin(θ)   cos(θ) ]

To rotate a vector v = [x, y]T, you multiply the rotation matrix R with the vector v:

v' = R * v

Which expands to:

[x'] = [ cos(θ)  -sin(θ) ] [x]
[y'] = [ sin(θ)   cos(θ) ] [y]

Therefore:

  • x' = x cos(θ) - y sin(θ)
  • y' = x sin(θ) + y cos(θ)

Where (x', y') are the coordinates of the rotated vector.

3D Rotation

In 3D space, rotations are more complex as they involve rotations around the x, y, and z axes. Common rotation matrices are:

  • Rotation about the x-axis (Rx):

    [ 1     0       0     ]
    [ 0   cos(θ)  -sin(θ) ]
    [ 0   sin(θ)   cos(θ) ]
  • Rotation about the y-axis (Ry):

    [ cos(θ)   0   sin(θ) ]
    [   0      1     0    ]
    [ -sin(θ)  0   cos(θ) ]
  • Rotation about the z-axis (Rz):

    [ cos(θ)  -sin(θ)   0 ]
    [ sin(θ)   cos(θ)   0 ]
    [   0        0       1 ]

To rotate a vector v = [x, y, z]T in 3D, you would multiply the corresponding rotation matrix (or a sequence of rotation matrices for multiple rotations) with the vector. The order of multiplication matters when combining rotations around different axes. For example, rotating first around the x-axis and then the y-axis is different from rotating first around the y-axis and then the x-axis.

Example:

Let's say you want to rotate the vector v = [1, 0]T by 45 degrees (π/4 radians) counter-clockwise in 2D space.

  1. Determine the rotation matrix:

    θ = π/4

    cos(π/4) = √2/2 ≈ 0.707

    sin(π/4) = √2/2 ≈ 0.707

    R = [ 0.707  -0.707 ]
        [ 0.707   0.707 ]
  2. Multiply the rotation matrix with the vector:

    [x'] = [ 0.707  -0.707 ] [1] = [0.707]
    [y'] = [ 0.707   0.707 ] [0] = [0.707]

    So the rotated vector v' is approximately [0.707, 0.707]T.

Key Takeaways:

  • Rotating a vector with a matrix involves multiplying the appropriate rotation matrix by the vector's coordinates.
  • The rotation matrix depends on the dimension of the space (2D, 3D) and the axis of rotation.
  • In 3D, the order of rotations around different axes matters.

Related Articles