<p>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.</p>

CC BY-SA 3.0
2016-09-06T09:49:49.813Z
The problem with quaternions is the literature.  Most standard operations are complex numbers wearing a mustache.
MB Reynolds
CC BY-SA 3.0
2016-09-06T10:27:45.700Z
@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.
joojaa
CC BY-SA 3.0
2016-09-06T11:49:43.297Z
Anything specific you thinking of?
MB Reynolds
CC BY-SA 3.0
2016-08-28T20:28:01.203Z
2016-08-28T20:28:01.203Z
joojaa
<p>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</p>

<pre><code>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
</code></pre>

<p>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. </p>

CC BY-SA 3.0
2017-07-29T04:28:44.200Z
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.
Nathan Reed
CC BY-SA 3.0
2017-07-28T14:44:29.253Z
2017-07-28T14:59:01.977Z
2017-07-28T14:59:01.977Z
CroCo
<p>Both methods end up doing the same calculations when you break it down.</p>

<p>Rotating a vector $u$ with a matrix:
$$\begin{bmatrix}\cos\theta &amp; -\sin\theta \\ \sin\theta &amp; \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}$$</p>

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

<p>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.</p>

<p>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.</p>

<blockquote>
  <p>On a related note, is there some spatial transformation that complex numbers can do but matrices cannot?</p>
</blockquote>

<p>No. Matrices are more general than complex numbers. Any complex number $z$ can be represented by a matrix as:
$$\begin{bmatrix}\text{Re}(z) &amp; -\text{Im}(z) \\ \text{Im}(z) &amp; \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.</p>

CC BY-SA 3.0
2017-07-28T14:33:15.843Z
Using  trigonometric functions has some costs. You could avoid using  trigonometric functions by directing multiplying complex numbers.
CroCo
CC BY-SA 3.0
2017-07-28T17:54:24.460Z
@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.
Nathan Reed
CC BY-SA 3.0
2016-09-06T09:46:46.523Z
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. https://en.wikipedia.org/wiki/2_%C3%97_2_real_matrices
MB Reynolds
CC BY-SA 3.0
2016-08-28T21:28:10.987Z
2016-08-28T21:28:10.987Z
Nathan Reed
<p>A 2D vector can be rotated by an angle $\theta$ using the rotation matrix:
\begin{bmatrix}
\cos(\theta) &amp; -\sin(\theta) \\
\sin(\theta) &amp; \cos(\theta)
\end{bmatrix}</p>

<p>Or, it can be rotated by multiplying the vector by the complex number $c$:</p>

<p>$$c = \cos(\theta) + i\sin(\theta)$$</p>

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

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

<transformations><computational-geometry>
Computing a rotation: complex numbers vs rotation matrix
Vermillion
# Computing a rotation: complex numbers vs rotation matrix

(Asked by: username_0 on 2016-08-28)

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?

**Tags:** transformations, computational-geometry


---

## 3 answers

### Answer by username_4 on 2016-08-28. Score: 11 | Accepted answer

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.

> **Comments:**
> **username_2**: 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. https://en.wikipedia.org/wiki/2_%C3%97_2_real_matrices  
> **username_3**: Using  trigonometric functions has some costs. You could avoid using  trigonometric functions by directing multiplying complex numbers.  
> **username_4**: @username_3 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.  

---

### Answer by username_1 on 2016-08-28. Score: 1

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.

> **Comments:**
> **username_2**: The problem with quaternions is the literature.  Most standard operations are complex numbers wearing a mustache.  
> **username_1**: @username_2 well that is to be expected, having 3 separate imaginary axes certainly has that effect. But then multiplicative transforns have their share of problems.  
> **username_2**: Anything specific you thinking of?  

---

### Answer by username_3 on 2017-07-28. Score: 0

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.

> **Comments:**
> **username_4**: 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.  

---

