# Computing a rotation: complex numbers vs rotation matrix

A 2D vector can be rotated by an angle $\theta$ using the rotation matrix: \begin{bmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{bmatrix}

Or, it can be rotated by multiplying the vector by the complex number $c$:

$$c = \cos(\theta) + i\sin(\theta)$$

Is there any meaningful difference between these two methods? I tested both in MATLAB, and they seem to run at the same speed.

On a related note, is there some spatial transformation that complex numbers can do but matrices cannot?

Both methods end up doing the same calculations when you break it down.

Rotating a vector $u$ with a matrix: $$\begin{bmatrix}\cos\theta & -\sin\theta \\ \sin\theta & \cos\theta\end{bmatrix} \begin{bmatrix}u_x\\u_y\end{bmatrix} = \begin{bmatrix}u_x \cos\theta - u_y\sin\theta \\ u_x \sin\theta + u_y \cos\theta \end{bmatrix}$$

Rotating a vector $u$ using complex numbers: \begin{aligned} (\cos\theta + i\sin\theta)(u_x + iu_y) &= u_x\cos\theta + iu_y\cos\theta + iu_x\sin\theta - u_y\sin\theta \\ &=(u_x\cos\theta - u_y\sin\theta) + i(u_x\sin\theta + u_y\cos\theta) \end{aligned}

I wouldn't expect either one to be appreciably faster or slower than the other, since they all end up doing the same set of basic operations, i.e. 4 multiplies and 2 adds.

Conceivably, complex numbers could be faster when you have a large number of rotations stored in an array, because they have only two components instead of four and therefore more of them fit into each cache line.

On a related note, is there some spatial transformation that complex numbers can do but matrices cannot?

No. Matrices are more general than complex numbers. Any complex number $z$ can be represented by a matrix as: $$\begin{bmatrix}\text{Re}(z) & -\text{Im}(z) \\ \text{Im}(z) & \text{Re}(z) \end{bmatrix}$$ This corresponds to rotation by the phase of $z$ combined with scaling by the magnitude of $z$. Complex numbers can only represent rotation and uniform scaling. Matrices can represent those, but also nonuniform scaling and shearing. Another way to see it is that complex numbers have only two degrees of freedom, while 2×2 matrices have four degrees of freedom.

• Same thing different way on xforms: converting a complex number to matrix M(2,R) as above is an isomorphism. Addition-> addition, product->product, conjugate->transpose. All complex ops can be expressed in terms of these. en.wikipedia.org/wiki/2_%C3%97_2_real_matrices Sep 6, 2016 at 9:46
• Using trigonometric functions has some costs. You could avoid using trigonometric functions by directing multiplying complex numbers. Jul 28, 2017 at 14:33
• @CroCo I don't think there are any cases where complex numbers save you from trig. You still need trig functions to get a unit complex number corresponding to a given angle, for instance. Jul 28, 2017 at 17:54

In a 2D case it reduces to the same calculation. Anyway for 3D we have quaternions that are multidimensional imaginary numbers with one real and 3 imaginary components. Quaternions have a property that makes rotation composing a linear interpolation operation by summing 2 weighted quaternions. This neatly solves certain problems with space rotations. But at the cost of understandability.

• The problem with quaternions is the literature. Most standard operations are complex numbers wearing a mustache. Sep 6, 2016 at 9:49
• @MBReynolds well that is to be expected, having 3 separate imaginary axes certainly has that effect. But then multiplicative transforns have their share of problems. Sep 6, 2016 at 10:27
• Anything specific you thinking of? Sep 6, 2016 at 11:49

In the rotation matrix, you actually use trigonometric functions (i.e. sine and cosine with an independent variable known as the angle) which internally implemented by Taylor series (i.e. has some costs). With complex numbers you could avoid that by multiplying the vector (i.e. after represents it as a complex number) by a complex number that represents the rotation. For example, if you need to rotate a vector (1,0) and make it points upward (i.e. no need for an angle), you basically multiple it by a complex number $z=i$, the rotated vector is then (0,1). As you can see no trigonometric functions are being used. See the following Matlab code to perform some rotations

clear all
clc

v =  1 + 0i; % vector

z1 =  1 + 1i; % 45  rotation
z2 =  0 + 1i; % 90  rotation
z3 = -1 + 1i; % 135 rotation
z4 = -1 + 0i; % 180 rotation
z5 = -1 - 1i; % 225 rotation
z6 =  1 - 1i; % 270 rotation

%rotate v1 by z deg
v1 = v*z6


But remember with 2D, the rotation matrix does fairly a good job however, with 3D the importance of complex numbers represented via quaternion is significant.

• You can also make rotation matrices for special angles like these by plugging values directly into the matrix. For example the matrix $\begin{bmatrix}1 & -1 \\ 1 & 1\end{bmatrix}$ implements the same rotation and scaling as the complex number $1 + 1i$. For general angles you still need trig functions, with either matrices or with complex numbers. Jul 29, 2017 at 4:28